コード例 #1
0
        public void OnGUI()
        {
            this.CollectEditors();

            if (this.worlds.Count != ME.ECS.Worlds.registeredWorlds.Count)
            {
                this.worlds.Clear();
                foreach (var item in ME.ECS.Worlds.registeredWorlds)
                {
                    var worldEditor = new WorldEditor();
                    worldEditor.world = item;
                    this.worlds.Add(worldEditor);
                }
            }

            GUILayoutExt.Padding(6f, () => {
                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                {
                    GUILayout.BeginVertical(GUILayout.Width(400f), GUILayout.ExpandHeight(true));
                    GUILayout.Space(4f); // Unity GUI bug: we need to add 4px space when use GUILayout.Width() control
                    var world = this.DrawWorlds();
                    GUILayout.Space(4f); // Unity GUI bug: we need to add 4px space when use GUILayout.Width() control
                    GUILayout.EndVertical();

                    GUILayout.Space(4f);

                    GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                    this.DrawEntities(world);
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            });
        }
コード例 #2
0
ファイル: ViewBaseEditor.cs プロジェクト: bagusindrayana/ecs
        public void DrawInspectorGUI(ME.ECS.Entity entity, bool drawDefaultInspector = false)
        {
            var    isMultiple = false;
            string output     = string.Empty;

            if (this.targets.Length > 1)
            {
                foreach (var t in this.targets)
                {
                    var str = t.ToString();
                    if (output != string.Empty && output != str)
                    {
                        isMultiple = true;
                    }

                    output = str;
                }
            }

            if (entity != ME.ECS.Entity.Empty)
            {
                GUILayoutExt.Box(2f, 2f, () => {
                    EditorGUILayout.HelpBox(isMultiple == true ? "-" : this.target.ToString(), MessageType.Info);

                    if (isMultiple == false)
                    {
                        GUILayoutExt.DrawEntitySelection(ME.ECS.Worlds.currentWorld, in entity, checkAlive: true);
                    }
                }, UnityEngine.GUIStyle.none);
                GUILayoutExt.Separator();
            }

            EditorGUILayout.BeginHorizontal();
            UnityEngine.GUILayout.FlexibleSpace();

            var style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.button);

            style.fontSize    = 12;
            style.fixedWidth  = 230;
            style.fixedHeight = 23;
            if (UnityEngine.GUILayout.Button("Refresh Data", style) == true)
            {
                var targets = this.targets;
                foreach (var target in targets)
                {
                    ((IDoValidate)target).DoValidate();
                    UnityEditor.EditorUtility.SetDirty(target);
                }
            }

            UnityEngine.GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (drawDefaultInspector == true)
            {
                EditorGUILayout.Space();

                this.DrawDefaultInspector();
            }
        }
コード例 #3
0
        public override void OnInspectorGUI()
        {
            var target = this.target as ME.ECS.Debug.EntityDebugComponent;

            if (target.world != null && target.world.isActive == true)
            {
                var currentEntity = GUILayoutExt.DrawEntitySelection(target.world, in target.entity, checkAlive: true, drawSelectButton: false);
                if (currentEntity.IsAlive() == true)
                {
                    if (EntityDebugComponentEditor.worldEditors.TryGetValue(target.world, out var worldEditor) == false)
                    {
                        worldEditor       = new WorldsViewerEditor.WorldEditor();
                        worldEditor.world = target.world;
                        EntityDebugComponentEditor.worldEditors.Add(target.world, worldEditor);
                    }

                    WorldsViewerEditor.DrawEntity(target.entity, worldEditor, worldEditor.GetEntitiesStorage(), worldEditor.GetStructComponentsStorage(), worldEditor.GetComponentsStorage(), worldEditor.GetModules());
                    this.Repaint();
                }
            }
            else
            {
                if (Worlds.currentWorld == null)
                {
                    GUILayout.Label("No running worlds found", EditorStyles.centeredGreyMiniLabel);
                }
                else
                {
                    GUILayoutExt.DrawAddEntityMenu(target);
                }
            }
        }
コード例 #4
0
ファイル: GUILayoutExt.cs プロジェクト: cleancoindev/ecs
        public static void FoldOut(ref bool state, string content, System.Action onContent, GUIStyle style = null)
        {
            if (style == null)
            {
                style              = new GUIStyle(EditorStyles.foldoutHeader);
                style.fixedWidth   = 0f;
                style.stretchWidth = true;

                if (GUILayoutExt.foldOutLevel == 0)
                {
                    style.fixedHeight = 24f;
                    style.richText    = true;
                    content           = "<b>" + content + "</b>";
                }
                else
                {
                    style.fixedHeight = 16f;
                    style.richText    = true;
                }
            }

            ++GUILayoutExt.foldOutLevel;
            state = GUILayoutExt.BeginFoldoutHeaderGroup(state, new GUIContent(content), style);
            if (state == true)
            {
                onContent.Invoke();
            }

            EditorGUILayout.EndFoldoutHeaderGroup();
            --GUILayoutExt.foldOutLevel;
        }
コード例 #5
0
 public virtual void OnGUI(Rect rect)
 {
     if (this.data != null)
     {
         var dataType = GUILayoutExt.GetTypeLabel(this.data.GetType());
         GUI.Label(rect, dataType, Styles.nodeCaption);
     }
 }
コード例 #6
0
ファイル: GUILayoutExt.cs プロジェクト: cleancoindev/ecs
 public static bool BeginFoldoutHeaderGroup(
     bool foldout,
     GUIContent content,
     GUIStyle style = null,
     System.Action <Rect> menuAction = null,
     GUIStyle menuIcon = null)
 {
     return(GUILayoutExt.BeginFoldoutHeaderGroup(GUILayoutUtility.GetRect(content, style), foldout, content, style, menuAction, menuIcon));
 }
コード例 #7
0
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();
            EditorGUILayout.PropertyField(this.editorComment);
            this.serializedObject.ApplyModifiedProperties();

            base.OnInspectorGUI();

            if (this.targets.Length == 1)
            {
                var target = (DataConfigTemplate)this.target;
                if (target.usedIn.Count > 0)
                {
                    GUILayoutExt.Separator(6f);
                    GUILayoutExt.DrawHeader("Used by Configs:");
                    GUILayoutExt.Separator();

                    var rect        = new Rect(0f, 0f, EditorGUIUtility.currentViewWidth, 1000f);
                    var style       = new GUIStyle("AssetLabel Partial");
                    var buttonRects = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4f, 4f, target.usedIn.Select(x => {
                        var config = x;
                        if (config == null)
                        {
                            return(string.Empty);
                        }

                        return(config.name);
                    }).ToList());
                    GUILayout.BeginHorizontal();
                    GUILayout.EndHorizontal();
                    var areaRect = GUILayoutUtility.GetLastRect();
                    for (int i = 0; i < buttonRects.Count; ++i)
                    {
                        areaRect.height = Mathf.Max(0f, buttonRects[i].yMax);
                    }

                    GUILayoutUtility.GetRect(areaRect.width, areaRect.height);

                    GUI.BeginGroup(areaRect);
                    for (int i = 0; i < target.usedIn.Count; ++i)
                    {
                        var config = target.usedIn[i];
                        if (config == null)
                        {
                            continue;
                        }

                        if (GUI.Button(buttonRects[i], config.name, style) == true)
                        {
                            EditorGUIUtility.PingObject(config);
                        }
                    }

                    GUI.EndGroup();
                }
            }
        }
コード例 #8
0
        public bool OnDrawGUI()
        {
            var isDirty = false;

            EditorGUI.BeginDisabledGroup(this.target.worldDebugSettings.showViewsOnScene == false);
            GUILayoutExt.ToggleLeft(
                ref this.target.worldDebugSettings.viewsSettings.unityParticlesProviderShowOnScene,
                ref isDirty,
                "Unity Particles View Provider",
                string.Empty);
            EditorGUI.EndDisabledGroup();

            return(isDirty);
        }
コード例 #9
0
        public bool OnDrawGUI()
        {
            var isDirty = false;

            EditorGUI.BeginDisabledGroup(this.target.worldSettings.useJobsForViews == false);
            var disabled = this.target.worldSettings.viewsSettings.unityParticlesProviderDisableJobs;

            GUILayoutExt.ToggleLeft(
                ref disabled,
                ref isDirty,
                "Disable <b>Unity Particles View Provider</b> jobs",
                "Note: If checked <b>ApplyStateJob</b> will be called in main thread");
            EditorGUI.EndDisabledGroup();
            this.target.worldSettings.viewsSettings.unityParticlesProviderDisableJobs = disabled;

            return(isDirty);
        }
コード例 #10
0
ファイル: GUILayoutExt.cs プロジェクト: cleancoindev/ecs
        public static void Box(float padding, float margin, System.Action onContent, GUIStyle style = null, params GUILayoutOption[] options)
        {
            GUILayoutExt.Padding(margin, () => {
                if (style == null)
                {
                    style = "GroupBox";
                }
                else
                {
                    style = new GUIStyle(style);
                }

                style.padding = new RectOffset();
                style.margin  = new RectOffset();

                GUILayout.BeginVertical(style, options);
                {
                    GUILayoutExt.Padding(padding, onContent);
                }
                GUILayout.EndVertical();
            }, options);
        }
コード例 #11
0
ファイル: GUILayoutExt.cs プロジェクト: cleancoindev/ecs
        public static void DrawFields(object instance, float fieldWidth)
        {
            var padding    = 2f;
            var margin     = 1f;
            var cellHeight = 24f;
            var tableStyle = new GUIStyle("Box");

            GUILayout.BeginHorizontal();
            {
                GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Field", EditorStyles.miniBoldLabel); },
                                 tableStyle, GUILayout.Width(fieldWidth),
                                 GUILayout.Height(cellHeight));
                GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Value", EditorStyles.miniBoldLabel); },
                                 tableStyle, GUILayout.ExpandWidth(true),
                                 GUILayout.Height(cellHeight));
            }
            GUILayout.EndHorizontal();

            var fields = instance.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var field in fields)
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(field.Name); }, tableStyle,
                                     GUILayout.Width(fieldWidth), GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => {
                        var value = field.GetValue(instance);
                        if (GUILayoutExt.PropertyField(field, ref value) == true)
                        {
                            field.SetValue(instance, value);
                        }
                    }, tableStyle, GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                }
                GUILayout.EndHorizontal();
            }
        }
コード例 #12
0
        private static IMGUIContainer CreateButton(DataConfigEditor editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty source, VisualElement elements, bool noFields)
        {
            var addMenuButton = new IMGUIContainer(() => {
                GUILayoutExt.DrawAddComponentMenu(usedComponents, (type, isUsed) => {
                    if (isUsed == false)
                    {
                        usedComponents.Add(type);

                        source.serializedObject.Update();
                        ++source.arraySize;
                        var elem = source.GetArrayElementAtIndex(source.arraySize - 1);
                        elem.managedReferenceValue = System.Activator.CreateInstance(type);
                        source.serializedObject.ApplyModifiedProperties();

                        if (noFields == true)
                        {
                            editor.OnAddComponentFromRemoveList(type);
                        }
                        else
                        {
                            editor.OnAddComponent(type);
                        }
                    }
                    else
                    {
                        RemoveComponent(editor, usedComponents, source, type, noFields);
                    }

                    editor.Save();
                    BuildInspectorProperties(editor, usedComponents, source, elements, noFields);
                }, showRuntime: noFields);
            });

            addMenuButton.AddToClassList("add-component-menu-button-imgui");

            return(addMenuButton);
        }
