Пример #1
0
        public static void ShowInstance()
        {
            var instance = EditorWindow.GetWindow(typeof(NodesViewerEditor));
            var icon     = EditorUtilities.Load <Texture2D>("ECSEditor/EditorResources/icon-nodesviewer.png");

            instance.titleContent = new GUIContent("Nodes Viewer", icon);
            instance.Show();
        }
Пример #2
0
        public override UnityEngine.UIElements.VisualElement CreateInspectorGUI()
        {
            var container = new UnityEngine.UIElements.VisualElement();

            this.rootVisualElement = container;
            container.styleSheets.Add(EditorUtilities.Load <UnityEngine.UIElements.StyleSheet>("Editor/Core/DataConfigs/styles.uss", isRequired: true));
            container.Bind(this.serializedObjectCopy);

            BuildContainer(this, container, this.serializedObjectCopy);

            return(container);
        }
        public void OnEnable()
        {
            var styles             = EditorUtilities.Load <StyleSheet>("Editor/Core/DataConfigs/styles.uss", isRequired: true);
            var worldsViewerStyles = EditorUtilities.Load <StyleSheet>("Editor/WorldsViewer/EditorResources/styles.uss", isRequired: true);
            var domMain            = EditorUtilities.Load <VisualTreeAsset>("Editor/WorldsViewer/EditorResources/Main.uxml", isRequired: true);
            var domWorld           = EditorUtilities.Load <VisualTreeAsset>("Editor/WorldsViewer/EditorResources/World.uxml", isRequired: true);
            var domWorldContent    = EditorUtilities.Load <VisualTreeAsset>("Editor/WorldsViewer/EditorResources/World-Content.uxml", isRequired: true);
            var domSystem          = EditorUtilities.Load <VisualTreeAsset>("Editor/WorldsViewer/EditorResources/System.uxml", isRequired: true);
            var domModule          = EditorUtilities.Load <VisualTreeAsset>("Editor/WorldsViewer/EditorResources/Module.uxml", isRequired: true);

            this.rootVisualElement.styleSheets.Add(styles);
            this.rootVisualElement.styleSheets.Add(worldsViewerStyles);
            this.rootVisualElement.Add(domMain.CloneTree());

            var worldsContainer = this.rootVisualElement.Q("Worlds");

            for (int i = 0; i < 10; ++i)
            {
                var item = domWorld.CloneTree();
                worldsContainer.Add(item);

                var systemsContainer = item.Q(className: "systems");
                for (int j = 0; j < 20; ++j)
                {
                    systemsContainer.Add(domSystem.CloneTree());
                }

                var modulesContainer = item.Q(className: "modules");
                for (int j = 0; j < 20; ++j)
                {
                    modulesContainer.Add(domModule.CloneTree());
                }
            }

            var contentContainer = this.rootVisualElement.Q("Content");

            contentContainer.Add(domWorldContent.CloneTree());
        }
