mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-11-12 23:15:56 +08:00
update
This commit is contained in:
parent
cb4ef1c853
commit
a2340ae3c3
@ -22,8 +22,14 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
this.obj = obj;
|
||||
}
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
||||
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException(); //IntelliSense hack
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() //IntelliSense hack
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#region Unity Component Templates
|
||||
|
||||
@ -1,61 +1,64 @@
|
||||
using DCFApixels.DragonECS.Internal;
|
||||
using DCFApixels.DragonECS.RunnersCore;
|
||||
using DCFApixels.DragonECS.RunnersCore;
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
[MetaName(nameof(DrawGizmos))]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public interface IEcsGizmosProcess : IEcsProcess
|
||||
{
|
||||
public void DrawGizmos(EcsPipeline pipeline);
|
||||
public void DrawGizmos();
|
||||
}
|
||||
public static class IEcsGizmosProcessExtensions
|
||||
{
|
||||
public static void DrawGizmos(this EcsPipeline systems)
|
||||
{
|
||||
systems.GetRunnerInstance<EcsLateGizmosRunner>().DrawGizmos(systems);
|
||||
}
|
||||
}
|
||||
|
||||
[MetaName(nameof(LateRun))]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public interface IEcsLateRunProcess : IEcsProcess
|
||||
{
|
||||
public void LateRun(EcsPipeline pipeline);
|
||||
}
|
||||
public static class IEcsLateRunSystemExtensions
|
||||
{
|
||||
public static void LateRun(this EcsPipeline pipeline)
|
||||
{
|
||||
pipeline.GetRunnerInstance<EcsLateRunRunner>().LateRun(pipeline);
|
||||
}
|
||||
public void LateRun();
|
||||
}
|
||||
[MetaName(nameof(FixedRun))]
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public interface IEcsFixedRunProcess : IEcsProcess
|
||||
{
|
||||
public void FixedRun(EcsPipeline pipeline);
|
||||
}
|
||||
public static class IEcsFixedRunSystemExtensions
|
||||
{
|
||||
public static void FixedRun(this EcsPipeline pipeline)
|
||||
{
|
||||
pipeline.GetRunnerInstance<EcsFixedRunRunner>().FixedRun(pipeline);
|
||||
}
|
||||
public void FixedRun();
|
||||
}
|
||||
|
||||
namespace Internal
|
||||
public static class UnityProcessExtensions
|
||||
{
|
||||
public static void DrawGizmos(this EcsPipeline pipeline)
|
||||
{
|
||||
pipeline.GetRunnerInstance<EcsLateGizmosRunner>().DrawGizmos();
|
||||
}
|
||||
public static void LateRun(this EcsPipeline pipeline)
|
||||
{
|
||||
pipeline.GetRunnerInstance<EcsLateRunRunner>().LateRun();
|
||||
}
|
||||
public static void FixedRun(this EcsPipeline pipeline)
|
||||
{
|
||||
pipeline.GetRunnerInstance<EcsFixedRunRunner>().FixedRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace DCFApixels.DragonECS.Unity.Internal
|
||||
{
|
||||
|
||||
[MetaColor(MetaColor.Orange)]
|
||||
public class EcsLateGizmosRunner : EcsRunner<IEcsGizmosProcess>, IEcsGizmosProcess
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
private EcsProfilerMarker[] _markers;
|
||||
#endif
|
||||
public void DrawGizmos(EcsPipeline pipeline)
|
||||
public void DrawGizmos()
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
for (int i = 0; i < Process.Length; i++)
|
||||
{
|
||||
using (_markers[i].Auto())
|
||||
Process[i].DrawGizmos(pipeline);
|
||||
{
|
||||
Process[i].DrawGizmos();
|
||||
}
|
||||
}
|
||||
#else
|
||||
foreach (var item in targets) item.DrawGizmos(pipeline);
|
||||
foreach (var item in targets) item.DrawGizmos();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -77,18 +80,18 @@ namespace DCFApixels.DragonECS
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
private EcsProfilerMarker[] _markers;
|
||||
#endif
|
||||
public void LateRun(EcsPipeline pipeline)
|
||||
public void LateRun()
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
for (int i = 0; i < Process.Length; i++)
|
||||
{
|
||||
using (_markers[i].Auto())
|
||||
{
|
||||
Process[i].LateRun(pipeline);
|
||||
Process[i].LateRun();
|
||||
}
|
||||
}
|
||||
#else
|
||||
foreach (var item in targets) item.LateRun(pipeline);
|
||||
foreach (var item in targets) item.LateRun();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -109,18 +112,18 @@ namespace DCFApixels.DragonECS
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
private EcsProfilerMarker[] _markers;
|
||||
#endif
|
||||
public void FixedRun(EcsPipeline pipeline)
|
||||
public void FixedRun()
|
||||
{
|
||||
#if DEBUG && !DISABLE_DEBUG
|
||||
for (int i = 0; i < Process.Length; i++)
|
||||
{
|
||||
using (_markers[i].Auto())
|
||||
{
|
||||
Process[i].FixedRun(pipeline);
|
||||
Process[i].FixedRun();
|
||||
}
|
||||
}
|
||||
#else
|
||||
foreach (var item in targets) item.FixedRun(pipeline);
|
||||
foreach (var item in targets) item.FixedRun();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -136,4 +139,3 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
@ -7,8 +9,8 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
private sealed class Aspect : EcsAspect
|
||||
{
|
||||
public readonly EcsPool<UnityGameObject> unityGameObjects;
|
||||
public Aspect(Builder b)
|
||||
public EcsPool<UnityGameObject> unityGameObjects;
|
||||
protected override void Init(Builder b)
|
||||
{
|
||||
unityGameObjects = b.Include<UnityGameObject>();
|
||||
}
|
||||
@ -22,16 +24,11 @@ namespace DCFApixels.DragonECS
|
||||
[SerializeField]
|
||||
private MonoEntityTemplate[] _monoTemplates;
|
||||
|
||||
internal void SetTemplates_Editor(MonoEntityTemplate[] tempaltes)
|
||||
{
|
||||
_monoTemplates = tempaltes;
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public entlong Entity
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _entity;
|
||||
get { return _entity; }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
@ -43,46 +40,74 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _entity.IsAlive;
|
||||
}
|
||||
public IEnumerable<ScriptableEntityTemplate> ScriptableTemplates
|
||||
{
|
||||
get { return _scriptableTemplates; }
|
||||
}
|
||||
public IEnumerable<MonoEntityTemplate> MonoTemplates
|
||||
{
|
||||
get { return _monoTemplates; }
|
||||
}
|
||||
public IEnumerable<ITemplateInternal> AllTemplates
|
||||
{
|
||||
get { return ((IEnumerable<ITemplateInternal>)_scriptableTemplates).Concat(_monoTemplates); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Connect
|
||||
public void ConnectWith(entlong entity, bool applyTemplates = false)
|
||||
{
|
||||
if (_entity.TryGetID(out int oldE) && _world != null)
|
||||
if (_entity.TryGetID(out int oldEntityID) && _world != null)
|
||||
{
|
||||
var s = _world.GetAspect<Aspect>();
|
||||
s.unityGameObjects.Del(oldE);
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
a.unityGameObjects.Del(oldEntityID);
|
||||
}
|
||||
_world = null;
|
||||
|
||||
if (entity.TryGetID(out int newE))
|
||||
if (entity.TryGetID(out int newEntityID))
|
||||
{
|
||||
_entity = entity;
|
||||
_world = _entity.World;
|
||||
var s = _world.GetAspect<Aspect>();
|
||||
if (!s.unityGameObjects.Has(newE)) s.unityGameObjects.Add(newE) = new UnityGameObject(gameObject);
|
||||
|
||||
var a = _world.GetAspect<Aspect>();
|
||||
if (!a.unityGameObjects.Has(newEntityID))
|
||||
{
|
||||
a.unityGameObjects.Add(newEntityID) = new UnityGameObject(gameObject);
|
||||
}
|
||||
if (applyTemplates)
|
||||
{
|
||||
ApplyTemplates();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_entity = entlong.NULL;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ApplyTemplates
|
||||
public void ApplyTemplates()
|
||||
{
|
||||
ApplyTemplatesFor(_entity.ID);
|
||||
}
|
||||
public void ApplyTemplatesFor(int entityID)
|
||||
{
|
||||
foreach (var t in _scriptableTemplates)
|
||||
foreach (var template in _scriptableTemplates)
|
||||
{
|
||||
t.Apply(_world.id, entityID);
|
||||
template.Apply(_world.id, entityID);
|
||||
}
|
||||
foreach (var t in _monoTemplates)
|
||||
foreach (var template in _monoTemplates)
|
||||
{
|
||||
t.Apply(_world.id, entityID);
|
||||
template.Apply(_world.id, entityID);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Editor
|
||||
internal void SetTemplates_Editor(MonoEntityTemplate[] tempaltes)
|
||||
{
|
||||
_monoTemplates = tempaltes;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,10 @@
|
||||
#if UNITY_EDITOR
|
||||
using DCFApixels.DragonECS.Unity.Internal;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static PlasticGui.LaunchDiffParameters;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -94,14 +97,39 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
private void DrawTemplates()
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
var iterator = serializedObject.GetIterator();
|
||||
iterator.NextVisible(true);
|
||||
bool enterChildren = true;
|
||||
while (iterator.NextVisible(enterChildren))
|
||||
while (iterator.NextVisible(false))
|
||||
{
|
||||
EditorGUILayout.PropertyField(iterator, true);
|
||||
enterChildren = false;
|
||||
}
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
private void Autoset(EcsEntityConnect target)
|
||||
{
|
||||
var result = target.MonoTemplates.Where(o => o != null).Union(GetTemplatesFor(target.transform));
|
||||
|
||||
target.SetTemplates_Editor(result.ToArray());
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
private IEnumerable<MonoEntityTemplate> GetTemplatesFor(Transform parent)
|
||||
{
|
||||
IEnumerable<MonoEntityTemplate> result = parent.GetComponents<MonoEntityTemplate>();
|
||||
for (int i = 0; i < parent.childCount; i++)
|
||||
{
|
||||
var child = parent.GetChild(i);
|
||||
if (child.TryGetComponent<EcsEntityConnect>(out _))
|
||||
{
|
||||
return Enumerable.Empty<MonoEntityTemplate>();
|
||||
}
|
||||
result = result.Concat(GetTemplatesFor(child));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DrawButtons()
|
||||
@ -109,15 +137,13 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Autoset"))
|
||||
{
|
||||
Target.SetTemplates_Editor(Target.GetComponents<MonoEntityTemplate>());
|
||||
EditorUtility.SetDirty(target);
|
||||
Autoset(Target);
|
||||
}
|
||||
if (GUILayout.Button("Autoset Cascade"))
|
||||
{
|
||||
foreach (var item in Target.GetComponentsInChildren<EcsEntityConnect>())
|
||||
{
|
||||
item.SetTemplates_Editor(item.GetComponents<MonoEntityTemplate>());
|
||||
EditorUtility.SetDirty(item);
|
||||
Autoset(item);
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
@ -107,43 +107,35 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
return;
|
||||
}
|
||||
|
||||
DrawTop(target);
|
||||
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f));
|
||||
DrawTop(target);
|
||||
GUILayout.Label("", GUILayout.Height(0), GUILayout.ExpandWidth(true));
|
||||
for (int i = 0; i < componentsProp.arraySize; i++)
|
||||
{
|
||||
DrawComponentData(componentsProp.GetArrayElementAtIndex(i), i);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
DrawFooter(target);
|
||||
}
|
||||
private void DrawTop(ITemplateInternal target)
|
||||
{
|
||||
if (GUILayout.Button("Add Component", GUILayout.Height(24f)))
|
||||
switch (EcsGUI.Layout.AddClearComponentButtons())
|
||||
{
|
||||
case EcsGUI.AddClearComponentButton.AddComponent:
|
||||
Init();
|
||||
_genericMenu.ShowAsContext();
|
||||
}
|
||||
}
|
||||
private void DrawFooter(ITemplateInternal target)
|
||||
{
|
||||
if (GUILayout.Button("Clear", GUILayout.Height(24f)))
|
||||
{
|
||||
break;
|
||||
case EcsGUI.AddClearComponentButton.Clear:
|
||||
Init();
|
||||
serializedObject.FindProperty(target.ComponentsPropertyName).ClearArray();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawComponentData(SerializedProperty componentRefProp, int index)
|
||||
{
|
||||
IComponentTemplate template = componentRefProp.managedReferenceValue as IComponentTemplate;
|
||||
if (template == null)
|
||||
{
|
||||
DrawDamagedComponent(componentRefProp, index);
|
||||
return;
|
||||
}
|
||||
|
||||
if (componentRefProp.managedReferenceValue == null)
|
||||
if (template == null || componentRefProp.managedReferenceValue == null)
|
||||
{
|
||||
DrawDamagedComponent(componentRefProp, index);
|
||||
return;
|
||||
|
||||
@ -4,6 +4,7 @@ using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
|
||||
namespace DCFApixels.DragonECS.Unity.Editors
|
||||
{
|
||||
@ -15,6 +16,25 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
private static readonly Rect RemoveButtonRect = new Rect(0f, 0f, 17f, 19f);
|
||||
private static readonly Rect TooltipIconRect = new Rect(0f, 0f, 21f, 15f);
|
||||
|
||||
private static bool IsShowHidden
|
||||
{
|
||||
get { return DebugMonitorPrefs.instance.IsShowHidden; }
|
||||
set { DebugMonitorPrefs.instance.IsShowHidden = value; }
|
||||
}
|
||||
private static bool IsShowRuntimeComponents
|
||||
{
|
||||
get { return DebugMonitorPrefs.instance.IsShowRuntimeComponents; }
|
||||
set { DebugMonitorPrefs.instance.IsShowRuntimeComponents = value; }
|
||||
}
|
||||
|
||||
public enum AddClearComponentButton : byte
|
||||
{
|
||||
None = 0,
|
||||
AddComponent,
|
||||
Clear,
|
||||
}
|
||||
|
||||
//private static GUILayoutOption[] _defaultParams;
|
||||
//private static bool _isInit = false;
|
||||
//private static void Init()
|
||||
@ -27,17 +47,29 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
// _isInit = true;
|
||||
//}
|
||||
|
||||
public static AddClearComponentButton AddClearComponentButtons(Rect position)
|
||||
{
|
||||
//Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 36f);
|
||||
position = RectUtility.AddPadding(position, 20f, 20f, 12f, 2f);
|
||||
var (left, right) = RectUtility.HorizontalSliceLerp(position, 0.75f);
|
||||
|
||||
if (GUI.Button(left, "Add Component"))
|
||||
{
|
||||
return AddClearComponentButton.AddComponent;
|
||||
}
|
||||
if (GUI.Button(right, "Clear"))
|
||||
{
|
||||
return AddClearComponentButton.Clear;
|
||||
}
|
||||
return AddClearComponentButton.None;
|
||||
}
|
||||
|
||||
public static class Layout
|
||||
{
|
||||
private static bool IsShowHidden
|
||||
|
||||
public static AddClearComponentButton AddClearComponentButtons()
|
||||
{
|
||||
get { return DebugMonitorPrefs.instance.IsShowHidden; }
|
||||
set { DebugMonitorPrefs.instance.IsShowHidden = value; }
|
||||
}
|
||||
private static bool IsShowRuntimeComponents
|
||||
{
|
||||
get { return DebugMonitorPrefs.instance.IsShowRuntimeComponents; }
|
||||
set { DebugMonitorPrefs.instance.IsShowRuntimeComponents = value; }
|
||||
return EcsGUI.AddClearComponentButtons(GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 36f));
|
||||
}
|
||||
public static void DrawRuntimeComponents(entlong entity, bool isWithFoldout = true)
|
||||
{
|
||||
@ -59,8 +91,21 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
if (isWithFoldout == false || IsShowRuntimeComponents)
|
||||
{
|
||||
switch (EcsGUI.Layout.AddClearComponentButtons())
|
||||
{
|
||||
case AddClearComponentButton.AddComponent:
|
||||
GenericMenu genericMenu = RuntimeComponentsUtility.GetAddComponentGenericMenu(world);
|
||||
RuntimeComponentsUtility.CurrentEntityID = entityID;
|
||||
genericMenu.ShowAsContext();
|
||||
break;
|
||||
case AddClearComponentButton.Clear:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
GUILayout.Box("", UnityEditorUtility.GetStyle(GUI.color, 0.16f), GUILayout.ExpandWidth(true));
|
||||
IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden);
|
||||
|
||||
foreach (var componentTypeID in componentTypeIDs)
|
||||
{
|
||||
var pool = world.GetPoolInstance(componentTypeID);
|
||||
@ -70,13 +115,6 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
}
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (GUILayout.Button("Add Component", GUILayout.Height(24f)))
|
||||
{
|
||||
GenericMenu genericMenu = RuntimeComponentsUtility.GetAddComponentGenericMenu(world);
|
||||
RuntimeComponentsUtility.CurrentEntityID = entityID;
|
||||
genericMenu.ShowAsContext();
|
||||
}
|
||||
}
|
||||
private static readonly BindingFlags fieldFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||
private static void DrawRuntimeComponent(int entityID, IEcsPool pool)
|
||||
@ -124,8 +162,16 @@ namespace DCFApixels.DragonECS.Unity.Editors
|
||||
|
||||
private static bool DrawRuntimeData(Type fieldType, GUIContent label, ExpandMatrix expandMatrix, object data, out object outData)
|
||||
{
|
||||
Type type = data.GetType();
|
||||
outData = data;
|
||||
Type type = data == null ? typeof(void) : data.GetType();
|
||||
|
||||
bool isUnityObject = typeof(UnityEngine.Object).IsAssignableFrom(fieldType);
|
||||
|
||||
if (isUnityObject == false && data == null)
|
||||
{
|
||||
EditorGUILayout.TextField(label, "Null");
|
||||
return false;
|
||||
}
|
||||
ref bool isExpanded = ref expandMatrix.Down();
|
||||
bool changed = false;
|
||||
outData = data;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user