コード例 #13
0
        public static void BuildInspectorPropertiesElement(string elementPath, IEditorContainer editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty obj, UnityEngine.UIElements.VisualElement container, bool noFields, System.Action <int, PropertyField> onBuild = null)
        {
            obj = obj.Copy();
            container.Clear();
            var source = obj.Copy();
            SerializedProperty iterator = obj;

            if (iterator.NextVisible(true) == false)
            {
                return;
            }
            if (iterator.NextVisible(true) == false)
            {
                return;
            }
            var depth        = iterator.depth;
            var i            = 0;
            var iteratorNext = iterator.Copy();

            do
            {
                if (string.IsNullOrEmpty(elementPath) == false)
                {
                    iterator = iteratorNext.FindPropertyRelative(elementPath);
                }
                else
                {
                    iterator = iteratorNext;
                }
                if (iterator.propertyType != SerializedPropertyType.ManagedReference)
                {
                    continue;
                }

                var element = new VisualElement();
                element.AddToClassList("element");

                var itCopy = iterator.Copy();
                GetTypeFromManagedReferenceFullTypeName(iterator.managedReferenceFullTypename, out var type);
                element.AddToClassList(i % 2 == 0 ? "even" : "odd");
                element.RegisterCallback <UnityEngine.UIElements.ContextClickEvent, int>((evt, idx) => {
                    var menu = new GenericMenu();
                    if (usedComponents != null)
                    {
                        menu.AddItem(new GUIContent("Delete"), false, () => {
                            RemoveComponent((DataConfigEditor)editor, usedComponents, source, type, noFields);
                            editor.Save();
                            BuildInspectorProperties(editor, usedComponents, source, container, noFields);
                        });

                        menu.AddItem(new GUIContent("Copy JSON"), false, () => {
                            var instance = itCopy.GetValue();
                            var json     = JsonUtility.ToJson(instance, true);
                            EditorGUIUtility.systemCopyBuffer = json;
                        });
                    }

                    editor.OnComponentMenu(menu, idx);
                    menu.ShowAsContext();
                }, i);

                if (type != null && usedComponents?.Contains(type) == false)
                {
                    usedComponents?.Add(type);
                }
                if (type == null)
                {
                    var label = new UnityEngine.UIElements.Label("MISSING: " + iterator.managedReferenceFullTypename);
                    element.name = "missing";
                    label.AddToClassList("inner-element");
                    label.AddToClassList("missing-label");
                    element.Add(label);
                }
                else if (iterator.hasVisibleChildren == false || noFields == true)
                {
                    var horizontal = new UnityEngine.UIElements.VisualElement();
                    horizontal.AddToClassList("inner-element");
                    horizontal.AddToClassList("no-fields-container");
                    element.name = type.Name;

                    var toggle = new UnityEngine.UIElements.Toggle();
                    toggle.AddToClassList("no-fields-toggle");
                    toggle.SetEnabled(false);
                    toggle.SetValueWithoutNotify(true);
                    horizontal.Add(toggle);

                    var label = new UnityEngine.UIElements.Label(GUILayoutExt.GetStringCamelCaseSpace(type.Name));
                    label.AddToClassList("no-fields-label");
                    horizontal.Add(label);

                    element.Add(horizontal);
                }
                else
                {
                    var label = GUILayoutExt.GetStringCamelCaseSpace(type.Name);
                    if (iterator.hasVisibleChildren == true)
                    {
                        var childs = iterator.Copy();
                        //var height = EditorUtilities.GetPropertyHeight(childs, true, new GUIContent(label));
                        var cnt = EditorUtilities.GetPropertyChildCount(childs);
                        if (cnt == 1 /*&& height <= 22f*/)
                        {
                            iterator.NextVisible(true);
                        }
                    }

                    var propertyField = new PropertyField(iterator.Copy(), label);
                    propertyField.BindProperty(iterator);
                    onBuild?.Invoke(i, propertyField);
                    propertyField.AddToClassList("property-field");
                    propertyField.AddToClassList("inner-element");
                    element.name = type.Name;
                    element.Add(propertyField);
                }

                if (type != null)
                {
                    var helps = type.GetCustomAttributes(typeof(ComponentHelpAttribute), false);
                    if (helps.Length > 0)
                    {
                        var label = new UnityEngine.UIElements.Label(((ComponentHelpAttribute)helps[0]).comment);
                        label.AddToClassList("comment");
                        element.Add(label);
                    }

                    if (typeof(IComponentStatic).IsAssignableFrom(type) == true)
                    {
                        var label = new UnityEngine.UIElements.Label("Static");
                        label.AddToClassList("static-component");
                        element.AddToClassList("has-static-component");
                        element.Add(label);
                    }

                    if (typeof(IComponentShared).IsAssignableFrom(type) == true)
                    {
                        var label = new UnityEngine.UIElements.Label("Shared");
                        label.AddToClassList("shared-component");
                        element.AddToClassList("has-shared-component");
                        element.Add(label);
                    }
                }

                container.Add(element);
                ++i;
            } while (iteratorNext.NextVisible(false) == true && depth <= iteratorNext.depth);
        }
コード例 #14
0
        public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label)
        {
            ComponentDataEditor.lastDraw.Clear();

            var drawType = ComponentDataTypeAttribute.Type.WithData;

            if (this.GetAttr() is ComponentDataTypeAttribute attr)
            {
                drawType = attr.type;
            }

            var name           = "component";
            var usedComponents = new System.Collections.Generic.HashSet <System.Type>();
            {
                var backStyle = new GUIStyle(EditorStyles.label);
                backStyle.normal.background = Texture2D.whiteTexture;

                var with = property.FindPropertyRelative(name);
                FilterDataTypesEditor.GetTypeFromManagedReferenceFullTypeName(with.managedReferenceFullTypename, out var type);

                position.height = ComponentDataEditor.lineHeight;
                if (type == null)
                {
                    //Debug.Log("Not found: " + with.managedReferenceFullTypename + ", " + with.managedReferenceFieldTypename);
                    EditorGUI.LabelField(position, "Component is not defined");

                    position.y += ComponentDataEditor.lineHeight;
                }
                else
                {
                    usedComponents.Add(type);

                    EditorGUI.LabelField(position, type.Name, EditorStyles.boldLabel);
                    position.y += ComponentDataEditor.lineHeight;

                    if (drawType == ComponentDataTypeAttribute.Type.WithData)
                    {
                        using (new GUILayoutExt.GUIBackgroundAlphaUsing(0.5f)) {
                            var isDirty = false;
                            {
                                //var componentName = GUILayoutExt.GetStringCamelCaseSpace(type.Name);
                                var initDepth = with.depth;
                                if (with.NextVisible(with.hasChildren) == true)
                                {
                                    do
                                    {
                                        if (with.depth < initDepth)
                                        {
                                            break;
                                        }

                                        ComponentDataEditor.lastDraw.Add(new ComponentDataProperty()
                                        {
                                            position = position,
                                            property = with.propertyPath,
                                            so       = with.serializedObject,
                                        });

                                        EditorGUI.BeginChangeCheck();
                                        EditorGUI.PropertyField(position, with, true);
                                        position.y += EditorGUI.GetPropertyHeight(with, true);
                                        if (EditorGUI.EndChangeCheck() == true)
                                        {
                                            isDirty = true;
                                        }
                                    } while (with.NextVisible(false) == true);
                                }
                            }

                            if (isDirty == true)
                            {
                                var obj = property.serializedObject;
                                if (obj.targetObject is IValidateEditor validateEditor)
                                {
                                    obj.ApplyModifiedProperties();
                                    obj.Update();
                                    validateEditor.OnValidateEditor();
                                    EditorUtility.SetDirty(obj.targetObject);
                                    obj.ApplyModifiedProperties();
                                    obj.Update();
                                }
                            }
                        }
                    }
                }
            }
            {
                var obj = property.serializedObject;
                GUILayoutExt.DrawAddComponentMenu(position, usedComponents, (addType, isUsed) => {
                    obj.Update();
                    var prop = obj.FindProperty(property.propertyPath);
                    var with = prop.FindPropertyRelative(name);
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        with.managedReferenceValue = null;
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        with.managedReferenceValue = (IStructComponentBase)System.Activator.CreateInstance(addType);
                    }

                    if (obj.targetObject is IValidateEditor validateEditor)
                    {
                        obj.ApplyModifiedProperties();
                        obj.Update();
                        validateEditor.OnValidateEditor();
                        EditorUtility.SetDirty(obj.targetObject);
                        obj.ApplyModifiedProperties();
                        obj.Update();
                    }
                    obj.ApplyModifiedProperties();
                });
            }
        }