Пример #4
0
        internal static bool Create(string path, string fileName, string templateName, System.Collections.Generic.Dictionary <string, string> customDefines = null, bool allowRename = true, System.Action <Object> onCreated = null)
        {
            var templateAsset = EditorUtilities.Load <TextAsset>($"ECSEditor/Templates/EditorResources/{templateName}.txt", true);
            var content       = templateAsset.text;

            if (customDefines != null)
            {
                foreach (var def in customDefines)
                {
                    content = content.Replace("#" + def.Key + "#", def.Value);
                }
            }

            var stateTypeStr = "StateClassType";

            if (content.Contains("#STATENAME#") == true)
            {
                var projectName = path.Split('/');
                var type        = typeof(ME.ECS.State);
                var types       = System.AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes())
                                  .Where(p => p.IsClass == true && type.IsAssignableFrom(p) && projectName.Contains(p.Name.Replace("State", string.Empty))).ToArray();
                if (types.Length > 0)
                {
                    var stateType = types[0];
                    stateTypeStr = stateType.Name;
                }
            }

            var @namespace = path.Replace("Assets/", "").Replace("/", ".").Replace("\\", ".");

            content = content.Replace(@"#NAMESPACE#", @namespace);
            content = content.Replace(@"#PROJECTNAME#", @namespace.Split('.')[0]);
            content = content.Replace(@"#STATENAME#", stateTypeStr);
            content = content.Replace(@"#REFERENCES#", string.Empty);

            if (allowRename == true)
            {
                var defaultNewFileName = fileName;
                var image = ScriptTemplates.scriptIcon;
                ProjectWindowUtil.StartNameEditingIfProjectWindowExists(
                    0,
                    ScriptableObject.CreateInstance <DoCreateScriptAsset>().SetCallback((instance) => {
                    if (onCreated != null)
                    {
                        onCreated.Invoke(instance);
                    }
                }),
                    defaultNewFileName,
                    image,
                    content);
            }
            else
            {
                var fullDir = path + "/" + fileName;
                if (System.IO.File.Exists(fullDir) == true)
                {
                    var contentExists = System.IO.File.ReadAllText(fullDir);
                    if (contentExists == content)
                    {
                        return(false);
                    }
                }

                var withoutExtension = System.IO.Path.GetFileNameWithoutExtension(fullDir);
                withoutExtension = withoutExtension.Replace(" ", "");
                content          = content.Replace("#SCRIPTNAME#", withoutExtension);

                var dir = System.IO.Path.GetDirectoryName(fullDir);
                if (System.IO.Directory.Exists(dir) == false)
                {
                    return(false);
                }

                System.IO.File.WriteAllText(fullDir, content);
                AssetDatabase.ImportAsset(fullDir, ImportAssetOptions.ForceSynchronousImport);

                if (onCreated != null)
                {
                    onCreated.Invoke(AssetDatabase.LoadAssetAtPath <Object>(fullDir));
                }
            }

            return(true);
        }
Пример #5
0
        public override VisualElement CreateInspectorGUI()
        {
            var container = new VisualElement();

            container.styleSheets.Add(EditorUtilities.Load <StyleSheet>("Editor/Core/DataConfigs/styles.uss", isRequired: true));
            this.rootElement = container;

            var target = this.target as ME.ECS.Debug.EntityDebugComponent;

            if (target.world != null && target.world.isActive == true)
            {
                this.debug                 = new ME.ECS.Debug.EntityProxyDebugger(target.entity, target.world);
                this.temp.components       = this.debug.GetComponentsList();
                this.temp.sharedComponents = this.debug.GetSharedComponentsList();
                container.schedule.Execute(this.Update).Every((long)(target.world.GetTickTime() * 1000f));

                var searchField = new ToolbarSearchField();
                searchField.AddToClassList("search-field");
                searchField.RegisterValueChangedCallback((evt) => {
                    var search = evt.newValue.ToLower();
                    DataConfigEditor.Search(search, this.componentsContainer);
                    DataConfigEditor.Search(search, this.sharedComponentsContainer);
                });
                container.Add(searchField);

                {
                    var entityElement = new VisualElement();
                    this.entityContainer = entityElement;
                    entityElement.name   = "EntityContainer";
                    entityElement.AddToClassList("entity-container");
                    var id = new Label("ID:");
                    id.AddToClassList("entity-container-item");
                    id.AddToClassList("entity-container-item-label");
                    entityElement.Add(id);
                    var idValue = new Label();
                    idValue.AddToClassList("entity-container-item");
                    idValue.AddToClassList("entity-container-item-value");
                    idValue.name  = "EntityId";
                    this.entityId = idValue;
                    entityElement.Add(idValue);
                    var gen = new Label("Generation:");
                    gen.AddToClassList("entity-container-item");
                    gen.AddToClassList("entity-container-item-label");
                    entityElement.Add(gen);
                    var genValue = new Label();
                    genValue.AddToClassList("entity-container-item");
                    genValue.AddToClassList("entity-container-item-value");
                    genValue.name  = "EntityGen";
                    this.entityGen = genValue;
                    entityElement.Add(genValue);
                    var version = new Label("Version:");
                    version.AddToClassList("entity-container-item");
                    version.AddToClassList("entity-container-item-label");
                    entityElement.Add(version);
                    var versionValue = new Label();
                    versionValue.AddToClassList("entity-container-item");
                    versionValue.AddToClassList("entity-container-item-value");
                    versionValue.name  = "EntityVersion";
                    this.entityVersion = versionValue;
                    entityElement.Add(versionValue);

                    container.Add(entityElement);

                    var changedWarning = new Label("Selected entity is no longer available: generation has been changed.");
                    this.entityContainerWarning = changedWarning;
                    changedWarning.name         = "EntityChanged";
                    changedWarning.AddToClassList("entity-changed-warning");
                    changedWarning.AddToClassList("hidden");
                    container.Add(changedWarning);
                }

                this.content      = new VisualElement();
                this.content.name = "Content";
                container.Add(this.content);

                if (target.entity.IsAlive() == true)
                {
                    this.BuildLists(this.content);
                }
            }
            else
            {
                var element = new Label("No active world found");
                element.AddToClassList("world-not-found");
                this.rootElement.Add(element);
            }

            return(this.rootElement);
        }
