Beispiel #1
0
        private bool ToggleMethod(WorldEditor worldEditor, object instance, string methodName, ref bool state)
        {
            var disabled = !worldEditor.HasMethod(instance, methodName);

            if (disabled == true)
            {
                var style = new GUIStyle("Icon.Locked");
                style.fixedWidth    = 14f;
                style.fixedHeight   = 14f;
                style.stretchWidth  = false;
                style.stretchHeight = false;
                var boxStyle = GUIStyle.none;
                //EditorGUI.BeginDisabledGroup(false);
                if (GUILayout.Button(new GUIContent(style.normal.background), boxStyle) == true)
                {
                    this.ShowNotification(new GUIContent("Method " + methodName + " implementation is empty."));
                }
                //EditorGUI.EndDisabledGroup();
            }
            else
            {
                var newState = EditorGUILayout.Toggle(state, "ShurikenCheckMark", GUILayout.Width(10f));
                if (state != newState)
                {
                    state = newState;
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
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();
            });
        }
Beispiel #3
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);
        }
Beispiel #4
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();
        }