コード例 #15
0
        private WorldEditor DrawWorlds()
        {
            WorldEditor selectedWorld = null;
            var         style         = EditorStyles.helpBox;

            this.scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, style, GUILayout.ExpandHeight(true));
            {
                if (this.worlds.Count == 0)
                {
                    var centeredStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
                    centeredStyle.stretchHeight = true;
                    centeredStyle.richText      = true;
                    GUILayout.Label("This is runtime utility to view current running worlds.\nPress <b>Play</b> to start profiling.", centeredStyle);
                }
                else
                {
                    foreach (var worldEditor in this.worlds)
                    {
                        var systems         = worldEditor.GetSystems();
                        var modules         = worldEditor.GetModules();
                        var entitiesStorage = worldEditor.GetEntitiesStorage();
                        var filters         = worldEditor.GetFilters();
                        var world           = worldEditor.world;

                        GUILayoutExt.Padding(4f, () => {
                            GUILayoutExt.FoldOut(ref worldEditor.foldout, worldEditor.ToString() + " (Hash: " + worldEditor.world.GetStateHash() + ")", () => {
                                GUILayoutExt.Box(2f, 4f, () => {
                                    GUILayout.Label("Last Entity Id: " + worldEditor.world.GetLastEntityId().ToString());
                                    GUILayout.Label("State Tick: " + worldEditor.world.GetStateTick().ToString());
                                    GUILayout.Label("Tick: " + worldEditor.world.GetCurrentTick().ToString());
                                    GUILayout.Label("Tick Time: " + worldEditor.world.GetTickTime().ToString() + "ms.");
                                    GUILayout.Label("Time: " + ME.ECS.MathUtils.SecondsToString(worldEditor.world.GetTimeSinceStart()));
                                });

                                GUILayoutExt.FoldOut(ref worldEditor.foldoutSystems, "Systems (" + systems.Count.ToString() + ")", () => {
                                    var cellHeight = 25f;
                                    var padding    = 2f;
                                    var margin     = 1f;
                                    var col1       = 250f;
                                    var col2       = 50f;
                                    var col3       = 50f;
                                    var tableStyle = (GUIStyle)"Box";
                                    var dataStyle  = new GUIStyle(EditorStyles.label);
                                    GUILayoutExt.Padding(4f, () => {
                                        GUILayout.BeginHorizontal();
                                        {
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Caption", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.Width(col1),
                                                             GUILayout.Height(cellHeight));
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Logic", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.Width(col2),
                                                             GUILayout.Height(cellHeight));
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Visual", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.Width(col3),
                                                             GUILayout.Height(cellHeight));
                                        }
                                        GUILayout.EndHorizontal();

                                        foreach (var system in systems)
                                        {
                                            GUILayout.BeginHorizontal();
                                            {
                                                GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TypeLabel(system.GetType()); }, tableStyle, GUILayout.Width(col1),
                                                                 GUILayout.Height(cellHeight));
                                            }
                                            { // Logic
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                                                    GUILayout.FlexibleSpace();

                                                    var flag  = world.GetSystemState(system);
                                                    var state = (flag & ME.ECS.ModuleState.LogicInactive) == 0;
                                                    if (this.ToggleMethod(worldEditor, system, "AdvanceTick", ref state) == true)
                                                    {
                                                        world.SetSystemState(
                                                            system, state == false ? flag | ME.ECS.ModuleState.LogicInactive : flag & ~ME.ECS.ModuleState.LogicInactive);
                                                    }

                                                    GUILayout.FlexibleSpace();
                                                    GUILayout.EndHorizontal();
                                                }, tableStyle, GUILayout.Width(col2), GUILayout.Height(cellHeight));
                                            }
                                            { // Visual
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                                                    GUILayout.FlexibleSpace();

                                                    var flag  = world.GetSystemState(system);
                                                    var state = (flag & ME.ECS.ModuleState.VisualInactive) == 0;
                                                    if (this.ToggleMethod(worldEditor, system, "Update", ref state) == true)
                                                    {
                                                        world.SetSystemState(
                                                            system, state == false ? flag | ME.ECS.ModuleState.VisualInactive : flag & ~ME.ECS.ModuleState.VisualInactive);
                                                    }

                                                    GUILayout.FlexibleSpace();
                                                    GUILayout.EndHorizontal();
                                                }, tableStyle, GUILayout.Width(col3), GUILayout.Height(cellHeight));
                                            }
                                            GUILayout.EndHorizontal();

                                            {
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    /*if (system is IGUIEditor systemEditor) {
                                                     *
                                                     *  systemEditor.OnDrawGUI();
                                                     *
                                                     * }*/
                                                }, tableStyle, GUILayout.ExpandWidth(true));
                                                GUILayout.Space(2f);
                                            }
                                        }
                                    });
                                });

                                GUILayoutExt.FoldOut(ref worldEditor.foldoutModules, "Modules (" + modules.Count.ToString() + ")", () => {
                                    var cellHeight     = 25f;
                                    var padding        = 2f;
                                    var margin         = 1f;
                                    var col2           = 50f;
                                    var col3           = 50f;
                                    var tableStyle     = (GUIStyle)"Box";
                                    var dataStyle      = new GUIStyle(EditorStyles.label);
                                    dataStyle.richText = true;
                                    dataStyle.wordWrap = true;
                                    GUILayoutExt.Padding(4f, () => {
                                        GUILayout.BeginHorizontal();
                                        {
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Caption", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.ExpandWidth(true),
                                                             GUILayout.Height(cellHeight));
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Logic", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.Width(col2),
                                                             GUILayout.Height(cellHeight));
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Visual", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.Width(col3),
                                                             GUILayout.Height(cellHeight));
                                            //GUILayoutExt.Box(2f, 1f, () => { GUILayoutExt.TableCaption("Info", EditorStyles.miniBoldLabel); }, tableStyle,
                                            //                 GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                                        }
                                        GUILayout.EndHorizontal();

                                        foreach (var module in modules)
                                        {
                                            GUILayout.BeginHorizontal();
                                            {
                                                GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TypeLabel(module.GetType()); }, tableStyle, GUILayout.ExpandWidth(true),
                                                                 GUILayout.Height(cellHeight));
                                            }
                                            { // Logic
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                                                    GUILayout.FlexibleSpace();

                                                    var flag  = world.GetModuleState(module);
                                                    var state = (flag & ME.ECS.ModuleState.LogicInactive) == 0;
                                                    if (this.ToggleMethod(worldEditor, module, "AdvanceTick", ref state) == true)
                                                    {
                                                        world.SetModuleState(
                                                            module, state == false ? flag | ME.ECS.ModuleState.LogicInactive : flag & ~ME.ECS.ModuleState.LogicInactive);
                                                    }

                                                    GUILayout.FlexibleSpace();
                                                    GUILayout.EndHorizontal();
                                                }, tableStyle, GUILayout.Width(col2), GUILayout.Height(cellHeight));
                                            }
                                            { // Visual
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                                                    GUILayout.FlexibleSpace();

                                                    var flag  = world.GetModuleState(module);
                                                    var state = (flag & ME.ECS.ModuleState.VisualInactive) == 0;
                                                    if (this.ToggleMethod(worldEditor, module, "Update", ref state) == true)
                                                    {
                                                        world.SetModuleState(
                                                            module, state == false ? flag | ME.ECS.ModuleState.VisualInactive : flag & ~ME.ECS.ModuleState.VisualInactive);
                                                    }

                                                    GUILayout.FlexibleSpace();
                                                    GUILayout.EndHorizontal();
                                                }, tableStyle, GUILayout.Width(col3), GUILayout.Height(cellHeight));
                                            }
                                            GUILayout.EndHorizontal();

                                            {
                                                GUILayoutExt.Box(padding, margin, () => {
                                                    var editor = this.GetEditor(module);
                                                    if (editor != null)
                                                    {
                                                        editor.OnDrawGUI();
                                                    }
                                                }, tableStyle, GUILayout.ExpandWidth(true));
                                                GUILayout.Space(2f);
                                            }
                                        }
                                    });
                                });

                                var entitiesCount = 0;
                                foreach (var entityStorage in entitiesStorage)
                                {
                                    if (entityStorage == null)
                                    {
                                        continue;
                                    }

                                    var storages = entityStorage.Cast <ME.ECS.IStorage>().ToList();
                                    foreach (var storage in storages)
                                    {
                                        if (storage == null)
                                        {
                                            continue;
                                        }

                                        entitiesCount += storage.Count;
                                    }
                                }

                                GUILayoutExt.FoldOut(ref worldEditor.foldoutEntitiesStorage, "Entities (" + entitiesCount.ToString() + ")", () => {
                                    var cellHeight = 25f;
                                    var padding    = 2f;
                                    var margin     = 1f;
                                    //var col1 = 80f;
                                    var tableStyle     = (GUIStyle)"Box";
                                    var dataStyle      = new GUIStyle(EditorStyles.label);
                                    dataStyle.richText = true;
                                    GUILayoutExt.Padding(4f, () => {
                                        GUILayout.BeginHorizontal();
                                        {
                                            /*GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Caption", EditorStyles.miniBoldLabel); }, tableStyle,
                                             *               GUILayout.Width(col1),
                                             *               GUILayout.Height(cellHeight));*/
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Data", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                                        }
                                        GUILayout.EndHorizontal();

                                        GUILayout.BeginVertical();
                                        foreach (var entityStorage in entitiesStorage)
                                        {
                                            if (entityStorage == null)
                                            {
                                                continue;
                                            }

                                            var storages = entityStorage.Cast <ME.ECS.IStorage>().ToList();
                                            foreach (var storage in storages)
                                            {
                                                if (storage == null)
                                                {
                                                    continue;
                                                }

                                                GUILayout.BeginHorizontal();
                                                {
                                                    GUILayoutExt.Box(
                                                        padding,
                                                        margin,
                                                        () => {
                                                        GUILayoutExt.TypeLabel(storage.GetType());
                                                        GUILayout.Label(storage.ToString(), dataStyle);
                                                    },
                                                        tableStyle,
                                                        GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                                                }
                                                GUILayout.EndHorizontal();
                                            }
                                        }
                                        GUILayout.EndVertical();
                                    });
                                });

                                var filtersCount = filters.Count;
                                GUILayoutExt.FoldOut(ref worldEditor.foldoutFilters, "Filters (" + filtersCount.ToString() + ")", () => {
                                    var cellHeight = 25f;
                                    var padding    = 2f;
                                    var margin     = 1f;
                                    //var col1 = 80f;
                                    var tableStyle     = (GUIStyle)"Box";
                                    var dataStyle      = new GUIStyle(EditorStyles.label);
                                    dataStyle.richText = true;
                                    GUILayoutExt.Padding(4f, () => {
                                        GUILayout.BeginHorizontal();
                                        {
                                            /*GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Caption", EditorStyles.miniBoldLabel); }, tableStyle,
                                             *               GUILayout.Width(col1),
                                             *               GUILayout.Height(cellHeight));*/
                                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Data", EditorStyles.miniBoldLabel); }, tableStyle,
                                                             GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                                        }
                                        GUILayout.EndHorizontal();

                                        GUILayout.BeginVertical();
                                        foreach (var filter in filters.GetData())
                                        {
                                            GUILayout.BeginHorizontal();
                                            {
                                                GUILayoutExt.Box(
                                                    padding,
                                                    margin,
                                                    () => {
                                                    GUILayoutExt.TypeLabel(filter.GetType());
                                                    GUILayout.Label(filter.ToString(), dataStyle);
                                                },
                                                    tableStyle,
                                                    GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                                            }
                                            GUILayout.EndHorizontal();
                                        }
                                        GUILayout.EndVertical();
                                    });
                                });
                            });

                            if (worldEditor.foldout == true)
                            {
                                selectedWorld = worldEditor;

                                // Fold in all others
                                foreach (var wEditor in this.worlds)
                                {
                                    if (wEditor != worldEditor)
                                    {
                                        wEditor.foldout = false;
                                    }
                                }
                            }
                        });

                        GUILayoutExt.Separator();
                    }
                }
            }
            GUILayout.EndScrollView();

            return(selectedWorld);
        }
コード例 #16
0
        private void DrawEntities(WorldEditor world)
        {
            var style = EditorStyles.helpBox;

            this.scrollEntitiesPosition = GUILayout.BeginScrollView(this.scrollEntitiesPosition, style, GUILayout.ExpandHeight(true));
            {
                if (world == null)
                {
                    var centeredStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel);
                    centeredStyle.stretchHeight = true;
                    centeredStyle.richText      = true;
                    GUILayout.Label("Select world from the left list.", centeredStyle);
                }
                else
                {
                    var padding   = 2f;
                    var margin    = 1f;
                    var dataStyle = new GUIStyle(EditorStyles.label);
                    dataStyle.richText = true;
                    dataStyle.wordWrap = true;

                    var modules = world.GetModules();

                    //var componentsStorage = world.GetComponentsStorage();
                    var entitiesStorage = world.GetEntitiesStorage();
                    foreach (var entityStorage in entitiesStorage)
                    {
                        if (entityStorage == null)
                        {
                            continue;
                        }

                        var storages = entityStorage.Cast <ME.ECS.IStorage>().ToList();
                        foreach (var storage in storages)
                        {
                            if (storage == null)
                            {
                                continue;
                            }

                            GUILayout.BeginVertical();
                            {
                                var foldout = world.IsFoldOut(storage);
                                GUILayoutExt.FoldOut(ref foldout, GUILayoutExt.GetTypeLabel(storage.GetType()), () => {
                                    var list = storage.GetData();
                                    for (var i = list.FromIndex; i < list.SizeCount; ++i)
                                    {
                                        if (list.IsFree(i) == true)
                                        {
                                            continue;
                                        }

                                        var item       = list.Get <ME.ECS.IEntity>(i);
                                        var entityData = item;

                                        GUILayoutExt.Box(
                                            padding,
                                            margin,
                                            () => {
                                            GUILayout.Space(2f);
                                            GUILayout.Label("Entity " + entityData.entity.id.ToString() + " (" + entityData.entity.storageIdx.ToString() + ")");

                                            GUILayoutExt.Box(
                                                padding,
                                                margin,
                                                () => {
                                                #region Data
                                                var foldoutData = world.IsFoldOutData(storage, entityData.entity.id);
                                                GUILayoutExt.FoldOut(ref foldoutData, "Data", () => {
                                                    {         // Draw data table
                                                        GUILayoutExt.DrawFields(item, 120f);
                                                    }
                                                });
                                                world.SetFoldOutData(storage, entityData.entity.id, foldoutData);
                                                #endregion

                                                #region Components
                                                var foldoutComponents = world.IsFoldOutComponents(storage, entityData.entity.id);
                                                GUILayoutExt.FoldOut(ref foldoutComponents, "Components", () => {
                                                    GUILayout.Label("Due to technical issues components list is not supported for now", EditorStyles.miniBoldLabel);

                                                    /*ME.ECS.IComponentsBase components;
                                                     * if (componentsStorage.TryGetValue(entityData.entity.id, out components) == true) {
                                                     *
                                                     *  var componentsDic = components.GetData(entityData.entity.id);
                                                     *  foreach (var component in componentsDic) {
                                                     *
                                                     *      GUILayoutExt.Box(
                                                     *          padding,
                                                     *          margin,
                                                     *          () => {
                                                     *
                                                     *              GUILayout.Space(2f);
                                                     *              GUILayout.BeginHorizontal();
                                                     *              GUILayout.Label(component.GetType().Name, GUILayout.Width(90f));
                                                     *              GUILayoutExt.TypeLabel(component.GetType());
                                                     *              GUILayout.EndHorizontal();
                                                     *
                                                     *              GUILayoutExt.Box(
                                                     *                  padding,
                                                     *                  margin,
                                                     *                  () => {
                                                     *
                                                     *                      GUILayout.Label("Data", EditorStyles.miniBoldLabel);
                                                     *                      GUILayoutExt.DrawFields(component, 120f);
                                                     *
                                                     *                  }, GUIStyle.none);
                                                     *
                                                     *          }, "dragtabdropwindow");
                                                     *
                                                     *  }
                                                     *
                                                     * }*/
                                                });
                                                world.SetFoldOutComponents(storage, entityData.entity.id, foldoutComponents);
                                                #endregion

                                                        #if VIEWS_MODULE_SUPPORT
                                                var foldoutViews = world.IsFoldOutViews(storage, entityData.entity.id);
                                                GUILayoutExt.FoldOut(ref foldoutViews, "Views", () => {
                                                    {         // Draw views table
                                                        var viewsModules = modules.OfType <ME.ECS.Views.IViewModuleBase>().ToArray();
                                                        foreach (var viewsModule in viewsModules)
                                                        {
                                                            if (viewsModule != null)
                                                            {
                                                                var allViews = viewsModule.GetData();
                                                                foreach (DictionaryEntry itemEntry in allViews)
                                                                {
                                                                    var key = (EntityId)itemEntry.Key;
                                                                    if (key == entityData.entity.id)
                                                                    {
                                                                        var listViews = (IList)itemEntry.Value;
                                                                        for (int j = 0; j < listViews.Count; ++j)
                                                                        {
                                                                            var view = (ME.ECS.Views.IViewBase)listViews[j];
                                                                            GUILayoutExt.Box(
                                                                                padding,
                                                                                margin,
                                                                                () => {
                                                                                GUILayout.Label("Prefab Source Id: " + view.prefabSourceId.ToString());
                                                                                var provider = viewsModule.GetViewSourceProvider(view.prefabSourceId);
                                                                                GUILayout.Label("Provider: " + GUILayoutExt.GetTypeLabel(provider.GetType()));
                                                                                GUILayout.Label("Creation Tick: " + view.creationTick.ToString());
                                                                            });
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                });
                                                world.SetFoldOutViews(storage, entityData.entity.id, foldoutViews);
                                                        #endif
                                            }, GUIStyle.none);
                                        },
                                            "dragtabdropwindow");

                                        list.Set(i, entityData);
                                    }
                                });
                                world.SetFoldOut(storage, foldout);
                            }
                            GUILayout.EndVertical();
                        }
                    }
                }
            }
            GUILayout.EndScrollView();
        }
コード例 #17
0
        public override void OnInspectorGUI()
        {
            var dataConfig = (ME.ECS.DataConfigs.DataConfig) this.target;

            if (dataConfig is ME.ECS.DataConfigs.DataConfigTemplate == false)
            {
                foreach (var target in this.targets)
                {
                    var dc = (ME.ECS.DataConfigs.DataConfig)target;
                    if (dc.sharedGroupId == 0)
                    {
                        dc.sharedGroupId = ME.ECS.MathUtils.GetHash(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(dc)));
                        this.Save(dc);
                    }
                }

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                this.serializedObject.Update();
                var sharedIdLabelStyle = new GUIStyle(EditorStyles.miniBoldLabel);
                sharedIdLabelStyle.alignment = TextAnchor.MiddleRight;
                EditorGUILayout.LabelField("Shared ID:", sharedIdLabelStyle);
                EditorGUILayout.PropertyField(this.sharedGroupId, new GUIContent(string.Empty), GUILayout.Width(100f));
                this.serializedObject.ApplyModifiedProperties();
                GUILayout.EndHorizontal();
            }

            this.search = GUILayoutExt.SearchField("Search", this.search);

            {
                var style = new GUIStyle(EditorStyles.toolbar);
                style.fixedHeight   = 0f;
                style.stretchHeight = true;

                var backStyle = new GUIStyle(EditorStyles.label);
                backStyle.normal.background = Texture2D.whiteTexture;

                var slice      = new ME.ECS.DataConfigs.DataConfigSlice();
                var isMultiple = false;
                if (this.targets.Length > 1)
                {
                    slice      = ME.ECS.DataConfigs.DataConfigSlice.Distinct(this.targets.Cast <ME.ECS.DataConfigs.DataConfig>().ToArray());
                    isMultiple = true;
                }
                else
                {
                    var config = (ME.ECS.DataConfigs.DataConfig) this.target;
                    slice = new ME.ECS.DataConfigs.DataConfigSlice()
                    {
                        configs = new[] {
                            config
                        },
                        structComponentsTypes = config.structComponents.Where(x => x != null).Select(x => x.GetType()).ToArray(),
                    };
                }

                var usedComponentsAll = new System.Collections.Generic.HashSet <System.Type>();
                foreach (var cfg in slice.configs)
                {
                    var componentTypes = cfg.GetStructComponentTypes();
                    foreach (var cType in componentTypes)
                    {
                        if (usedComponentsAll.Contains(cType) == false)
                        {
                            usedComponentsAll.Add(cType);
                        }
                    }

                    if (DataConfigEditor.worldEditors.TryGetValue(cfg, out var worldEditor) == false)
                    {
                        worldEditor = new WorldsViewerEditor.WorldEditor();
                        DataConfigEditor.worldEditors.Add(cfg, worldEditor);
                    }
                }

                if (isMultiple == true)
                {
                    GUILayoutExt.DrawHeader("The Same Components:");

                    GUILayoutExt.Padding(4f, () => {
                        var kz = 0;
                        for (int i = 0; i < slice.structComponentsTypes.Length; ++i)
                        {
                            var type      = slice.structComponentsTypes[i];
                            var component = slice.configs[0].GetByType(slice.configs[0].structComponents, type);
                            if (GUILayoutExt.IsSearchValid(component, this.search) == false)
                            {
                                continue;
                            }
                            var components = slice.configs.Select(x => x.GetByType(x.structComponents, type)).ToArray();

                            var backColor       = GUI.backgroundColor;
                            GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                            GUILayout.BeginVertical(backStyle);
                            {
                                GUI.backgroundColor = backColor;
                                var editor          = WorldsViewerEditor.GetEditor(components);
                                if (editor != null)
                                {
                                    EditorGUI.BeginChangeCheck();
                                    editor.OnDrawGUI();
                                    if (EditorGUI.EndChangeCheck() == true)
                                    {
                                        slice.Set(components);
                                        this.Save(slice.configs);
                                    }
                                }
                                else
                                {
                                    var componentName = GUILayoutExt.GetStringCamelCaseSpace(component.GetType().Name);
                                    var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                                    if (fieldsCount == 0)
                                    {
                                        EditorGUI.BeginDisabledGroup(true);
                                        EditorGUILayout.Toggle(componentName, true);
                                        EditorGUI.EndDisabledGroup();
                                    }
                                    else if (fieldsCount == 1)
                                    {
                                        var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, components, componentName);
                                        if (changed == true)
                                        {
                                            slice.Set(components);
                                            this.Save(slice.configs);
                                        }
                                    }
                                    else
                                    {
                                        GUILayout.BeginHorizontal();
                                        {
                                            GUILayout.Space(18f);
                                            GUILayout.BeginVertical();
                                            {
                                                var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                                var foldout = EditorPrefs.GetBool(key, true);
                                                GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                                    var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, components);
                                                    if (changed == true)
                                                    {
                                                        slice.Set(components);
                                                        this.Save(slice.configs);
                                                    }
                                                });
                                                EditorPrefs.SetBool(key, foldout);
                                            }
                                            GUILayout.EndVertical();
                                        }
                                        GUILayout.EndHorizontal();
                                    }
                                }

                                GUILayoutExt.DrawComponentHelp(component.GetType());
                                this.DrawShared(component);
                            }
                            GUILayout.EndVertical();

                            GUILayoutExt.Separator();
                        }
                    });

                    GUILayoutExt.DrawAddComponentMenu(usedComponentsAll, (addType, isUsed) => {
                        foreach (var dataConfigInner in slice.configs)
                        {
                            if (isUsed == true)
                            {
                                this.OnRemoveComponent(addType);
                                usedComponentsAll.Remove(addType);
                                for (int i = 0; i < dataConfigInner.structComponents.Length; ++i)
                                {
                                    if (dataConfigInner.structComponents[i].GetType() == addType)
                                    {
                                        var list = dataConfigInner.structComponents.ToList();
                                        list.RemoveAt(i);
                                        dataConfigInner.structComponents = list.ToArray();
                                        //dataConfigInner.OnScriptLoad();
                                        this.Save(dataConfigInner);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                usedComponentsAll.Add(addType);
                                System.Array.Resize(ref dataConfigInner.structComponents, dataConfigInner.structComponents.Length + 1);
                                dataConfigInner.structComponents[dataConfigInner.structComponents.Length - 1] = (IStructComponentBase)System.Activator.CreateInstance(addType);
                                //dataConfigInner.OnScriptLoad();
                                this.Save(dataConfigInner);
                                this.OnAddComponent(addType);
                            }
                        }
                    });

                    return;
                }

                GUILayoutExt.DrawHeader("Add Struct Components:");
                GUILayoutExt.Separator();

                GUILayoutExt.Padding(4f, () => {
                    var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                    this.serializedObject.Update();
                    if (GUILayoutExt.DrawFieldsSingle(this.search, this, DataConfigEditor.multipleWorldEditor, dataConfig.structComponents,
                                                      (index, component, prop) => {
                        GUILayout.BeginVertical();
                    },
                                                      (index, component, prop) => {
                        if (component == null)
                        {
                            return;
                        }

                        usedComponents.Add(component.GetType());

                        GUILayoutExt.DrawComponentHelp(component.GetType());
                        this.DrawComponentTemplatesUsage(dataConfig, component);
                        this.DrawShared(component);

                        GUILayout.EndVertical();

                        {
                            var lastRect = GUILayoutUtility.GetLastRect();
                            if (Event.current.type == EventType.ContextClick && lastRect.Contains(Event.current.mousePosition) == true)
                            {
                                var menu = new GenericMenu();
                                if (this.CanMove(dataConfig, index, index - 1) == true)
                                {
                                    menu.AddItem(new GUIContent("Move Up"), false, () => { this.MoveElement(dataConfig, index, index - 1); });
                                }
                                else
                                {
                                    menu.AddDisabledItem(new GUIContent("Move Up"));
                                }

                                if (this.CanMove(dataConfig, index, index + 1) == true)
                                {
                                    menu.AddItem(new GUIContent("Move Down"), false, () => { this.MoveElement(dataConfig, index, index + 1); });
                                }
                                else
                                {
                                    menu.AddDisabledItem(new GUIContent("Move Down"));
                                }

                                menu.AddItem(new GUIContent("Delete"), false, () => {
                                    var list = dataConfig.structComponents.ToList();
                                    this.OnRemoveComponent(list[index].GetType());
                                    list.RemoveAt(index);
                                    dataConfig.structComponents = list.ToArray();
                                    //dataConfig.OnScriptLoad();
                                    this.Save(dataConfig);
                                });

                                this.OnComponentMenu(menu, index);

                                menu.ShowAsContext();
                            }
                        }

                        GUILayoutExt.Separator();
                    }) == true)
                    {
                        this.serializedObject.ApplyModifiedProperties();
                        this.Save(dataConfig);
                    }

                    GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                        if (isUsed == true)
                        {
                            this.OnRemoveComponent(addType);
                            usedComponents.Remove(addType);
                            for (int i = 0; i < dataConfig.structComponents.Length; ++i)
                            {
                                if (dataConfig.structComponents[i].GetType() == addType)
                                {
                                    var list = dataConfig.structComponents.ToList();
                                    list.RemoveAt(i);
                                    dataConfig.structComponents = list.ToArray();
                                    //dataConfig.OnScriptLoad();
                                    this.Save(dataConfig);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            usedComponents.Add(addType);
                            System.Array.Resize(ref dataConfig.structComponents, dataConfig.structComponents.Length + 1);
                            dataConfig.structComponents[dataConfig.structComponents.Length - 1] = (IStructComponentBase)System.Activator.CreateInstance(addType);
                            //dataConfig.OnScriptLoad();
                            this.Save(dataConfig);
                            this.OnAddComponent(addType);
                        }
                    });
                });

                GUILayoutExt.DrawHeader("Remove Struct Components:");
                GUILayoutExt.Separator();

                // Remove struct components
                GUILayoutExt.Padding(4f, () => {
                    var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                    var kz         = 0;
                    var registries = dataConfig.removeStructComponents;
                    for (int i = 0; i < registries.Length; ++i)
                    {
                        var registry = registries[i];
                        if (GUILayoutExt.IsSearchValid(registry, this.search) == false)
                        {
                            continue;
                        }
                        var type = registry.GetType();

                        usedComponents.Add(type);

                        var backColor       = GUI.backgroundColor;
                        GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                        GUILayout.BeginVertical(backStyle);
                        {
                            GUI.backgroundColor = backColor;
                            var componentName   = GUILayoutExt.GetStringCamelCaseSpace(type.Name);

                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.Toggle(componentName, true);
                            EditorGUI.EndDisabledGroup();

                            GUILayoutExt.DrawComponentHelp(type);
                            this.DrawComponentTemplatesUsage(dataConfig, dataConfig.removeStructComponents[i]);
                        }
                        GUILayout.EndVertical();

                        GUILayoutExt.Separator();
                    }

                    GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                        if (isUsed == true)
                        {
                            this.OnRemoveComponentFromRemoveList(addType);
                            usedComponents.Remove(addType);
                            for (int i = 0; i < dataConfig.removeStructComponents.Length; ++i)
                            {
                                if (dataConfig.removeStructComponents[i].GetType() == addType)
                                {
                                    var list = dataConfig.removeStructComponents.ToList();
                                    list.RemoveAt(i);
                                    dataConfig.removeStructComponents = list.ToArray();
                                    //dataConfig.OnScriptLoad();
                                    this.Save(dataConfig);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            usedComponents.Add(addType);
                            System.Array.Resize(ref dataConfig.removeStructComponents, dataConfig.removeStructComponents.Length + 1);
                            dataConfig.removeStructComponents[dataConfig.removeStructComponents.Length - 1] = (IStructComponentBase)System.Activator.CreateInstance(addType);
                            //dataConfig.OnScriptLoad();
                            this.Save(dataConfig);
                            this.OnAddComponentFromRemoveList(addType);
                        }
                    });
                });

                if ((dataConfig is ME.ECS.DataConfigs.DataConfigTemplate) == false)
                {
                    this.DrawTemplates(dataConfig);
                }
            }
        }
コード例 #18
0
        private void OnDrawListItem(Rect rect, int index, bool isActive, bool isFocused)
        {
            var featureData = (FeaturesList.FeatureData) this.list.list[index];

            rect.height = InitializerEditor.ONE_LINE_HEIGHT;

            var rectCheckBox = new Rect(rect);

            rectCheckBox.width = 20f;

            var isDirty = false;

            {
                rect.y      += 1f;
                rect.height -= 2f;

                var rectObjectField = new Rect(rect);
                rectObjectField.x     += rectCheckBox.width;
                rectObjectField.width -= rectCheckBox.width;

                var oldColor = GUI.color;
                if (featureData.enabled == false)
                {
                    GUI.color = new Color(oldColor.r, oldColor.g, oldColor.b, 0.5f);
                }

                var obj = (FeatureBase)EditorGUI.ObjectField(rectObjectField, featureData.feature, typeof(FeatureBase), allowSceneObjects: false);
                if (obj != featureData.feature)
                {
                    featureData.feature = obj;

                    var count = 0;
                    for (int i = 0; i < this.list.count; ++i)
                    {
                        var data = (FeaturesList.FeatureData) this.list.list[i];
                        if (data.feature != null && featureData.feature != null && featureData.feature == data.feature)
                        {
                            ++count;
                        }
                    }

                    if (count > 1)
                    {
                        featureData.feature = null;
                    }

                    isDirty = true;
                }

                GUI.color = oldColor;

                if (featureData.feature == null)
                {
                    featureData.enabled = false;
                }

                EditorGUI.BeginDisabledGroup(featureData.feature == null);
                var flag = GUI.Toggle(rectCheckBox, featureData.enabled, string.Empty);
                if (flag != featureData.enabled)
                {
                    featureData.enabled = flag;
                    isDirty             = true;
                }
                EditorGUI.EndDisabledGroup();
            }

            if (featureData.feature != null)   // Draw feature

            {
                rect.x += rectCheckBox.width + 14f;

                var editorComment = featureData.feature.editorComment;
                if (string.IsNullOrEmpty(editorComment) == false)
                {
                    var style   = EditorStyles.label;
                    var content = new GUIContent(editorComment);
                    var newRect = new Rect(rect);
                    newRect.height = style.CalcHeight(content, rect.width);
                    newRect.width  = rect.width;
                    newRect.y     += InitializerEditor.ONE_LINE_HEIGHT;
                    GUI.Label(newRect, content, style);
                    rect.y += newRect.height;
                }

                var count = this.GetSystemsCount(featureData.feature);
                if (count > 0)
                {
                    rect.y += InitializerEditor.ONE_LINE_HEIGHT;
                    var isOpen = GUILayoutExt.BeginFoldoutHeaderGroup(rect, this.IsSystemFoldout(featureData.feature), new GUIContent(string.Format("Systems ({0})", count)));
                    this.SetSystemFoldout(featureData.feature, isOpen);
                    if (isOpen == true)
                    {
                        var systems = this.GetSystems(featureData.feature);
                        foreach (var system in systems)
                        {
                            rect.y += InitializerEditor.ONE_LINE_HEIGHT;
                            GUI.Label(rect, system, EditorStyles.label);
                        }
                    }
                }

                count = this.GetModulesCount(featureData.feature);
                if (count > 0)
                {
                    rect.y += InitializerEditor.ONE_LINE_HEIGHT;
                    var isOpen = GUILayoutExt.BeginFoldoutHeaderGroup(rect, this.IsModuleFoldout(featureData.feature), new GUIContent(string.Format("Modules ({0})", count)));
                    this.SetModuleFoldout(featureData.feature, isOpen);
                    if (isOpen == true)
                    {
                        var systems = this.GetModules(featureData.feature);
                        foreach (var system in systems)
                        {
                            rect.y += InitializerEditor.ONE_LINE_HEIGHT;
                            GUI.Label(rect, system, EditorStyles.label);
                        }
                    }
                }
            }

            if (isDirty == true)
            {
                EditorUtility.SetDirty(this.target);
            }
        }
コード例 #19
0
        public override void OnInspectorGUI()
        {
            ((Component)this.target).transform.hideFlags = HideFlags.HideInInspector;

            GUILayoutExt.CollectEditors <IDebugViewGUIEditor <InitializerBase>, ViewProviderCustomEditorAttribute>(ref this.viewsDebugEditors);
            GUILayoutExt.CollectEditors <IJobsViewGUIEditor <InitializerBase>, ViewProviderCustomEditorAttribute>(ref this.viewsJobsEditors);

            var target = this.target as InitializerBase;

            if (target.featuresList == null)
            {
                target.featuresList = new FeaturesList();
            }
            if (target.featuresList.features == null)
            {
                target.featuresList.features = new System.Collections.Generic.List <FeaturesList.FeatureData>();
            }

            if (this.list == null)
            {
                this.list = new UnityEditorInternal.ReorderableList(target.featuresList.features, typeof(FeaturesList.FeatureData), true, true, true, true);
                this.list.drawElementCallback   = this.OnDrawListItem;
                this.list.drawHeaderCallback    = this.OnDrawHeader;
                this.list.onChangedCallback     = this.OnChanged;
                this.list.elementHeightCallback = this.GetElementHeight;
            }

            GUILayoutExt.Box(15f, 0f, () => {
                var isDirty = false;

                this.definesFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.definesFoldOut, new GUIContent("Defines"), EditorStyles.foldoutHeader);
                if (this.definesFoldOut == true)
                {
                    GUILayout.Space(10f);

                    EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling == true || EditorApplication.isPlaying == true || EditorApplication.isPaused == true /* || InitializerEditor.isCompilingManual == true*/);

                    foreach (var defineInfo in InitializerEditor.defines)
                    {
                        if (defineInfo.showInList == false)
                        {
                            continue;
                        }

                        var value = defineInfo.isActive.Invoke();
                        if (GUILayoutExt.ToggleLeft(
                                ref value,
                                ref isDirty,
                                defineInfo.define,
                                defineInfo.description) == true)
                        {
                            //InitializerEditor.isCompilingManual = true;

                            if (value == true)
                            {
                                this.CompileWithDefine(defineInfo.define);
                            }
                            else
                            {
                                this.CompileWithoutDefine(defineInfo.define);
                            }
                        }
                    }

                    EditorGUI.EndDisabledGroup();
                }

                this.settingsFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.settingsFoldOut, new GUIContent("Settings"), EditorStyles.foldoutHeader);
                if (this.settingsFoldOut == true)
                {
                    GUILayout.Space(10f);

                    GUILayoutExt.ToggleLeft(
                        ref target.worldSettings.turnOffViews,
                        ref isDirty,
                        "Turn off views module",
                        "If you want to run ME.ECS on server, you don't need to use Views at all. Turn off views module to avoid updating view instances overhead.");

                    GUILayoutExt.ToggleLeft(
                        ref target.worldSettings.useJobsForSystems,
                        ref isDirty,
                        "Use jobs for Systems",
                        "Each system with filter has `jobs` flag which determine AdvanceTick behavior. If checked, jobs will be enabled and AdvanceTick will run asynchronously.");

                    GUILayoutExt.ToggleLeft(
                        ref target.worldSettings.useJobsForViews,
                        ref isDirty,
                        "Use jobs for Views",
                        "Some view providers have jobs implementation. Turn it on to enable them update views inside jobs. Please note that some providers could lose some method calls.");

                    if (this.viewsJobsEditors != null)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(10f);
                        {
                            GUILayout.BeginVertical();
                            foreach (var editor in this.viewsJobsEditors)
                            {
                                GUILayoutExt.Separator();
                                editor.Value.target = this.target as InitializerBase;
                                if (editor.Value.OnDrawGUI() == true)
                                {
                                    isDirty = true;
                                }
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                this.settingsDebugFoldOut = GUILayoutExt.BeginFoldoutHeaderGroup(this.settingsDebugFoldOut, new GUIContent("Debug Settings"), EditorStyles.foldoutHeader);
                if (this.settingsDebugFoldOut == true)
                {
                    GUILayout.Space(10f);

                    GUILayoutExt.ToggleLeft(
                        ref target.worldDebugSettings.createGameObjectsRepresentation,
                        ref isDirty,
                        "Create GameObject representation",
                        "Editor-only feature. If checked, all entities will be represented by GameObject with debug information.");

                    GUILayoutExt.ToggleLeft(
                        ref target.worldDebugSettings.showViewsOnScene,
                        ref isDirty,
                        "Show Views in Hierarchy",
                        "Editor-only feature. If checked, views module always show views on scene.");

                    if (this.viewsDebugEditors != null)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(10f);
                        {
                            GUILayout.BeginVertical();
                            foreach (var editor in this.viewsDebugEditors)
                            {
                                GUILayoutExt.Separator();
                                editor.Value.target = this.target as InitializerBase;
                                if (editor.Value.OnDrawGUI() == true)
                                {
                                    isDirty = true;
                                }
                            }
                            GUILayout.EndVertical();
                        }
                        GUILayout.EndHorizontal();
                    }
                }

                {
                    var editor = Editor.CreateEditor(target);
                    var field  = editor.serializedObject.GetIterator();
                    editor.serializedObject.Update();
                    var baseClassEnd = false;
                    while (field.NextVisible(true) == true)
                    {
                        if (baseClassEnd == true)
                        {
                            EditorGUILayout.PropertyField(field);
                        }

                        if (field.type == "EndOfBaseClass")
                        {
                            baseClassEnd = true;
                        }
                    }

                    editor.serializedObject.ApplyModifiedProperties();
                }

                if (isDirty == true)
                {
                    EditorUtility.SetDirty(this.target);
                }
            });

            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(EditorApplication.isPlaying == true || EditorApplication.isPaused == true);
            this.drawWidth = GUILayoutUtility.GetLastRect().width;
            this.list.DoLayoutList();
            EditorGUI.EndDisabledGroup();
        }
コード例 #20
0
        private Rect DrawArray(UnityEngine.Rect position, SerializedProperty property, string name)
        {
            var list           = new System.Collections.Generic.List <System.Type>();
            var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

            {
                var backStyle = new GUIStyle(EditorStyles.label);
                backStyle.normal.background = Texture2D.whiteTexture;

                var with = property.FindPropertyRelative(name);
                for (int i = 0; i < with.arraySize; ++i)
                {
                    var registry = with.GetArrayElementAtIndex(i);
                    FilterDataTypesEditor.GetTypeFromManagedReferenceFullTypeName(registry.managedReferenceFullTypename, out var type);

                    if (type == null)
                    {
                        Debug.Log("Not found: " + registry.managedReferenceFullTypename + ", " + registry.managedReferenceFieldTypename);
                        continue;
                    }

                    list.Add(type);
                    usedComponents.Add(type);

                    using (new GUILayoutExt.GUIBackgroundAlphaUsing(i % 2 == 0 ? 0f : 0.05f)) {
                        {
                            var componentName = GUILayoutExt.GetStringCamelCaseSpace(type.Name);

                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUI.Toggle(position, componentName, true, EditorStyles.toggle);
                            EditorGUI.EndDisabledGroup();
                        }
                    }

                    position.y += lineHeight;
                }
            }
            {
                var obj = property.serializedObject;
                GUILayoutExt.DrawAddComponentMenu(position, usedComponents, (addType, isUsed) => {
                    obj.Update();
                    var prop = obj.FindProperty(property.propertyPath);
                    var with = prop.FindPropertyRelative(name);
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        with.DeleteArrayElementAtIndex(list.IndexOf(addType));
                        list.Remove(addType);
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        list.Add(addType);
                        ++with.arraySize;
                        var item = with.GetArrayElementAtIndex(with.arraySize - 1);
                        item.managedReferenceValue = (IComponentBase)System.Activator.CreateInstance(addType);
                    }
                    obj.ApplyModifiedProperties();
                }, showRuntime: true);
            }

            position.y += FilterDataTypesEditor.editButtonHeight;
            return(position);
        }