Пример #6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position.y += 4f;

            var enabled = property.FindPropertyRelative("enabled");
            var items   = property.FindPropertyRelative("feature");
            //var innerFeatures = property.FindPropertyRelative("innerFeatures");
            var enabledRect = position;

            enabledRect.height = EditorGUIUtility.singleLineHeight;
            enabledRect.width  = 30f;
            enabled.boolValue  = EditorGUI.ToggleLeft(enabledRect, GUIContent.none, enabled.boolValue);

            var featureRect = position;

            featureRect.height = EditorGUIUtility.singleLineHeight;
            featureRect.x     += 30f;
            featureRect.width -= 30f;

            using (new GUILayoutExt.GUIAlphaUsing(enabled.boolValue == false ? 0.5f : 1f)) {
                EditorGUI.PropertyField(featureRect, items, GUIContent.none, true);

                var featureBase = items.objectReferenceValue as FeatureBase;
                if (featureBase != null)
                {
                    var offset = 0f;
                    {
                        var systems = this.GetSystems(featureBase);
                        if (systems.Count > 0)
                        {
                            var icon = EditorUtilities.Load <Texture2D>("Editor/EditorResources/icon-system.png");

                            var systemsLabelRect = featureRect;
                            var style            = new GUIStyle(EditorStyles.label);
                            style.fontSize           = 10;
                            systemsLabelRect.width   = style.CalcSize(new GUIContent(systems.Count.ToString(), icon)).x;
                            systemsLabelRect.x      += featureRect.width - systemsLabelRect.width - 18f;
                            systemsLabelRect.y      += 2f;
                            systemsLabelRect.height -= 4f;

                            var tooltip = string.Empty;
                            foreach (var sys in systems)
                            {
                                tooltip += sys.typeName + "\n";
                            }

                            offset += systemsLabelRect.width;

                            FeatureDataDrawer.DrawLabel(systemsLabelRect, new GUIContent(systems.Count.ToString(), icon, tooltip.Trim()), new Color(0.5f, 0.5f, 0.5f));
                        }
                    }
                    {
                        var modules = this.GetModules(featureBase);
                        if (modules.Count > 0)
                        {
                            var icon = EditorUtilities.Load <Texture2D>("Editor/EditorResources/icon-module.png");

                            var systemsLabelRect = featureRect;
                            var style            = new GUIStyle(EditorStyles.label);
                            style.fontSize           = 10;
                            systemsLabelRect.width   = style.CalcSize(new GUIContent(modules.Count.ToString(), icon)).x;
                            systemsLabelRect.x      += featureRect.width - systemsLabelRect.width - 18f - offset - 1f;
                            systemsLabelRect.y      += 2f;
                            systemsLabelRect.height -= 4f;

                            var tooltip = string.Empty;
                            foreach (var sys in modules)
                            {
                                tooltip += sys.typeName + "\n";
                            }

                            FeatureDataDrawer.DrawLabel(systemsLabelRect, new GUIContent(modules.Count.ToString(), icon, tooltip.Trim()), new Color(0.5f, 0.5f, 0.8f));
                        }
                    }
                    //EditorStyles.helpBox.Draw(systemsLabelRect, "SS", false, false, false, false);

                    position.y      += featureRect.height;
                    position.height -= featureRect.height;

                    if (string.IsNullOrEmpty(featureBase?.editorComment) == false)
                    {
                        var width = this.GetWidth();
                        var style = new GUIStyle(EditorStyles.miniLabel);
                        style.wordWrap     = true;
                        style.fixedWidth   = 0f;
                        style.stretchWidth = false;
                        var h           = style.CalcHeight(new GUIContent(featureBase.editorComment), width);
                        var commentRect = position;
                        commentRect.height = h;
                        EditorGUI.LabelField(commentRect, featureBase.editorComment, style);

                        position.y      += commentRect.height;
                        position.height -= commentRect.height;
                    }
                }
            }

            //EditorGUI.PropertyField(position, innerFeatures, new GUIContent("Sub Features"), true);
        }
