public static void DrawGui()
        {
            if (!ImGui.BeginMainMenuBar())
            {
                return;
            }

            menuHeight = ImGui.GetWindowHeight();

            if (ImGui.BeginMenu("File"))
            {
                if (ImGui.MenuItem("New Scene", false))
                {
                    ;
                }
                if (ImGui.MenuItem("Open Scene", false))
                {
                    ;
                }

                ImGui.Separator();
                if (ImGui.MenuItem("Save Scenes", false))
                {
                    ;
                }
                if (ImGui.MenuItem("Save Scene as..", false))
                {
                    ;
                }

                ImGui.Separator();
                if (ImGui.MenuItem("New Project..", false))
                {
                    ;
                }
                if (ImGui.MenuItem("Open Project..", false))
                {
                    ;
                }
                if (ImGui.MenuItem("Save Project", false))
                {
                    ;
                }

                ImGui.Separator();
                if (ImGui.MenuItem("Exit", false))
                {
                    ;
                }

                ImGui.EndMenu();
            }

            if (ImGui.BeginMenu("Edit"))
            {
                if (ImGui.BeginMenu("Project Settings"))
                {
                    if (ImGui.MenuItem(TagLayerManager.displayName))
                    {
                        TagLayerManager.Select();
                    }

                    ImGui.EndMenu();
                }

                ImGui.EndMenu();
            }

            if (ImGui.BeginMenu("GameObject"))
            {
                DrawCreateMenu();

                ImGui.EndMenu();
            }

            ImGui.EndMainMenuBar();
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            var gameObject = target as GameObject;

            if (gameObject == null)
            {
                return;
            }

            ImGui.BeginChildFrame(0, new Vector2(ImGui.GetWindowWidth(), 25f), WindowFlags.NoScrollbar);
            {
                ImGui.Columns(2, "Tags and Layers Columns", false);

                var tagIndex = gameObject.tagIndex;
                if (ImGui.Combo("Tag", ref tagIndex, TagLayerManager.instanceTags.ToArray()))
                {
                    gameObject.tagIndex = tagIndex;
                }

                ImGui.SameLine();
                if (ImGui.Button(" + "))
                {
                    TagLayerManager.Select();
                }

                ImGui.NextColumn();

                ImGui.SetColumnOffset(1, ImGui.GetWindowContentRegionWidth() * 0.4f);
                var layerIndex = gameObject.layerIndex;
                if (ImGui.Combo("Layer", ref layerIndex, TagLayerManager.instanceLayers.ToArray()))
                {
                    gameObject.layerIndex = layerIndex;
                }

                ImGui.SameLine();
                if (ImGui.Button(" + "))
                {
                    TagLayerManager.Select();
                }
            }
            ImGui.EndChildFrame();

            var components = gameObject.GetComponents <Component>().ToList();

            foreach (var component in components)
            {
                ImGui.PushID(component.id);
                {
                    if (DrawCollapsingHeader(component))
                    {
                        var componentType = component.GetType();
                        if (s_ComponentEditors.TryGetValue(componentType, out Inspector editor))
                        {
                            editor.target = component;
                            editor.OnInspectorGUI();
                        }
                        else if (componentType.IsGenericType)
                        {
                            var foundEditor = false;
                            foreach (var keyValuePair in s_ComponentEditors)
                            {
                                var underlyingType = componentType.GetGenericTypeDefinition();
                                if (underlyingType != keyValuePair.Key)
                                {
                                    continue;
                                }

                                keyValuePair.Value.target = component;
                                keyValuePair.Value.OnInspectorGUI();

                                foundEditor = true;
                                break;
                            }

                            if (!foundEditor)
                            {
                                s_DefaultInspector.target = component;
                                s_DefaultInspector.OnInspectorGUI();
                            }
                        }
                        else
                        {
                            s_DefaultInspector.target = component;
                            s_DefaultInspector.OnInspectorGUI();
                        }
                    }
                }
                ImGui.PopID();
            }

            ImGui.LabelText("", "");

            ImGui.Columns(3, "Add Component Column", false);
            {
                ImGui.NextColumn();
                if (ImGui.Button(
                        "Add Component",
                        new Vector2(ImGui.GetColumnWidth(ImGui.GetColumnIndex()) - 15f, 0)))
                {
                    ImGui.OpenPopup("Add Component Popup");
                }

                if (ImGui.BeginPopup("Add Component Popup"))
                {
                    foreach (var type in Assembly.GetCallingAssembly().GetTypes())
                    {
                        if (!typeof(Component).IsAssignableFrom(type) || type.IsAbstract)
                        {
                            continue;
                        }

                        if (ImGui.MenuItem(type.Name))
                        {
                            gameObject.AddComponent(type);
                        }
                    }
                    ImGui.EndPopup();
                }
            }
        }