コード例 #21
0
        public override void OnInspectorGUI()
        {
            var style = new GUIStyle(EditorStyles.toolbar);

            style.fixedHeight   = 0f;
            style.stretchHeight = true;

            var backStyle = new GUIStyle(EditorStyles.label);

            backStyle.normal.background = Texture2D.whiteTexture;

            var slice      = new ME.ECS.DataConfigs.DataConfigSlice();
            var isMultiple = false;

            if (this.targets.Length > 1)
            {
                slice      = ME.ECS.DataConfigs.DataConfigSlice.Distinct(this.targets.Cast <ME.ECS.DataConfigs.DataConfig>().ToArray());
                isMultiple = true;
            }
            else
            {
                var config = (ME.ECS.DataConfigs.DataConfig) this.target;
                slice = new ME.ECS.DataConfigs.DataConfigSlice()
                {
                    configs = new [] {
                        config
                    },
                    structComponentsDataTypeIds = config.structComponentsDataTypeIds,
                    componentsTypeIds           = config.componentsTypeIds
                };
            }

            var usedComponentsAll = new System.Collections.Generic.HashSet <System.Type>();

            foreach (var cfg in slice.configs)
            {
                var componentTypes = cfg.GetStructComponentTypes();
                foreach (var cType in componentTypes)
                {
                    if (usedComponentsAll.Contains(cType) == false)
                    {
                        usedComponentsAll.Add(cType);
                    }
                }

                if (DataConfigEditor.worldEditors.TryGetValue(cfg, out var worldEditor) == false)
                {
                    worldEditor = new WorldsViewerEditor.WorldEditor();
                    DataConfigEditor.worldEditors.Add(cfg, worldEditor);
                }
            }

            if (isMultiple == true)
            {
                GUILayoutExt.DrawHeader("The same components:");

                GUILayoutExt.Padding(8f, () => {
                    var kz = 0;
                    for (int i = 0; i < slice.structComponentsDataTypeIds.Length; ++i)
                    {
                        var typeId     = slice.structComponentsDataTypeIds[i];
                        var component  = slice.configs[0].GetByTypeId(typeId);
                        var components = slice.configs.Select(x => x.GetByTypeId(typeId)).ToArray();

                        var backColor       = GUI.backgroundColor;
                        GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                        GUILayout.BeginVertical(backStyle);
                        {
                            GUI.backgroundColor = backColor;
                            var editor          = WorldsViewerEditor.GetEditor(components);
                            if (editor != null)
                            {
                                EditorGUI.BeginChangeCheck();
                                editor.OnDrawGUI();
                                if (EditorGUI.EndChangeCheck() == true)
                                {
                                    slice.Set(typeId, components);
                                    this.Save(slice.configs);
                                }
                            }
                            else
                            {
                                var componentName = GUILayoutExt.GetStringCamelCaseSpace(component.GetType().Name);
                                var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                                if (fieldsCount == 0)
                                {
                                    EditorGUI.BeginDisabledGroup(true);
                                    EditorGUILayout.Toggle(componentName, true);
                                    EditorGUI.EndDisabledGroup();
                                }
                                else if (fieldsCount == 1)
                                {
                                    var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, components, componentName);
                                    if (changed == true)
                                    {
                                        slice.Set(typeId, components);
                                        this.Save(slice.configs);
                                    }
                                }
                                else
                                {
                                    GUILayout.BeginHorizontal();
                                    {
                                        GUILayout.Space(18f);
                                        GUILayout.BeginVertical();
                                        {
                                            var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                            var foldout = EditorPrefs.GetBool(key, true);
                                            GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                                var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, components);
                                                if (changed == true)
                                                {
                                                    slice.Set(typeId, components);
                                                    this.Save(slice.configs);
                                                }
                                            });
                                            EditorPrefs.SetBool(key, foldout);
                                        }
                                        GUILayout.EndVertical();
                                    }
                                    GUILayout.EndHorizontal();
                                }
                            }

                            GUILayoutExt.DrawComponentHelp(component.GetType());
                        }
                        GUILayout.EndVertical();

                        GUILayoutExt.Separator();
                    }
                });

                GUILayoutExt.DrawAddComponentMenu(usedComponentsAll, (addType, isUsed) => {
                    foreach (var dataConfigInner in slice.configs)
                    {
                        if (isUsed == true)
                        {
                            usedComponentsAll.Remove(addType);
                            for (int i = 0; i < dataConfigInner.structComponents.Length; ++i)
                            {
                                if (dataConfigInner.structComponents[i].GetType() == addType)
                                {
                                    var list = dataConfigInner.structComponents.ToList();
                                    list.RemoveAt(i);
                                    dataConfigInner.structComponents = list.ToArray();
                                    dataConfigInner.OnScriptLoad();
                                    this.Save(dataConfigInner);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            usedComponentsAll.Add(addType);
                            System.Array.Resize(ref dataConfigInner.structComponents, dataConfigInner.structComponents.Length + 1);
                            dataConfigInner.structComponents[dataConfigInner.structComponents.Length - 1] = (IStructComponent)System.Activator.CreateInstance(addType);
                            dataConfigInner.OnScriptLoad();
                            this.Save(dataConfigInner);
                        }
                    }
                });

                return;
            }

            GUILayoutExt.Separator(6f);
            GUILayoutExt.DrawHeader("Add Struct Components:");
            GUILayoutExt.Separator();

            var dataConfig = (ME.ECS.DataConfigs.DataConfig) this.target;

            GUILayoutExt.Padding(8f, () => {
                var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                var kz               = 0;
                var registries       = dataConfig.structComponents;
                var sortedRegistries = new System.Collections.Generic.SortedDictionary <int, Registry>(new WorldsViewerEditor.DuplicateKeyComparer <int>());
                for (int i = 0; i < registries.Length; ++i)
                {
                    var registry = registries[i];
                    if (registry == null)
                    {
                        continue;
                    }

                    var component = registry;
                    usedComponents.Add(component.GetType());

                    var editor = WorldsViewerEditor.GetEditor(component, out var order);
                    if (editor != null)
                    {
                        sortedRegistries.Add(order, new Registry()
                        {
                            index = i,
                            data  = component
                        });
                    }
                    else
                    {
                        sortedRegistries.Add(0, new Registry()
                        {
                            index = i,
                            data  = component
                        });
                    }
                }

                foreach (var registryKv in sortedRegistries)
                {
                    var registry  = registryKv.Value;
                    var component = registry.data;

                    var backColor       = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                    GUILayout.BeginVertical(backStyle);
                    {
                        GUI.backgroundColor = backColor;
                        var editor          = WorldsViewerEditor.GetEditor(component);
                        if (editor != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            editor.OnDrawGUI();
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                component = editor.GetTarget <IStructComponent>();
                                dataConfig.structComponents[registry.index] = component;
                                this.Save(dataConfig);
                            }
                        }
                        else
                        {
                            var componentName = GUILayoutExt.GetStringCamelCaseSpace(component.GetType().Name);
                            var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                            if (fieldsCount == 0)
                            {
                                EditorGUI.BeginDisabledGroup(true);
                                EditorGUILayout.Toggle(componentName, true);
                                EditorGUI.EndDisabledGroup();
                            }
                            else if (fieldsCount == 1)
                            {
                                var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, component, componentName);
                                if (changed == true)
                                {
                                    dataConfig.structComponents[registry.index] = component;
                                    this.Save(dataConfig);
                                }
                            }
                            else
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(18f);
                                    GUILayout.BeginVertical();
                                    {
                                        var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                        var foldout = EditorPrefs.GetBool(key, true);
                                        GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                            var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, component);
                                            if (changed == true)
                                            {
                                                dataConfig.structComponents[registry.index] = component;
                                                this.Save(dataConfig);
                                            }
                                        });
                                        EditorPrefs.SetBool(key, foldout);
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }

                        GUILayoutExt.DrawComponentHelp(component.GetType());
                        this.DrawComponentTemplatesUsage(dataConfig, component);
                    }
                    GUILayout.EndVertical();

                    GUILayoutExt.Separator();
                }

                GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        for (int i = 0; i < dataConfig.structComponents.Length; ++i)
                        {
                            if (dataConfig.structComponents[i].GetType() == addType)
                            {
                                var list = dataConfig.structComponents.ToList();
                                list.RemoveAt(i);
                                dataConfig.structComponents = list.ToArray();
                                dataConfig.OnScriptLoad();
                                this.Save(dataConfig);
                                break;
                            }
                        }
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        System.Array.Resize(ref dataConfig.structComponents, dataConfig.structComponents.Length + 1);
                        dataConfig.structComponents[dataConfig.structComponents.Length - 1] = (IStructComponent)System.Activator.CreateInstance(addType);
                        dataConfig.OnScriptLoad();
                        this.Save(dataConfig);
                    }
                });
            });

            GUILayoutExt.Separator(6f);
            GUILayoutExt.DrawHeader("Add Managed Components:");
            GUILayoutExt.Separator();

            GUILayoutExt.Padding(8f, () => {
                var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                var kz               = 0;
                var registries       = dataConfig.components;
                var sortedRegistries = new System.Collections.Generic.SortedDictionary <int, RegistryComponent>(new WorldsViewerEditor.DuplicateKeyComparer <int>());
                for (int i = 0; i < registries.Length; ++i)
                {
                    var registry = registries[i];
                    if (registry == null)
                    {
                        continue;
                    }

                    var component = registry;
                    usedComponents.Add(component.GetType());

                    var editor = WorldsViewerEditor.GetEditor(component, out var order);
                    if (editor != null)
                    {
                        sortedRegistries.Add(order, new RegistryComponent()
                        {
                            index = i,
                            data  = component
                        });
                    }
                    else
                    {
                        sortedRegistries.Add(0, new RegistryComponent()
                        {
                            index = i,
                            data  = component
                        });
                    }
                }

                foreach (var registryKv in sortedRegistries)
                {
                    var registry  = registryKv.Value;
                    var component = registry.data;

                    var backColor       = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                    GUILayout.BeginVertical(backStyle);
                    {
                        GUI.backgroundColor = backColor;
                        var editor          = WorldsViewerEditor.GetEditor(component);
                        if (editor != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            editor.OnDrawGUI();
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                component = editor.GetTarget <IComponent>();
                                dataConfig.components[registry.index] = component;
                                this.Save(dataConfig);
                            }
                        }
                        else
                        {
                            var componentName = component.GetType().Name;
                            var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                            if (fieldsCount == 0)
                            {
                                EditorGUI.BeginDisabledGroup(true);
                                EditorGUILayout.Toggle(componentName, true);
                                EditorGUI.EndDisabledGroup();
                            }
                            else if (fieldsCount == 1)
                            {
                                var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, component, componentName);
                                if (changed == true)
                                {
                                    dataConfig.components[registry.index] = component;
                                    this.Save(dataConfig);
                                }
                            }
                            else
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(18f);
                                    GUILayout.BeginVertical();
                                    {
                                        var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                        var foldout = EditorPrefs.GetBool(key, true);
                                        GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                            var changed = GUILayoutExt.DrawFields(DataConfigEditor.multipleWorldEditor, component);
                                            if (changed == true)
                                            {
                                                dataConfig.components[registry.index] = component;
                                                this.Save(dataConfig);
                                            }
                                        });
                                        EditorPrefs.SetBool(key, foldout);
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }

                        GUILayoutExt.DrawComponentHelp(component.GetType());
                        this.DrawComponentTemplatesUsage(dataConfig, component);
                    }
                    GUILayout.EndVertical();

                    GUILayoutExt.Separator();
                }

                GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        for (int i = 0; i < dataConfig.components.Length; ++i)
                        {
                            if (dataConfig.components[i].GetType() == addType)
                            {
                                var list = dataConfig.components.ToList();
                                list.RemoveAt(i);
                                dataConfig.components = list.ToArray();
                                dataConfig.OnScriptLoad();
                                this.Save(dataConfig);
                                break;
                            }
                        }
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        System.Array.Resize(ref dataConfig.components, dataConfig.components.Length + 1);
                        dataConfig.components[dataConfig.components.Length - 1] = (IComponent)System.Activator.CreateInstance(addType);
                        dataConfig.OnScriptLoad();
                        this.Save(dataConfig);
                    }
                }, drawRefComponents: true);
            });

            GUILayoutExt.Separator(6f);
            GUILayoutExt.DrawHeader("Remove Struct Components:");
            GUILayoutExt.Separator();

            // Remove struct components
            GUILayoutExt.Padding(8f, () => {
                var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                var kz         = 0;
                var registries = dataConfig.removeStructComponentsDataTypeIds;
                for (int i = 0; i < registries.Length; ++i)
                {
                    var registry = registries[i];
                    var type     = ComponentTypesRegistry.allTypeId.FirstOrDefault(x => x.Value == registry).Key;

                    if (type == null)
                    {
                        continue;
                    }

                    usedComponents.Add(type);

                    var backColor       = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                    GUILayout.BeginVertical(backStyle);
                    {
                        GUI.backgroundColor = backColor;
                        var componentName   = GUILayoutExt.GetStringCamelCaseSpace(type.Name);

                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.Toggle(componentName, true);
                        EditorGUI.EndDisabledGroup();

                        GUILayoutExt.DrawComponentHelp(type);
                        this.DrawComponentTemplatesUsage(dataConfig, dataConfig.removeStructComponents[i]);
                    }
                    GUILayout.EndVertical();

                    GUILayoutExt.Separator();
                }

                GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        for (int i = 0; i < dataConfig.removeStructComponents.Length; ++i)
                        {
                            if (dataConfig.removeStructComponents[i].GetType() == addType)
                            {
                                var list = dataConfig.removeStructComponents.ToList();
                                list.RemoveAt(i);
                                dataConfig.removeStructComponents = list.ToArray();
                                dataConfig.OnScriptLoad();
                                this.Save(dataConfig);
                                break;
                            }
                        }
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        System.Array.Resize(ref dataConfig.removeStructComponents, dataConfig.removeStructComponents.Length + 1);
                        dataConfig.removeStructComponents[dataConfig.removeStructComponents.Length - 1] = (IStructComponent)System.Activator.CreateInstance(addType);
                        dataConfig.OnScriptLoad();
                        this.Save(dataConfig);
                    }
                });
            });

            if ((dataConfig is ME.ECS.DataConfigs.DataConfigTemplate) == false)
            {
                this.DrawTemplates(dataConfig);
            }
        }
