Exemple #1
0
        /// <summary>
        /// Draws the module in the header. The default behaviour is to draw a simple tab button.
        /// </summary>
        /// <param name="focusedModuleID">ID of the focused module.</param>
        public virtual Rect     DrawMenu(Rect r, int focusedModuleID)
        {
            GeneralSettings settings = HQ.Settings.Get <GeneralSettings>();

            Utility.content.text = this.name;
            r.width = settings.MenuButtonStyle.CalcSize(Utility.content).x;

            EditorGUI.BeginChangeCheck();
            NGEditorGUILayout.OutlineToggle(r, this.name, this.id == focusedModuleID, settings.MenuButtonStyle);
            if (EditorGUI.EndChangeCheck() == true)
            {
                if (Event.current.button == 1 ||
                    Event.current.control == true)
                {
                    ConsoleUtility.OpenModuleInWindow(this.console, this, Event.current.control);
                }
                else if (this.id != focusedModuleID)
                {
                    this.Focus();
                }
            }

            r.x += r.width;

            return(r);
        }
Exemple #2
0
        protected virtual void  OnGUI()
        {
            EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
            {
                if (GUILayout.Button("Open", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(100F)) == true)
                {
                    this.OpenReplay();
                }

                for (int i = 0; i < this.replays.Count; i++)
                {
                    EditorGUI.BeginChangeCheck();
                    NGEditorGUILayout.OutlineToggle(this.replays[i].name, i == this.currentReplay);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        if (Event.current.button == 2)
                        {
                            this.replays.RemoveAt(i);
                            return;
                        }
                        else if (Event.current.button == 1)
                        {
                            GenericMenu menu = new GenericMenu();

                            menu.AddItem(new GUIContent("Delete"), false, (d) => this.replays.RemoveAt((int)d), i);
                            menu.ShowAsContext();
                            return;
                        }
                        else
                        {
                            if (this.currentReplay >= 0 && this.currentReplay < this.replays.Count)
                            {
                                this.replays[this.currentReplay].Pause();
                            }

                            this.currentReplay = i;
                        }
                    }
                }

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

            if (this.replays.Count == 0)
            {
                if (GUILayout.Button("No replay loaded yet, please open one.", GeneralStyles.BigCenterText, GUILayoutOptionPool.ExpandHeightTrue) == true)
                {
                    this.OpenReplay();
                }
            }

            if (this.currentReplay >= 0 && this.currentReplay < this.replays.Count)
            {
                Replay replay = this.replays[this.currentReplay];

                EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
                {
                    if (replay.canSave == true)
                    {
                        if (GUILayout.Button("Save", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(100F)) == true)
                        {
                            string filepath = EditorUtility.SaveFilePanel("Save Replay", ".", PlayerSettings.productName + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss"), NGReplayWindow.ReplayExtension);

                            if (string.IsNullOrEmpty(filepath) == false)
                            {
                                if (replay.Save(filepath) == false)
                                {
                                    InternalNGDebug.LogError("An error occurred. Replay could not been saved at \"" + filepath + "\".");
                                }
                                else
                                {
                                    InternalNGDebug.Log("Replay saved at \"" + filepath + "\".");
                                }
                            }
                        }
                    }

                    if (GUILayout.Button("<", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(35F)) == true)
                    {
                        replay.Pause();
                        replay.Set(replay.cursorTime - .1F);
                    }
                    if (GUILayout.Button(">", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(35F)) == true)
                    {
                        replay.Pause();
                        replay.Set(replay.cursorTime + .1F);
                    }

                    if (replay.playing == false)
                    {
                        if (GUILayout.Button("►", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(75F)) == true)
                        {
                            replay.Play();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("▮▮", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(75F)) == true)
                        {
                            replay.Pause();
                        }
                    }

                    if (GUILayout.Button("■", GeneralStyles.ToolbarButton, GUILayoutOptionPool.Width(75F)) == true)
                    {
                        replay.Stop();
                    }

                    GUILayout.FlexibleSpace();

                    using (LabelWidthRestorer.Get(50F))
                    {
                        replay.speed = EditorGUILayout.FloatField("Speed", replay.speed, GUILayoutOptionPool.Width(75F));
                    }

                    EditorGUI.BeginChangeCheck();
                    Utility.content.text    = " ∞ ";
                    Utility.content.tooltip = "Repeat";
                    GUILayout.Toggle(replay.repeat, Utility.content, GeneralStyles.ToolbarButton);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        replay.repeat = !replay.repeat;
                    }

                    for (int i = 0; i < replay.modules.Count; i++)
                    {
                        replay.modules[i].OnGUIOptions(this);
                    }

                    Rect r2 = GUILayoutUtility.GetRect(new GUIContent("Modules"), GeneralStyles.ToolbarDropDown);
                    if (GUI.Button(r2, "Modules", GeneralStyles.ToolbarDropDown) == true)
                    {
                        GenericMenu menu = new GenericMenu();

                        for (int i = 0; i < replay.modules.Count; i++)
                        {
                            if (replay.modules[i].moduleID == ScreenshotModule.ModuleID)
                            {
                                continue;
                            }

                            menu.AddItem(new GUIContent(replay.modules[i].name), replay.modules[i].active, this.ToggleModule, replay.modules[i]);
                        }

                        menu.DropDown(r2);
                    }

                    if (Conf.DebugMode != Conf.DebugState.None)
                    {
                        EditorGUI.BeginChangeCheck();
                        GUILayout.Toggle(this.showDBG, "DBG", GeneralStyles.ToolbarButton);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            this.showDBG = !this.showDBG;
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUI.BeginChangeCheck();
                    float t = EditorGUILayout.Slider(replay.cursorTime, 0F, replay.maxTime);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        replay.Pause();
                        replay.Set(t, true);
                    }

                    GUILayout.Label("/ " + replay.maxTime, GUILayoutOptionPool.ExpandWidthFalse);
                }
                EditorGUILayout.EndHorizontal();

                Rect r = GUILayoutUtility.GetRect(0F, 0F, GUILayoutOptionPool.ExpandWidthTrue, GUILayoutOptionPool.ExpandHeightTrue);

                for (int i = 0; i < replay.modules.Count; i++)
                {
                    if (replay.modules[i].active == true)
                    {
                        replay.modules[i].OnGUIReplay(r);
                    }
                }

                if (Conf.DebugMode != Conf.DebugState.None && this.showDBG == true)
                {
                    EditorGUILayout.LabelField("Time Offset", replay.realTimeOffset.ToString());

                    for (int i = 0; i < replay.modules.Count; i++)
                    {
                        if (replay.modules[i].active == true)
                        {
                            replay.modules[i].OnGUIDBG();
                        }
                    }
                }
            }
        }
        private void    DrawPrefabs()
        {
            EditorGUILayout.BeginHorizontal();
            {
                for (int i = 0; i < this.Hierarchy.PendingPrefabs.Count; i++)
                {
                    EditorGUI.BeginChangeCheck();
                    NGEditorGUILayout.OutlineToggle(this.Hierarchy.PendingPrefabs[i].rootGameObject.gameObject.name, this.selectedPrefab == i);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        this.selectedPrefab = i;
                    }
                }

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

            if (this.selectedPrefab < this.Hierarchy.PendingPrefabs.Count)
            {
                PrefabConstruct prefab = this.Hierarchy.PendingPrefabs[this.selectedPrefab];

                GUILayout.Space(10F + 32F);

                Rect r = GUILayoutUtility.GetLastRect();

                r.xMin += 20F;
                r.width = 150F;
                if (GUI.Button(r, prefab.rootGameObject.gameObject.name) == true)
                {
                    this.Hierarchy.PingObject(prefab.rootGameObject.gameObject.instanceID);
                }

                r.x += r.width + 10F;

                if (prefab.constructionError != null)
                {
                    EditorGUI.HelpBox(r, prefab.constructionError, MessageType.Error);
                }
                else if (prefab.outputPath != null)
                {
                    if (GUI.Button(r, "Local Prefab", GeneralStyles.ToolbarDropDown) == true)
                    {
                        EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(prefab.outputPath, typeof(Object)));
                    }
                }

                r.width = 20F;
                if (GUI.Button(r, GUIContent.none, GeneralStyles.ToolbarDropDown) == true)
                {
                }

                GUILayout.Space(11F);

                r = GUILayoutUtility.GetLastRect();

                r.y     += r.height - 1F;
                r.height = 1F;
                r.width  = this.position.width;
                EditorGUI.DrawRect(r, Color.cyan);
                r.y     += 1F;
                r.height = 20F;

                Rect rH = r;
                rH.width = Mathf.Round(rH.width * .33F);
                GUI.Label(rH, "Hierarchy");

                rH.y     += rH.height;
                rH.height = prefab.rootGameObject.GetHeight();

                Rect view = new Rect(0F, 0F, 0F, rH.height);

                this.hierarchyScrollPosition = GUI.BeginScrollView(rH, this.hierarchyScrollPosition, view);
                {
                    rH.y      = 0F;
                    rH.height = Constants.SingleLineHeight;
                    prefab.rootGameObject.DrawGameObject(rH, this);
                }
                GUI.EndScrollView();

                Rect rI = r;
                rI.x += rH.width;

                rI.width  = 1F;
                rI.height = this.position.height - rI.y;
                rI.y     += 1F;
                EditorGUI.DrawRect(rI, Color.cyan);
                rI.y -= 1F;
                rI.x += 1F;

                rI.width  = this.position.width - rH.xMax - 1F;
                rI.height = Constants.SingleLineHeight;
                GUI.Label(rI, "Inspector");

                rI.y     += rI.height;
                rI.height = this.position.height - rI.yMax;

                if (this.selectedGameObject != null)
                {
                    if (this.selectedGameObject.components != null)
                    {
                        if (this.selectedGameObject.components.Length > 0)
                        {
                            view.height = 0F;
                            for (int i = 0; i < this.selectedGameObject.components.Length; i++)
                            {
                                view.height += this.selectedGameObject.components[i].GetHeight(this, Hierarchy);
                            }
                        }
                        else
                        {
                            view.height = 32F;
                        }

                        this.inspectorScrollPosition = GUI.BeginScrollView(rI, this.inspectorScrollPosition, view);
                        {
                            rI.x = 0F;
                            rI.y = 0F;

                            if (this.selectedGameObject.components.Length > 0)
                            {
                                for (int i = 0; i < this.selectedGameObject.components.Length; i++)
                                {
                                    rI.height = this.selectedGameObject.components[i].GetHeight(this, Hierarchy);
                                    this.selectedGameObject.components[i].DrawComponent(rI, this, this.Hierarchy);
                                    rI.y += rI.height;
                                }
                            }
                            else
                            {
                                rI.height = 32F;
                                rI.xMin  += 5F;
                                rI.xMax  -= 5F;
                                EditorGUI.HelpBox(rI, "Does not contain a Component with importable assets.", MessageType.Info);
                            }
                        }
                        GUI.EndScrollView();
                    }
                    else
                    {
                        EditorGUI.HelpBox(rI, "Loading Components.", MessageType.Info);
                        GUI.Label(rI, GeneralStyles.StatusWheel);
                    }
                }
            }
        }
        protected override void OnGUIHeader()
        {
            bool has = false;

            for (int i = 0; i < this.Hierarchy.ImportingAssetsParams.Count; i++)
            {
                if (this.Hierarchy.ImportingAssetsParams[i].localAsset == null &&
                    this.Hierarchy.ImportingAssetsParams[i].isSupported == true &&
                    this.Hierarchy.ImportingAssetsParams[i].originPath != null)
                {
                    has = true;
                    break;
                }
            }

            EditorGUILayout.BeginHorizontal(GeneralStyles.Toolbar);
            {
                if (GUILayout.Button("☰", "GV Gizmo DropDown", GUILayoutOptionPool.ExpandWidthFalse) == true)
                {
                    PopupWindow.Show(new Rect(0F, 16F, 0F, 0F), new OptionsPopup(this));
                }

                EditorGUI.BeginChangeCheck();
                NGEditorGUILayout.OutlineToggle("Prefabs", this.tab == Tab.Prefabs);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.tab = Tab.Prefabs;
                }

                EditorGUI.BeginChangeCheck();
                NGEditorGUILayout.OutlineToggle("Assets", this.tab == Tab.Assets);
                if (EditorGUI.EndChangeCheck() == true)
                {
                    this.tab = Tab.Assets;
                }

                GUILayout.FlexibleSpace();

                if (has == true && this.Hierarchy.IsClientConnected() == true)
                {
                    if (GUILayout.Button("Set Auto to all", GeneralStyles.ToolbarButton) == true)
                    {
                        for (int i = 0; i < this.Hierarchy.ImportingAssetsParams.Count; i++)
                        {
                            if (this.Hierarchy.ImportingAssetsParams[i].localAsset == null &&
                                this.Hierarchy.ImportingAssetsParams[i].isSupported == true &&
                                this.Hierarchy.ImportingAssetsParams[i].originPath != null)
                            {
                                this.Hierarchy.ImportingAssetsParams[i].importMode = ImportMode.Auto;
                            }
                        }
                    }

                    GUILayout.Space(10F);

                    if (GUILayout.Button("Confirm all", GeneralStyles.ToolbarButton) == true)
                    {
                        for (int i = 0; i < this.Hierarchy.ImportingAssetsParams.Count; i++)
                        {
                            this.Hierarchy.ImportingAssetsParams[i].Confirm();
                        }
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }