diff --git a/src/Buildin/EcsDefaultWorldProvider.cs b/src/Buildin/EcsDefaultWorldProvider.cs index 21cf271..e9b8721 100644 --- a/src/Buildin/EcsDefaultWorldProvider.cs +++ b/src/Buildin/EcsDefaultWorldProvider.cs @@ -2,9 +2,9 @@ namespace DCFApixels.DragonECS { - [CreateAssetMenu(fileName = nameof(EcsDefaultWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/WorldProviders/" + nameof(EcsDefaultWorldProvider), order = 1)] + [CreateAssetMenu(fileName = nameof(EcsDefaultWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/Providers/" + nameof(EcsDefaultWorldProvider), order = 1)] public class EcsDefaultWorldProvider : EcsWorldProvider { - protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, null, WorldID); } + protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, WorldName, WorldID); } } } diff --git a/src/Buildin/EcsDefaultWorldSingletonProvider.cs b/src/Buildin/EcsDefaultWorldSingletonProvider.cs index 2f2abc2..d79f1b3 100644 --- a/src/Buildin/EcsDefaultWorldSingletonProvider.cs +++ b/src/Buildin/EcsDefaultWorldSingletonProvider.cs @@ -1,7 +1,11 @@ -namespace DCFApixels.DragonECS +using UnityEngine; + +namespace DCFApixels.DragonECS { + [CreateAssetMenu(fileName = NAME, menuName = EcsConsts.FRAMEWORK_NAME + "/Providers/" + NAME, order = 1)] public class EcsDefaultWorldSingletonProvider : EcsWorldProvider { + private const string NAME = "SingletonDefaultWorld"; private static EcsDefaultWorldSingletonProvider _instance; public static EcsDefaultWorldSingletonProvider Instance { @@ -9,11 +13,11 @@ { if (_instance == null) { - _instance = FindOrCreateSingleton("SingletonDefaultWorld"); + _instance = FindOrCreateSingleton(NAME); } return _instance; } } - protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, null, WorldID); } + protected override EcsDefaultWorld BuildWorld(ConfigContainer configs) { return new EcsDefaultWorld(configs, WorldName, WorldID); } } } diff --git a/src/Buildin/EcsRootUnity.cs b/src/Buildin/EcsRootUnity.cs index d859dab..48276f4 100644 --- a/src/Buildin/EcsRootUnity.cs +++ b/src/Buildin/EcsRootUnity.cs @@ -2,8 +2,10 @@ using DCFApixels.DragonECS.Unity.Internal; using System.Collections.Generic; using System.Linq; -using UnityEditor; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace DCFApixels.DragonECS { @@ -11,14 +13,19 @@ namespace DCFApixels.DragonECS [AddComponentMenu(EcsConsts.FRAMEWORK_NAME + "/" + nameof(EcsRootUnity), 30)] public class EcsRootUnity : MonoBehaviour { + [SerializeField] + private EcsPipelineProvider _pipelineProvider; [SerializeField] private bool _enablePipelineDebug = true; [SerializeField] + private bool _enableWorldDebug = true; + [SerializeField] private ScriptablePipelineTemplateBase[] _scriptableTemplates; [SerializeField] private MonoPipelineTemplateBase[] _monoTemplates; private EcsPipeline _pipeline; + private bool _isInit = false; public IEnumerable ScriptableTemplates { @@ -34,12 +41,23 @@ namespace DCFApixels.DragonECS } public bool IsInit { - get { return _pipeline != null && _pipeline.IsInit; } + get { return _isInit; } + } + public bool EnablePipelineDebug + { + get { return _enablePipelineDebug; } + } + public bool EnableWorldDebug + { + get { return _enableWorldDebug; } } - private void Start() + public void ManualStart() { - var pipelineBuilder = EcsPipeline.New(); + if (_isInit) { return; } + + var pipelineBuilder = EcsPipeline.New(new ConfigContainer(this)); + foreach (var template in _scriptableTemplates) { if (template == null) { continue; } @@ -50,6 +68,7 @@ namespace DCFApixels.DragonECS if (template == null) { continue; } pipelineBuilder.Add(template); } + #if UNITY_EDITOR if (_enablePipelineDebug) { @@ -57,7 +76,26 @@ namespace DCFApixels.DragonECS pipelineBuilder.AddUnique(new PipelineMonitorSystem(), EcsUnityConsts.DEBUG_LAYER); } #endif - _pipeline = pipelineBuilder.BuildAndInit(); + _pipeline = pipelineBuilder.Build(); + if (_pipelineProvider != null) + { + _pipelineProvider.Set(_pipeline); + } + _pipeline.Init(); + + _isInit = true; + } + private void Start() + { + ManualStart(); + } + + private void OnValidate() + { + if (_pipelineProvider == null) + { + _pipelineProvider = EcsPipelineProvider.SingletonInstance; + } } private void Update() @@ -77,7 +115,6 @@ namespace DCFApixels.DragonECS private void OnDrawGizmos() { - Gizmos.DrawIcon(transform.position, "", false); _pipeline?.DrawGizmos(); } @@ -133,4 +170,11 @@ namespace DCFApixels.DragonECS #endif #endregion } + public static class EcsRootUnityExt + { + public static bool IsEnableWorldDebug(this EcsPipeline.Builder self) + { + return self.Configs.Instance.Get().EnableWorldDebug; + } + } } diff --git a/src/Buildin/EcsRootUnitySingleton.cs b/src/Buildin/EcsRootUnitySingleton.cs new file mode 100644 index 0000000..15466e8 --- /dev/null +++ b/src/Buildin/EcsRootUnitySingleton.cs @@ -0,0 +1,39 @@ +using UnityEngine; + +namespace DCFApixels.DragonECS +{ + [DisallowMultipleComponent] + [RequireComponent(typeof(EcsRootUnity))] + [AddComponentMenu(EcsConsts.FRAMEWORK_NAME + "/" + nameof(EcsRootUnitySingleton), 30)] + public class EcsRootUnitySingleton : MonoBehaviour + { + [SerializeField] + private EcsRootUnity _root; + [SerializeField] + private bool _dontDestroyOnLoad = true; + + private static EcsRootUnitySingleton _singletonInstance; + public static EcsRootUnity Instance + { + get + { + if (_singletonInstance == null) + { + _singletonInstance = FindObjectOfType();//FindFirstObjectByType(); + } + return _singletonInstance?._root; + } + } + private void Awake() + { + if (_dontDestroyOnLoad) + { + DontDestroyOnLoad(gameObject); + } + } + private void OnValidate() + { + _root = GetComponent(); + } + } +} diff --git a/src/Buildin/EcsRootUnitySingleton.cs.meta b/src/Buildin/EcsRootUnitySingleton.cs.meta new file mode 100644 index 0000000..0864293 --- /dev/null +++ b/src/Buildin/EcsRootUnitySingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d2baa1c20021ec540b0c5399aba0db86 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Buildin/EcsWorldProvider.cs b/src/Buildin/EcsWorldProvider.cs index 8f4f35e..643a05f 100644 --- a/src/Buildin/EcsWorldProvider.cs +++ b/src/Buildin/EcsWorldProvider.cs @@ -2,9 +2,9 @@ namespace DCFApixels.DragonECS { - [CreateAssetMenu(fileName = nameof(EcsWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/WorldProviders/" + nameof(EcsWorldProvider), order = 1)] + [CreateAssetMenu(fileName = nameof(EcsWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/Providers/" + nameof(EcsWorldProvider), order = 1)] public class EcsWorldProvider : EcsWorldProvider { - protected override EcsWorld BuildWorld(ConfigContainer configs) { return new EcsWorld(configs, null, WorldID); } + protected override EcsWorld BuildWorld(ConfigContainer configs) { return new EcsWorld(configs, WorldName, WorldID); } } } diff --git a/src/Buildin/UnityComponent.cs b/src/Buildin/UnityComponent.cs index 6c24ad8..171122e 100644 --- a/src/Buildin/UnityComponent.cs +++ b/src/Buildin/UnityComponent.cs @@ -32,18 +32,16 @@ namespace DCFApixels.DragonECS { this.obj = obj; } - IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack - { - throw new NotSupportedException(); - } - IEnumerator IEnumerable.GetEnumerator() //IntelliSense hack - { - throw new NotSupportedException(); - } + IEnumerator IEnumerable.GetEnumerator() { throw new NotSupportedException(); }//IntelliSense hack + IEnumerator IEnumerable.GetEnumerator() { throw new NotSupportedException(); }//IntelliSense hack [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator T(UnityComponent a) { return a.obj; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator UnityComponent(T a) { return new UnityComponent(a); } + public override string ToString() + { + return $"UnityComponent<{typeof(T).ToMeta().TypeName}>"; + } } #region Unity Component Templates diff --git a/src/Connectors/AutoEntityCreator.cs b/src/Connectors/AutoEntityCreator.cs index 2475ceb..3de36e7 100644 --- a/src/Connectors/AutoEntityCreator.cs +++ b/src/Connectors/AutoEntityCreator.cs @@ -18,7 +18,7 @@ namespace DCFApixels.DragonECS [SerializeField] private EcsWorldProviderBase _world; - private bool _created; + private bool _started; #region Properties public EcsEntityConnect Connect @@ -39,10 +39,7 @@ namespace DCFApixels.DragonECS AutoResolveWorldProviderDependensy(); } } - private void Start() - { - CreateEntity(); - } + private void Start() { ManualStart(); } #endregion #region Methods @@ -56,19 +53,17 @@ namespace DCFApixels.DragonECS } public void ManualStart() { - CreateEntity(); + if (_started) { return; } + ManualCreate(); + _started = true; } - private void CreateEntity() + public void ManualCreate() { - if (_created) { return; } - if (_world == null) { AutoResolveWorldProviderDependensy(); } - InitConnect(_connect, _world.GetRaw()); - _created = true; } private void InitConnect(EcsEntityConnect connect, EcsWorld world) diff --git a/src/Connectors/EcsPipelineProvider.cs b/src/Connectors/EcsPipelineProvider.cs new file mode 100644 index 0000000..8d7378a --- /dev/null +++ b/src/Connectors/EcsPipelineProvider.cs @@ -0,0 +1,65 @@ +using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace DCFApixels.DragonECS +{ + [CreateAssetMenu(fileName = nameof(EcsWorldProvider), menuName = EcsConsts.FRAMEWORK_NAME + "/Providers/" + nameof(EcsWorldProvider), order = 1)] + public class EcsPipelineProvider : ScriptableObject + { + private EcsPipeline _pipeline; + private static EcsPipelineProvider _singletonInstance; + + #region Properties + public bool IsEmpty + { + get { return _pipeline == null; } + } + public static EcsPipelineProvider SingletonInstance + { + get + { + if(_singletonInstance == null) + { + _singletonInstance = FindOrCreateSingleton(); + } + return _singletonInstance; + } + } + #endregion + + #region Methods + public void Set(EcsPipeline pipeline) + { + _pipeline = pipeline; + } + public EcsPipeline GetCurrentPipeline() + { + return _pipeline; + } + protected static EcsPipelineProvider FindOrCreateSingleton() + { + return FindOrCreateSingleton(typeof(EcsPipelineProvider).Name + "Singleton"); + } + protected static EcsPipelineProvider FindOrCreateSingleton(string name) + { + EcsPipelineProvider instance = Resources.Load(name); + if (instance == null) + { + instance = CreateInstance(); +#if UNITY_EDITOR + if (AssetDatabase.IsValidFolder("Assets/Resources/") == false) + { + System.IO.Directory.CreateDirectory(Application.dataPath + "/Resources/"); + AssetDatabase.Refresh(); + } + AssetDatabase.CreateAsset(instance, "Assets/Resources/" + name + ".asset"); + AssetDatabase.Refresh(); +#endif + } + return instance; + } + #endregion + } +} \ No newline at end of file diff --git a/src/Connectors/EcsPipelineProvider.cs.meta b/src/Connectors/EcsPipelineProvider.cs.meta new file mode 100644 index 0000000..5313f2f --- /dev/null +++ b/src/Connectors/EcsPipelineProvider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 63bcd818806115742a86a7bbae1b8e95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/Connectors/EcsWorldProvider.cs b/src/Connectors/EcsWorldProvider.cs index 480291d..b051fee 100644 --- a/src/Connectors/EcsWorldProvider.cs +++ b/src/Connectors/EcsWorldProvider.cs @@ -1,7 +1,5 @@ using System; using UnityEngine; - - #if UNITY_EDITOR using UnityEditor; #endif @@ -17,14 +15,17 @@ namespace DCFApixels.DragonECS public abstract EcsWorld GetCurrentWorldRaw(); } [Serializable] - public abstract class EcsWorldProvider : EcsWorldProviderBase where TWorld : EcsWorld + public abstract class EcsWorldProvider : EcsWorldProviderBase, IEcsModule + where TWorld : EcsWorld { private TWorld _world; - [SerializeField] - public short _worldID = -1; - [Header("Default Configs")] + [Header("Base")] + [SerializeField] + private short _worldID = -1; + private string _worldName = ""; + [Header("Entites")] [SerializeField] private int _entitiesCapacity = EcsWorldConfig.Default.EntitiesCapacity; @@ -50,6 +51,10 @@ namespace DCFApixels.DragonECS { get { return _worldID; } } + public string WorldName + { + get { return _worldName; } + } public int EntitiesCapacity { get { return _entitiesCapacity; } @@ -122,9 +127,19 @@ namespace DCFApixels.DragonECS } return instance; } + void IEcsModule.Import(EcsPipeline.Builder b) + { + var wolrd = Get(); + b.Inject(wolrd); + if (b.IsEnableWorldDebug()) + { + b.AddUnityDebug(wolrd); + } + } #endregion #region Events + //TODO переименовать в CreateWorld protected abstract TWorld BuildWorld(ConfigContainer configs); protected virtual void OnWorldCreated(TWorld world) { } #endregion diff --git a/src/Connectors/Editor/AutoEntityCreatorEditor.cs b/src/Connectors/Editor/AutoEntityCreatorEditor.cs index bbbdaae..00873f5 100644 --- a/src/Connectors/Editor/AutoEntityCreatorEditor.cs +++ b/src/Connectors/Editor/AutoEntityCreatorEditor.cs @@ -51,6 +51,17 @@ namespace DCFApixels.DragonECS.Unity.Editors target.Autoset_Editor(); } } + using (EcsGUI.SetEnable(Application.isPlaying)) + { + buttonRect = buttonRect.Move(-height, 0); + if (EcsGUI.NewEntityButton(buttonRect)) + { + foreach (AutoEntityCreator target in targets) + { + target.ManualCreate(); + } + } + } } } } diff --git a/src/Connectors/GameObjectConnect.cs b/src/Connectors/GameObjectConnect.cs index afde7df..6576831 100644 --- a/src/Connectors/GameObjectConnect.cs +++ b/src/Connectors/GameObjectConnect.cs @@ -39,6 +39,10 @@ namespace DCFApixels.DragonECS } component = default; } + public override string ToString() + { + return $"GO({(Connect == null ? "NULL" : Connect.name)})"; + } } public enum GameObjectIcon : byte diff --git a/src/DebugUtils/Editor/SettingsEditor.cs b/src/DebugUtils/Editor/SettingsEditor.cs index d8ad072..4511f44 100644 --- a/src/DebugUtils/Editor/SettingsEditor.cs +++ b/src/DebugUtils/Editor/SettingsEditor.cs @@ -20,7 +20,7 @@ namespace DCFApixels.DragonECS.Unity.Editors private DefineSymbolsInfo[] _defineSymbols = null; private void InitDefines() { - string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone); + string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone);//TODO _defineSymbols = typeof(EcsDefines).GetFields(BindingFlags.Static | BindingFlags.Public).Select(o => new DefineSymbolsInfo(o.Name, false)) .Concat(typeof(EcsUnityDefines).GetFields(BindingFlags.Static | BindingFlags.Public).Select(o => new DefineSymbolsInfo(o.Name, false))) @@ -98,7 +98,7 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.BeginHorizontal(); var symbol = _defineSymbols[i]; - string text = symbol.name == "DEBUG" ? symbol.name + " (Build Olny)" : symbol.name; + string text = symbol.name == "DEBUG" ? symbol.name + " (Build Only)" : symbol.name; symbol.isOn = EditorGUILayout.ToggleLeft(text, symbol.isOn); GUILayout.EndHorizontal(); @@ -106,14 +106,24 @@ namespace DCFApixels.DragonECS.Unity.Editors if (EditorGUI.EndChangeCheck()) { } if (GUILayout.Button("Apply")) { + BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup; +#if UNITY_6000_0_OR_NEWER + string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group)); + for (int i = 0; i < _defineSymbols.Length; i++) + { + symbolsString = symbolsString.Replace(_defineSymbols[i].name, ""); + } + symbolsString += ";" + string.Join(';', _defineSymbols.Where(o => o.isOn).Select(o => o.name)); + PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString); +#else string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); for (int i = 0; i < _defineSymbols.Length; i++) { - var symbol = _defineSymbols[i]; - symbolsString = symbolsString.Replace(symbol.name, ""); + symbolsString = symbolsString.Replace(_defineSymbols[i].name, ""); } symbolsString += ";" + string.Join(';', _defineSymbols.Where(o => o.isOn).Select(o => o.name)); PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbolsString); +#endif InitDefines(); } GUILayout.EndVertical(); diff --git a/src/DebugUtils/Editor/UserSettingsPrefs.cs b/src/DebugUtils/Editor/UserSettingsPrefs.cs index 35707df..6d5eb4c 100644 --- a/src/DebugUtils/Editor/UserSettingsPrefs.cs +++ b/src/DebugUtils/Editor/UserSettingsPrefs.cs @@ -69,6 +69,20 @@ namespace DCFApixels.DragonECS.Unity.Editors } } } + [SerializeField] + private bool _isShowEntityOther = false; + public bool IsShowEntityOtherData + { + get => _isShowEntityOther; + set + { + if (_isShowEntityOther != value) + { + _isShowEntityOther = value; + AutoSave(); + } + } + } //[SerializeField] //private bool _isFastModeRuntimeComponents = false; //public bool IsFastModeRuntimeComponents diff --git a/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs b/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs new file mode 100644 index 0000000..47e385f --- /dev/null +++ b/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs @@ -0,0 +1,7 @@ +namespace DCFApixels.DragonECS.Unity.Editors +{ + public abstract class EntityEditorBlockDrawer + { + public abstract void Draw(entlong entity); + } +} diff --git a/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs.meta b/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs.meta new file mode 100644 index 0000000..dbe60ae --- /dev/null +++ b/src/DebugUtils/Monitors/Editor/EntityEditorBlockDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 932947836ddab7640b33fc15b7ffb33c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/DebugUtils/Monitors/Editor/EntityMonitorEditor.cs b/src/DebugUtils/Monitors/Editor/EntityMonitorEditor.cs index d7a70d2..0b40c0b 100644 --- a/src/DebugUtils/Monitors/Editor/EntityMonitorEditor.cs +++ b/src/DebugUtils/Monitors/Editor/EntityMonitorEditor.cs @@ -10,7 +10,8 @@ namespace DCFApixels.DragonECS.Unity.Editors { protected override void DrawCustom() { - bool isAlive = Target.Entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world); + var entity = Target.Entity; + bool isAlive = entity.TryUnpackForUnityEditor(out int id, out short gen, out short worldID, out EcsWorld world); using (EcsGUI.SetEnable(isAlive)) { if (GUILayout.Button("Delete Entity", GUILayout.Height(36f))) @@ -19,7 +20,34 @@ namespace DCFApixels.DragonECS.Unity.Editors } } EcsGUI.Layout.EntityBarForAlive(isAlive ? EcsGUI.EntityStatus.Alive : EcsGUI.EntityStatus.NotAlive, id, gen, worldID); - EcsGUI.Layout.DrawRuntimeComponents(Target.Entity, false); + + var drawers = UnityEditorUtility._entityEditorBlockDrawers; + if (drawers.Length > 0) + { + using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f))) + { + bool isExpand = false; + using (EcsGUI.CheckChanged()) + { + isExpand = EditorGUILayout.Foldout(UserSettingsPrefs.instance.IsShowEntityOtherData, "Other data"); + if (EcsGUI.Changed) + { + UserSettingsPrefs.instance.IsShowEntityOtherData = isExpand; + } + } + + if (isExpand) + { + foreach (var drawer in drawers) + { + drawer.Draw(entity); + } + } + } + + } + + EcsGUI.Layout.DrawRuntimeComponents(entity, false); } } } diff --git a/src/DebugUtils/Monitors/Editor/PipelineMonitorEditor.cs b/src/DebugUtils/Monitors/Editor/PipelineMonitorEditor.cs index 70b2b12..3fef48a 100644 --- a/src/DebugUtils/Monitors/Editor/PipelineMonitorEditor.cs +++ b/src/DebugUtils/Monitors/Editor/PipelineMonitorEditor.cs @@ -55,7 +55,7 @@ namespace DCFApixels.DragonECS.Unity.Editors systemsListStyle = new GUIStyle(EditorStyles.miniLabel); systemsListStyle.wordWrap = true; - if (Target.Pipeline == null || Target.Pipeline.IsDestoryed) + if (Target.Pipeline == null || Target.Pipeline.IsDestroyed) { return; } diff --git a/src/DebugUtils/UnityDebugService.cs b/src/DebugUtils/UnityDebugService.cs index f8dec29..e0b6f96 100644 --- a/src/DebugUtils/UnityDebugService.cs +++ b/src/DebugUtils/UnityDebugService.cs @@ -66,7 +66,7 @@ namespace DCFApixels.DragonECS } return; } - Debug.Log(v); + Debug.Log(msg); } public override void Break() { diff --git a/src/Internal/Editor/EcsGUI.cs b/src/Internal/Editor/EcsGUI.cs index 0837fd5..3a33023 100644 --- a/src/Internal/Editor/EcsGUI.cs +++ b/src/Internal/Editor/EcsGUI.cs @@ -435,6 +435,10 @@ namespace DCFApixels.DragonECS.Unity.Editors } } + public static bool NewEntityButton(Rect position) + { + return IconButton(position, Icons.Instance.PassIcon, 2f, "Create entity"); + } public static bool ValidateButton(Rect position) { return IconButton(position, Icons.Instance.RepaireIcon, 2f, "Validate"); @@ -523,15 +527,21 @@ namespace DCFApixels.DragonECS.Unity.Editors using (new EditorGUI.DisabledScope(true)) { GUI.Label(idRect, "Entity ID", style); - GUI.Label(genRect, "Generation", style); - GUI.Label(worldRect, "World ID", style); + using (SetAlpha(0.85f)) + { + GUI.Label(genRect, "Generation", style); + GUI.Label(worldRect, "World ID", style); + } } } else { EditorGUI.IntField(idRect, id, style); - EditorGUI.IntField(genRect, gen, style); - EditorGUI.IntField(worldRect, world, style); + using (SetAlpha(0.85f)) + { + EditorGUI.IntField(genRect, gen, style); + EditorGUI.IntField(worldRect, world, style); + } } } } diff --git a/src/Internal/Editor/MetaObjectsDropDown.cs b/src/Internal/Editor/MetaObjectsDropDown.cs index 572110f..e78c69f 100644 --- a/src/Internal/Editor/MetaObjectsDropDown.cs +++ b/src/Internal/Editor/MetaObjectsDropDown.cs @@ -88,9 +88,16 @@ namespace DCFApixels.DragonECS.Unity.Editors } internal class ComponentDropDown : MetaObjectsDropDown { + //private class StringComparer : IComparer + //{ + // public int Compare(string x, string y) + // { + // return x.CompareTo(y); + // } + //} public ComponentDropDown() { - IEnumerable<(IComponentTemplate, ITypeMeta)> itemMetaPairs = ComponentTemplateTypeCache.Dummies.ToArray().Select(dummy => + IEnumerable<(IComponentTemplate template, ITypeMeta meta)> itemMetaPairs = ComponentTemplateTypeCache.Dummies.ToArray().Select(dummy => { ITypeMeta meta; if (dummy is IComponentTemplateWithMetaOverride withMetaOverride) @@ -103,6 +110,8 @@ namespace DCFApixels.DragonECS.Unity.Editors } return (dummy, meta); }); + //TODO оптимизировать или вырезать + itemMetaPairs = itemMetaPairs.OrderBy(o => o.meta.Group.Name); Setup(itemMetaPairs); } @@ -170,7 +179,7 @@ namespace DCFApixels.DragonECS.Unity.Editors { public RuntimeComponentDropDown(IEnumerable pools) { - IEnumerable<(IEcsPool, ITypeMeta)> itemMetaPairs = pools.Select(pool => + IEnumerable<(IEcsPool pool, ITypeMeta meta)> itemMetaPairs = pools.Select(pool => { return (pool, (ITypeMeta)pool.ComponentType.ToMeta()); }); @@ -230,6 +239,7 @@ namespace DCFApixels.DragonECS.Unity.Editors Dictionary dict = new Dictionary(); + foreach (var pair in _itemMetaPairs) { ITypeMeta meta = pair.Item2; diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 7df6d82..727d0b9 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -115,6 +115,7 @@ namespace DCFApixels.DragonECS.Unity.Editors colorBoxeStyles = new SparseArray(); List serializableTypes = new List(); + List entityEditorBlockDrawers = new List(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { //var targetTypes = assembly.GetTypes().Where(type => @@ -122,6 +123,16 @@ namespace DCFApixels.DragonECS.Unity.Editors // type.IsSubclassOf(typeof(UnityObject)) == false && // type.GetCustomAttribute() != null); + foreach (var type in assembly.GetTypes()) + { + if ((type.IsGenericType || type.IsAbstract || type.IsInterface) == false && + typeof(EntityEditorBlockDrawer).IsAssignableFrom(type)) + { + var drawer = (EntityEditorBlockDrawer)Activator.CreateInstance(type); + entityEditorBlockDrawers.Add(drawer); + } + } + var targetTypes = assembly.GetTypes().Where(type => (type.IsGenericType || type.IsAbstract || type.IsInterface) == false && type.IsSubclassOf(typeof(UnityObject)) == false && @@ -130,6 +141,7 @@ namespace DCFApixels.DragonECS.Unity.Editors serializableTypes.AddRange(targetTypes); } _serializableTypes = serializableTypes.ToArray(); + _entityEditorBlockDrawers = entityEditorBlockDrawers.ToArray(); _serializableTypeWithMetaIDMetas = serializableTypes .Where(TypeMeta.IsHasMetaID) .Select(type => type.ToMeta()) @@ -149,6 +161,7 @@ namespace DCFApixels.DragonECS.Unity.Editors internal static readonly Assembly _integrationAssembly; internal static readonly Type[] _serializableTypes; + internal static readonly EntityEditorBlockDrawer[] _entityEditorBlockDrawers; internal static readonly TypeMeta[] _serializableTypeWithMetaIDMetas; private static readonly Dictionary _metaIDTypePairs = new Dictionary(); diff --git a/src/Tools/DragonDocs/Editors/DragonDocsPrefs.cs b/src/Tools/DragonDocs/Editors/DragonDocsPrefs.cs index 9bedab6..729a6d3 100644 --- a/src/Tools/DragonDocs/Editors/DragonDocsPrefs.cs +++ b/src/Tools/DragonDocs/Editors/DragonDocsPrefs.cs @@ -72,7 +72,15 @@ namespace DCFApixels.DragonECS.Unity.Docs.Editors private void AddInfo(List infos, string path, int startIndex, int length) { - MetaGroupInfo lastInfo = infos[infos.Count - 1]; + MetaGroupInfo lastInfo; + if (infos.Count == 0) + { + lastInfo = new MetaGroupInfo(string.Empty, string.Empty, 0, 0, 0); + } + else + { + lastInfo = infos[infos.Count - 1]; + } //if (lastInfo.Depth == 0) { lastInfo = new MetaGroupInfo("", "", 0, 0, 0); } int depth = 0; int lastSeparatorIndex = 0;