コード例 #22
0
        private static IMGUIContainer CreateTemplatesButton(DataConfigEditor editor,
                                                            System.Collections.Generic.HashSet <ME.ECS.DataConfigs.DataConfigTemplate> usedComponents,
                                                            VisualElement rootElement,
                                                            VisualElement templatesContainer,
                                                            SerializedProperty source,
                                                            SerializedObject so,
                                                            System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onAddTemplate,
                                                            System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onRemoveTemplate)
        {
            var container = new IMGUIContainer(() => {
                GUILayoutExt.DrawManageDataConfigTemplateMenu(usedComponents, (template, isUsed) => {
                    var path = AssetDatabase.GetAssetPath(template);
                    var guid = AssetDatabase.AssetPathToGUID(path);
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        return;
                    }

                    if (isUsed == true)
                    {
                        var copy          = source.Copy();
                        var i             = 0;
                        var enterChildren = true;
                        while (copy.NextVisible(enterChildren) == true)
                        {
                            enterChildren = false;

                            if (copy.propertyType != SerializedPropertyType.String)
                            {
                                continue;
                            }

                            if (copy.stringValue == guid)
                            {
                                usedComponents.Remove(template);
                                source.DeleteArrayElementAtIndex(i);
                                so.ApplyModifiedProperties();
                                onRemoveTemplate.Invoke(so, template);
                                break;
                            }

                            ++i;
                        }
                    }
                    else
                    {
                        usedComponents.Add(template);
                        onAddTemplate.Invoke(so, template);

                        ++source.arraySize;
                        var elem         = source.GetArrayElementAtIndex(source.arraySize - 1);
                        elem.stringValue = guid;
                        so.ApplyModifiedProperties();
                    }

                    editor.Save();
                    BuildContainer(editor, rootElement, so);
                });
            });

            container.AddToClassList("add-template-menu-button-imgui");

            return(container);
        }