Пример #7
0
        public static void GenerateFilters()
        {
            const int count = 20;

            var asms = UnityEditor.AssetDatabase.FindAssets("t:asmdef ME.ECS");

            foreach (var asm in asms)
            {
                var asset = UnityEditor.AssetDatabase.GUIDToAssetPath(asm);
                var dir   = $"{System.IO.Path.GetDirectoryName(asset)}/Core/Filters/CodeGenerator";
                if (System.IO.Directory.Exists(dir) == false)
                {
                    continue;
                }

                var outputDelegates = string.Empty;
                var outputForEach   = string.Empty;
                var buffers         = string.Empty;

                for (int j = 1; j < count; ++j)
                {
                    var itemsType = "T0";
                    for (int i = 1; i < j; ++i)
                    {
                        itemsType += $",T{i}";
                    }

                    var itemsWhere = " where T0:unmanaged,IComponentBase";
                    for (int i = 1; i < j; ++i)
                    {
                        itemsWhere += $" where T{i}:unmanaged,IComponentBase";
                    }

                    {
                        var resForEachSource = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsForEachItem.txt", isRequired: true).text;

                        var resSource  = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsDelegateItem.txt", isRequired: true).text;
                        var formsWrite = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            formsWrite += "W";
                        }

                        var items = new List <string>();
                        items.Add("ref T0 t0");
                        for (int i = 1; i < j; ++i)
                        {
                            items.Add($"ref T{i} t{i}");
                        }

                        var itemsGet = new List <string>();
                        itemsGet.Add("ref bag.GetT0(i)");
                        for (int i = 1; i < j; ++i)
                        {
                            itemsGet.Add($"ref bag.GetT{i}(i)");
                        }

                        for (int i = 0; i <= j; ++i)
                        {
                            var chars = formsWrite.ToCharArray();

                            var res = resSource;
                            res              = res.Replace("#ITEMS_TYPE#", itemsType);
                            res              = res.Replace("#ITEMS#", string.Join(",", items));
                            res              = res.Replace("#INDEX#", j.ToString());
                            res              = res.Replace("#FORMS#", formsWrite);
                            outputDelegates += $"{res}\n";

                            var resForEach = resForEachSource;
                            resForEach     = resForEach.Replace("#ITEMS_TYPE#", itemsType);
                            resForEach     = resForEach.Replace("#ITEMS_WHERE#", itemsWhere);
                            resForEach     = resForEach.Replace("#FORMS#", formsWrite);
                            resForEach     = resForEach.Replace("#ITEMS_GET#", string.Join(",", itemsGet));
                            resForEach     = resForEach.Replace("#INDEX#", j.ToString());
                            outputForEach += $"{resForEach}\n";

                            if (i == j)
                            {
                                break;
                            }

                            itemsGet[i] = $"in bag.GetT{i}(i)";
                            items[i]    = $"in T{i} t{i}";
                            chars[i]    = 'R';
                            formsWrite  = new string(chars);
                        }
                    }

                    {
                        var itemsGet = "ref buffer.GetT0(id)";
                        for (int i = 1; i < j; ++i)
                        {
                            itemsGet += $", ref buffer.GetT{i}(id)";
                        }

                        var res = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsForEachItem.txt", isRequired: true).text;
                        res = res.Replace("#ITEMS_TYPE#", itemsType);
                        res = res.Replace("#ITEMS_WHERE#", itemsWhere);
                        res = res.Replace("#ITEMS_GET#", itemsGet);
                        res = res.Replace("#INDEX#", j.ToString());
                        //outputForEach += $"{res}\n";
                    }

                    {
                        var itemMethods  = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferMethods.txt", isRequired: true).text;
                        var itemsMethods = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = itemMethods;
                            text          = text.Replace("#INDEX#", i.ToString());
                            itemsMethods += text;
                        }

                        var dataBufferContains       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferDataBufferContains.txt", isRequired: true).text;
                        var dataBufferContainsOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = dataBufferContains;
                            text = text.Replace("#INDEX#", i.ToString());
                            dataBufferContainsOutput += text;
                        }

                        var dataBufferOps       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferDataBufferOps.txt", isRequired: true).text;
                        var dataBufferOpsOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = dataBufferOps;
                            text = text.Replace("#INDEX#", i.ToString());
                            dataBufferOpsOutput += text;
                        }

                        var dataBufferData       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferDataBufferData.txt", isRequired: true).text;
                        var dataBufferDataOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = dataBufferData;
                            text = text.Replace("#INDEX#", i.ToString());
                            dataBufferDataOutput += text;
                        }

                        var regsInit       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferRegsInit.txt", isRequired: true).text;
                        var regsInitOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = regsInit;
                            text            = text.Replace("#INDEX#", i.ToString());
                            regsInitOutput += text;
                        }

                        var regsInitFill       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferRegsInitFill.txt", isRequired: true).text;
                        var regsInitFillOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = regsInitFill;
                            text = text.Replace("#INDEX#", i.ToString());
                            regsInitFillOutput += text;
                        }

                        var pushRegsInit       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferPushRegsInit.txt", isRequired: true).text;
                        var pushRegsInitOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = pushRegsInit;
                            text = text.Replace("#INDEX#", i.ToString());
                            pushRegsInitOutput += text;
                        }

                        var pushOps       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferPushOps.txt", isRequired: true).text;
                        var pushOpsOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = pushOps;
                            text           = text.Replace("#INDEX#", i.ToString());
                            pushOpsOutput += text;
                        }

                        var regsDispose       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferRegsDispose.txt", isRequired: true).text;
                        var regsDisposeOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = regsDispose;
                            text = text.Replace("#INDEX#", i.ToString());
                            regsDisposeOutput += text;
                        }

                        var regsJobInit       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferRegsJobInit.txt", isRequired: true).text;
                        var regsJobInitOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = regsJobInit;
                            text = text.Replace("#INDEX#", i.ToString());
                            regsJobInitOutput += text;
                        }

                        var regsJobFill       = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferRegsJobFill.txt", isRequired: true).text;
                        var regsJobFillOutput = string.Empty;
                        for (int i = 0; i < j; ++i)
                        {
                            var text = regsJobFill;
                            text = text.Replace("#INDEX#", i.ToString());
                            regsJobFillOutput += text;
                        }

                        var res = EditorUtilities.Load <UnityEngine.TextAsset>("Editor/Templates/EditorResources/00-FilterExtensionsBufferItem.txt", isRequired: true).text;
                        res = res.Replace("#ITEMS_TYPE#", itemsType);
                        res = res.Replace("#ITEMS_WHERE#", itemsWhere);
                        res = res.Replace("#ITEMS_METHODS#", itemsMethods);

                        res = res.Replace("#DATABUFFER_CONTAINS#", dataBufferContainsOutput);
                        res = res.Replace("#DATABUFFER_OPS#", dataBufferOpsOutput);
                        res = res.Replace("#DATABUFFER_DATA#", dataBufferDataOutput);
                        res = res.Replace("#REGS_INIT#", regsInitOutput);
                        res = res.Replace("#REGS_FILL#", regsInitFillOutput);
                        res = res.Replace("#PUSH_REGS_INIT#", pushRegsInitOutput);
                        res = res.Replace("#PUSH_OPS#", pushOpsOutput);

                        res = res.Replace("#REGS_DISPOSE#", regsDisposeOutput);
                        res = res.Replace("#JOB_INIT_ITEMS#", regsJobInitOutput);
                        res = res.Replace("#JOB_FILL_ITEMS#", regsJobFillOutput);

                        res      = res.Replace("#INDEX#", j.ToString());
                        buffers += $"{res}\n";
                    }
                }

                if (string.IsNullOrEmpty(outputDelegates) == false)
                {
                    ME.ECSEditor.ScriptTemplates.Create(dir, "Filters.Delegates.gen.cs", "00-FilterExtensionsDelegates", new Dictionary <string, string>()
                    {
                        { "CONTENT", outputDelegates }
                    }, allowRename: false);
                }
                if (string.IsNullOrEmpty(outputForEach) == false)
                {
                    ME.ECSEditor.ScriptTemplates.Create(dir, "Filters.ForEach.gen.cs", "00-FilterExtensionsForEach", new Dictionary <string, string>()
                    {
                        { "CONTENT", outputForEach }, { "CONTENT_BUFFERS", buffers }
                    }, allowRename: false);
                }
            }
        }