コード例 #23
0
ファイル: DataConfigEditor.cs プロジェクト: mmvlad/ecs
        public override void OnInspectorGUI()
        {
            var style = new GUIStyle(EditorStyles.toolbar);

            style.fixedHeight   = 0f;
            style.stretchHeight = true;

            var backStyle = new GUIStyle(EditorStyles.label);

            backStyle.normal.background = Texture2D.whiteTexture;

            var dataConfig = (ME.ECS.DataConfigs.DataConfig) this.target;

            if (DataConfigEditor.worldEditors.TryGetValue(this.target, out var worldEditor) == false)
            {
                worldEditor = new WorldsViewerEditor.WorldEditor();
                DataConfigEditor.worldEditors.Add(this.target, worldEditor);
            }

            GUILayoutExt.Padding(8f, () => {
                var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                var kz               = 0;
                var registries       = dataConfig.structComponents;
                var sortedRegistries = new System.Collections.Generic.SortedDictionary <int, Registry>(new WorldsViewerEditor.DuplicateKeyComparer <int>());
                for (int i = 0; i < registries.Length; ++i)
                {
                    var registry = registries[i];
                    if (registry == null)
                    {
                        continue;
                    }

                    var component = registry;
                    usedComponents.Add(component.GetType());

                    var editor = WorldsViewerEditor.GetEditor(component, out var order);
                    if (editor != null)
                    {
                        sortedRegistries.Add(order, new Registry()
                        {
                            index = i,
                            data  = component
                        });
                    }
                    else
                    {
                        sortedRegistries.Add(0, new Registry()
                        {
                            index = i,
                            data  = component
                        });
                    }
                }

                foreach (var registryKv in sortedRegistries)
                {
                    var registry  = registryKv.Value;
                    var component = registry.data;

                    var backColor       = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                    GUILayout.BeginVertical(backStyle);
                    {
                        GUI.backgroundColor = backColor;
                        var editor          = WorldsViewerEditor.GetEditor(component);
                        if (editor != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            editor.OnDrawGUI();
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                component = editor.GetTarget <IStructComponent>();
                                dataConfig.structComponents[registry.index] = component;
                            }
                        }
                        else
                        {
                            var componentName = component.GetType().Name;
                            var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                            if (fieldsCount == 0)
                            {
                                EditorGUI.BeginDisabledGroup(true);
                                EditorGUILayout.Toggle(componentName, true);
                                EditorGUI.EndDisabledGroup();
                            }
                            else if (fieldsCount == 1)
                            {
                                var changed = GUILayoutExt.DrawFields(worldEditor, component, componentName);
                                if (changed == true)
                                {
                                    dataConfig.structComponents[registry.index] = component;
                                }
                            }
                            else
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(18f);
                                    GUILayout.BeginVertical();
                                    {
                                        var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                        var foldout = EditorPrefs.GetBool(key, true);
                                        GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                            var changed = GUILayoutExt.DrawFields(worldEditor, component);
                                            if (changed == true)
                                            {
                                                dataConfig.structComponents[registry.index] = component;
                                            }
                                        });
                                        EditorPrefs.SetBool(key, foldout);
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayoutExt.Separator();
                }

                GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        for (int i = 0; i < dataConfig.structComponents.Length; ++i)
                        {
                            if (dataConfig.structComponents[i].GetType() == addType)
                            {
                                var list = dataConfig.structComponents.ToList();
                                list.RemoveAt(i);
                                dataConfig.structComponents = list.ToArray();
                                dataConfig.OnScriptLoad();
                                break;
                            }
                        }
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        System.Array.Resize(ref dataConfig.structComponents, dataConfig.structComponents.Length + 1);
                        dataConfig.structComponents[dataConfig.structComponents.Length - 1] = (IStructComponent)System.Activator.CreateInstance(addType);
                        dataConfig.OnScriptLoad();
                    }
                });
            });

            GUILayoutExt.Padding(8f, () => {
                var usedComponents = new System.Collections.Generic.HashSet <System.Type>();

                var kz               = 0;
                var registries       = dataConfig.components;
                var sortedRegistries = new System.Collections.Generic.SortedDictionary <int, RegistryComponent>(new WorldsViewerEditor.DuplicateKeyComparer <int>());
                for (int i = 0; i < registries.Length; ++i)
                {
                    var registry = registries[i];
                    if (registry == null)
                    {
                        continue;
                    }

                    var component = registry;
                    usedComponents.Add(component.GetType());

                    var editor = WorldsViewerEditor.GetEditor(component, out var order);
                    if (editor != null)
                    {
                        sortedRegistries.Add(order, new RegistryComponent()
                        {
                            index = i,
                            data  = component
                        });
                    }
                    else
                    {
                        sortedRegistries.Add(0, new RegistryComponent()
                        {
                            index = i,
                            data  = component
                        });
                    }
                }

                foreach (var registryKv in sortedRegistries)
                {
                    var registry  = registryKv.Value;
                    var component = registry.data;

                    var backColor       = GUI.backgroundColor;
                    GUI.backgroundColor = new Color(1f, 1f, 1f, kz++ % 2 == 0 ? 0f : 0.05f);

                    GUILayout.BeginVertical(backStyle);
                    {
                        GUI.backgroundColor = backColor;
                        var editor          = WorldsViewerEditor.GetEditor(component);
                        if (editor != null)
                        {
                            EditorGUI.BeginChangeCheck();
                            editor.OnDrawGUI();
                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                component = editor.GetTarget <IComponent>();
                                dataConfig.components[registry.index] = component;
                            }
                        }
                        else
                        {
                            var componentName = component.GetType().Name;
                            var fieldsCount   = GUILayoutExt.GetFieldsCount(component);
                            if (fieldsCount == 0)
                            {
                                EditorGUI.BeginDisabledGroup(true);
                                EditorGUILayout.Toggle(componentName, true);
                                EditorGUI.EndDisabledGroup();
                            }
                            else if (fieldsCount == 1)
                            {
                                var changed = GUILayoutExt.DrawFields(worldEditor, component, componentName);
                                if (changed == true)
                                {
                                    dataConfig.components[registry.index] = component;
                                }
                            }
                            else
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    GUILayout.Space(18f);
                                    GUILayout.BeginVertical();
                                    {
                                        var key     = "ME.ECS.WorldsViewerEditor.FoldoutTypes." + component.GetType().FullName;
                                        var foldout = EditorPrefs.GetBool(key, true);
                                        GUILayoutExt.FoldOut(ref foldout, componentName, () => {
                                            var changed = GUILayoutExt.DrawFields(worldEditor, component);
                                            if (changed == true)
                                            {
                                                dataConfig.components[registry.index] = component;
                                            }
                                        });
                                        EditorPrefs.SetBool(key, foldout);
                                    }
                                    GUILayout.EndVertical();
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                    }
                    GUILayout.EndVertical();

                    GUILayoutExt.Separator();
                }

                GUILayoutExt.DrawAddComponentMenu(usedComponents, (addType, isUsed) => {
                    if (isUsed == true)
                    {
                        usedComponents.Remove(addType);
                        for (int i = 0; i < dataConfig.components.Length; ++i)
                        {
                            if (dataConfig.components[i].GetType() == addType)
                            {
                                var list = dataConfig.components.ToList();
                                list.RemoveAt(i);
                                dataConfig.components = list.ToArray();
                                dataConfig.OnScriptLoad();
                                break;
                            }
                        }
                    }
                    else
                    {
                        usedComponents.Add(addType);
                        System.Array.Resize(ref dataConfig.components, dataConfig.components.Length + 1);
                        dataConfig.components[dataConfig.components.Length - 1] = (IComponent)System.Activator.CreateInstance(addType);
                        dataConfig.OnScriptLoad();
                    }
                }, drawRefComponents: true);
            });
        }
コード例 #24
0
        private void DrawTemplates(ME.ECS.DataConfigs.DataConfig dataConfig)
        {
            GUILayoutExt.Separator(6f);
            GUILayoutExt.DrawHeader("Used Templates:");
            GUILayoutExt.Separator();

            var usedComponents = new System.Collections.Generic.HashSet <ME.ECS.DataConfigs.DataConfigTemplate>();

            if (dataConfig.templates != null)
            {
                var rect        = new Rect(0f, 0f, EditorGUIUtility.currentViewWidth, 1000f);
                var style       = new GUIStyle("AssetLabel Partial");
                var buttonRects = EditorGUIUtility.GetFlowLayoutedRects(rect, style, 4f, 4f, dataConfig.templates.Select(x => {
                    var guid = x;
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        return(string.Empty);
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        return(string.Empty);
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        return(string.Empty);
                    }

                    return(template.name);
                }).ToList());
                GUILayout.BeginHorizontal();
                GUILayout.EndHorizontal();
                var areaRect = GUILayoutUtility.GetLastRect();
                for (int i = 0; i < buttonRects.Count; ++i)
                {
                    areaRect.height = Mathf.Max(0f, buttonRects[i].yMax);
                }

                GUILayoutUtility.GetRect(areaRect.width, areaRect.height);

                GUI.BeginGroup(areaRect);
                for (int i = 0; i < dataConfig.templates.Length; ++i)
                {
                    var guid = dataConfig.templates[i];
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        continue;
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        continue;
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        continue;
                    }

                    if (usedComponents.Contains(template) == false)
                    {
                        usedComponents.Add(template);
                    }
                }

                for (int i = 0; i < dataConfig.templates.Length; ++i)
                {
                    var guid = dataConfig.templates[i];
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        continue;
                    }

                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) == true)
                    {
                        continue;
                    }

                    var template = AssetDatabase.LoadAssetAtPath <ME.ECS.DataConfigs.DataConfigTemplate>(path);
                    if (template == null)
                    {
                        continue;
                    }

                    if (GUI.Button(buttonRects[i], template.name, style) == true)
                    {
                        EditorGUIUtility.PingObject(template);
                        //this.RemoveTemplate(dataConfig, template, usedComponents);
                    }
                }
                GUI.EndGroup();
            }

            GUILayoutExt.DrawManageDataConfigTemplateMenu(usedComponents, (template, isUsed) => {
                var path = AssetDatabase.GetAssetPath(template);
                var guid = AssetDatabase.AssetPathToGUID(path);
                if (string.IsNullOrEmpty(guid) == true)
                {
                    return;
                }

                if (isUsed == true)
                {
                    usedComponents.Remove(template);
                    for (int i = 0; i < dataConfig.templates.Length; ++i)
                    {
                        if (dataConfig.templates[i] == guid)
                        {
                            this.RemoveTemplate(dataConfig, template, usedComponents);
                            break;
                        }
                    }
                }
                else
                {
                    usedComponents.Add(template);
                    if (dataConfig.templates == null)
                    {
                        dataConfig.templates = new string[0];
                    }
                    System.Array.Resize(ref dataConfig.templates, dataConfig.templates.Length + 1);
                    dataConfig.templates[dataConfig.templates.Length - 1] = guid;
                    dataConfig.AddTemplate(template);
                    dataConfig.OnScriptLoad();
                    this.Save(dataConfig);
                    AssetDatabase.ForceReserializeAssets(new [] { AssetDatabase.GetAssetPath(dataConfig) }, ForceReserializeAssetsOptions.ReserializeAssetsAndMetadata);
                    AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(dataConfig), ImportAssetOptions.ForceUpdate);
                    AssetDatabase.SaveAssets();
                }
            });
        }
コード例 #25
0
ファイル: GUILayoutExt.cs プロジェクト: cleancoindev/ecs
 public static void TypeLabel(System.Type type, params GUILayoutOption[] options)
 {
     GUILayoutExt.DataLabel(GUILayoutExt.GetTypeLabel(type), options);
 }
コード例 #26
0
        bool IGUIEditorBase.OnDrawGUI()
        {
            var style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label);

            style.richText = true;

            var dataCount = 0;

            foreach (System.Collections.DictionaryEntry ren in this.target.GetData())
            {
                dataCount += ((ME.ECS.Collections.SortedList <long, HistoryEvent>)ren.Value).Count;
            }

            GUILayoutExt.Box(2f, 2f, () => {
                UnityEngine.GUILayout.Label("<b>Memory Usage:</b> " + ME.ECS.MathUtils.BytesCountToString(WorldEditor.current.stateSize * (this.target.GetCacheSize() / this.target.GetTicksPerState())), style);
                UnityEngine.GUILayout.Label("<b>Events:</b> " + dataCount.ToString(), style);
                UnityEngine.GUILayout.Label("<b>Events Added:</b> " + this.target.GetEventsAddedCount().ToString(), style);
                UnityEngine.GUILayout.Label("<b>Events Played:</b> " + this.target.GetEventsPlayedCount().ToString(), style);
            });

            GUILayoutExt.Separator();
            var val = this.syncTableFoldState;

            GUILayoutExt.FoldOut(ref val, "Sync Table", () => {
                const float padding    = 2f;
                const float margin     = 2f;
                const float col1       = 60f;
                const float col2       = 50f;
                const float col3       = 22f;
                const float cellHeight = 22f;
                var tableStyle         = (GUIStyle)"Box";

                GUILayout.BeginHorizontal();
                {
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Tick", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col1),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Player", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col2),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Hash", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.ExpandWidth(true),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption(string.Empty, EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col3),
                                     GUILayout.Height(cellHeight));
                }
                GUILayout.EndHorizontal();

                var syncHashTable = this.target.GetSyncHashTable();

                /*if (syncHashTable.ContainsKey(20) == false) syncHashTable.Add(20, new System.Collections.Generic.Dictionary<int, int>() {
                 *  { 100, 1234 }
                 * });
                 * if (syncHashTable.ContainsKey(100) == false) syncHashTable.Add(100, new System.Collections.Generic.Dictionary<int, int>() {
                 *  { 100, 1902832914 },
                 *  { 101, 1902832914 },
                 *  { 102, 1902832915 },
                 * });
                 * if (syncHashTable.ContainsKey(2000) == false) syncHashTable.Add(2000, new System.Collections.Generic.Dictionary<int, int>() {
                 *  { 100, 2345 }
                 * });*/
                foreach (var item in syncHashTable)
                {
                    var tick      = item.Key;
                    int localHash = 0;

                    GUILayout.BeginHorizontal();
                    {
                        GUILayoutExt.DataLabel(tick.ToString(), GUILayout.Width(col1));
                    }
                    GUILayout.EndHorizontal();
                    var stateHashResult = 0;
                    foreach (var kv in item.Value)
                    {
                        var hash = kv.Value;
                        if (localHash != 0 && localHash != hash)
                        {
                            stateHashResult = -1;
                            break;
                        }
                        else if (localHash != 0)
                        {
                            stateHashResult = 1;
                        }
                        localHash = hash;
                    }

                    foreach (var kv in item.Value)
                    {
                        var playerId = kv.Key;
                        GUILayout.BeginHorizontal();
                        {
                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(string.Empty); }, tableStyle, GUILayout.Width(col1), GUILayout.Height(cellHeight));
                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(playerId.ToString()); }, tableStyle, GUILayout.Width(col2), GUILayout.Height(cellHeight));
                            GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(kv.Value.ToString()); }, tableStyle, GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                            GUILayoutExt.Box(padding, margin, () => {
                                GUILayout.BeginHorizontal();
                                GUILayout.FlexibleSpace();

                                if (stateHashResult == 1)
                                {
                                    using (new GUILayoutExt.GUIColorUsing(Color.green)) {
                                        GUILayout.Toggle(true, new GUIContent(string.Empty, $"Local hash synced with player #{playerId}."), StatesHistoryModuleEditor.syncBoxStyle);
                                    }
                                }
                                else if (stateHashResult == -1)
                                {
                                    using (new GUILayoutExt.GUIColorUsing(Color.red)) {
                                        GUILayout.Toggle(true, new GUIContent(string.Empty, $"Local hash is not the same as player #{playerId} has, your server must resync that player."), StatesHistoryModuleEditor.syncBoxStyle);
                                    }
                                }
                                else
                                {
                                    using (new GUILayoutExt.GUIColorUsing(Color.yellow)) {
                                        GUILayout.Toggle(false, new GUIContent(string.Empty, $"Local hash is not sync yet with player #{playerId}, current tick is less than remote."), StatesHistoryModuleEditor.syncBoxStyle);
                                    }
                                }

                                GUILayout.FlexibleSpace();
                                GUILayout.EndHorizontal();
                            }, tableStyle, GUILayout.Width(col3), GUILayout.Height(cellHeight));
                        }
                        GUILayout.EndHorizontal();
                    }
                }
            });
            this.syncTableFoldState = val;

            GUILayoutExt.Separator();
            val = this.statesHistoryFoldState;
            GUILayoutExt.FoldOut(ref val, "States History", () => {
                var padding    = 2f;
                var margin     = 2f;
                var col1       = 60f;
                var col2       = 70f;
                var cellHeight = 22f;
                var tableStyle = (GUIStyle)"Box";

                UnityEngine.GUILayout.BeginHorizontal();
                {
                    if (UnityEngine.GUILayout.Button("Entities", UnityEditor.EditorStyles.miniButtonLeft) == true)
                    {
                        var world = Worlds.currentWorld;
                        this.PrintEntities(world.currentState);
                    }

                    if (UnityEngine.GUILayout.Button("Events", UnityEditor.EditorStyles.miniButtonMid) == true)
                    {
                        foreach (System.Collections.DictionaryEntry ren in this.target.GetData())
                        {
                            var entry = (ME.ECS.Collections.SortedList <long, HistoryEvent>)ren.Value;
                            for (int i = 0; i < entry.Count; ++i)
                            {
                                UnityEngine.Debug.Log(entry.GetByIndex(i).ToString());
                            }
                        }
                    }

                    if (UnityEngine.GUILayout.Button("Reset State", UnityEditor.EditorStyles.miniButtonRight) == true)
                    {
                        this.target.RecalculateFromResetState();
                    }
                }
                UnityEngine.GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Tick", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col1),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Hash", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.ExpandWidth(true),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Actions", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col2),
                                     GUILayout.Height(cellHeight));
                }
                GUILayout.EndHorizontal();

                var dataStates = this.target.GetDataStates();
                var entries    = dataStates.GetEntries();
                foreach (var entryData in entries)
                {
                    var entry = entryData as ME.ECS.Network.IStatesHistoryEntry;
                    var state = entry.GetData() as State;
                    UnityEngine.GUILayout.BeginHorizontal();
                    {
                        GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(entry.isEmpty == true ? "-" : state.tick.ToString()); }, tableStyle, GUILayout.Width(col1), GUILayout.Height(cellHeight));
                        GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(entry.isEmpty == true ? "-" : state.GetHash().ToString()); }, tableStyle, GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                        GUILayoutExt.Box(padding, margin, () => {
                            EditorGUI.BeginDisabledGroup(entry.isEmpty == true);
                            if (UnityEngine.GUILayout.Button("Entities") == true)
                            {
                                this.PrintEntities(state);
                            }
                            EditorGUI.EndDisabledGroup();
                        }, tableStyle, GUILayout.Width(col2), GUILayout.Height(cellHeight));
                    }
                    UnityEngine.GUILayout.EndHorizontal();
                }
            });
            this.statesHistoryFoldState = val;
            GUILayoutExt.Separator();

            GUILayoutExt.Separator();
            val = this.eventsFoldState;
            GUILayoutExt.FoldOut(ref val, "Events Table", () => {
                const float padding    = 2f;
                const float margin     = 2f;
                const float col1       = 60f;
                const float col2       = 50f;
                const float cellHeight = 22f;
                var tableStyle         = (GUIStyle)"Box";

                GUILayout.BeginHorizontal();
                {
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Tick", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col1),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Player", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.Width(col2),
                                     GUILayout.Height(cellHeight));
                    GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.TableCaption("Rpc ID", EditorStyles.miniBoldLabel); }, tableStyle,
                                     GUILayout.ExpandWidth(true),
                                     GUILayout.Height(cellHeight));
                }
                GUILayout.EndHorizontal();

                var events = this.target.GetEvents();
                foreach (var item in events)
                {
                    var tick = item.tick;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayoutExt.DataLabel(tick.ToString(), GUILayout.Width(col1));
                    }
                    GUILayout.EndHorizontal();

                    var playerId = item.order;
                    GUILayout.BeginHorizontal();
                    {
                        GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(tick.ToString()); }, tableStyle, GUILayout.Width(col1), GUILayout.Height(cellHeight));
                        GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(playerId.ToString()); }, tableStyle, GUILayout.Width(col2), GUILayout.Height(cellHeight));
                        GUILayoutExt.Box(padding, margin, () => { GUILayoutExt.DataLabel(item.rpcId.ToString()); }, tableStyle, GUILayout.ExpandWidth(true), GUILayout.Height(cellHeight));
                    }
                    GUILayout.EndHorizontal();
                }
            });
            this.eventsFoldState = val;

            return(false);
        }
コード例 #27
0
            public override void OnGUI(Rect rect)
            {
                var dataType = GUILayoutExt.GetTypeLabel(this.GetType());

                GUI.Label(rect, dataType, Styles.containerCaption);
            }