Esempio n. 1
0
        private static void OnSceneGUI(SceneView sceneView)
        {
            if (!Preferences.showToolbar)
            {
                return;
            }

            var r = new Rect(Vector2.zero, new Vector2(sceneView.position.width, 24));

            Handles.BeginGUI();
            using (new GUILayout.AreaScope(r))
            {
                using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
                {
                    if (Preferences.showPlayFromHere)
                    {
                        using (new EditorGUI.DisabledGroupScope(!PlayFromHere.IsReady))
                        {
                            bool play = GUILayout.Toggle(EditorApplication.isPlaying, Contents.playFromHere, EditorStyles.toolbarButton);

                            if (GUI.changed)
                            {
                                if (play)
                                {
                                    PlayFromHere.Play(sceneView);
                                }
                                else
                                {
                                    EditorApplication.isPlaying = false;
                                }
                            }
                        }
                        GUILayout.Space(24);
                    }

                    if (Preferences.showLinkGameView)
                    {
                        Color backup = GUI.color;

                        bool isLinked = LinkGameView.Active;
                        bool isLocked = LinkGameView.LockedSceneView == sceneView;


                        if (isLinked && isLocked)
                        {
                            GUI.color = Styles.lockedLinkColor * 2;
                        }
                        else if (isLinked && LinkGameView.CinemachineActive)
                        {
                            GUI.color = Styles.cineColor * 2;
                        }

                        isLinked = GUILayout.Toggle(isLinked, LinkGameView.CinemachineActive ? Contents.linkGameViewCinemachine : Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));

                        if (GUI.changed)
                        {
                            if (Event.current.shift)
                            {
                                if (!LinkGameView.Active)
                                {
                                    LinkGameView.Active = true;
                                }

                                LinkGameView.CinemachineActive = !LinkGameView.CinemachineActive;
                            }
                            else
                            {
                                LinkGameView.Active            = isLinked;
                                LinkGameView.CinemachineActive = false;
                            }
                        }

                        isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);

                        if (GUI.changed)
                        {
                            if (isLocked)
                            {
                                LinkGameView.CinemachineActive = false;
                                LinkGameView.LockedSceneView   = sceneView;
                            }
                            else
                            {
                                LinkGameView.LockedSceneView = null;
                            }
                        }

                        GUI.color = backup;
                        GUILayout.Space(16);
                    }

                    if (Preferences.showPOV)
                    {
                        if (GUILayout.Button("POV", EditorStyles.toolbarDropDown))
                        {
                            Rect btnrect = GUILayoutUtility.GetLastRect();
                            btnrect.yMax += 17;
                            SceneViewPOV.ShowPopup(btnrect, sceneView);
                        }
                        GUILayout.Space(16);
                    }

                    if (Preferences.showCheck)
                    {
                        if (GUILayout.Button(Contents.checkWindow, EditorStyles.toolbarButton))
                        {
                            EditorWindow.GetWindow <CheckWindow>();
                        }
                        GUILayout.Space(16);
                    }

                    if (Preferences.showComments)
                    {
                        if (GUILayout.Button(Contents.commentsWindow, EditorStyles.toolbarButton))
                        {
                            CommentsWindow.Open();
                        }
                        if (GUILayout.Button(Contents.addComment, EditorStyles.toolbarButton))
                        {
                            SceneCommentEditor.CreateComment();
                        }
                    }

                    if (Preferences.showCustom)
                    {
                        // Custom Callback here
                        if (OnSceneViewToolbarGUI != null)
                        {
                            OnSceneViewToolbarGUI.Invoke(sceneView);
                        }
                    }

                    GUILayout.FlexibleSpace();
                    // Saving Space not to overlap view controls
                    GUILayout.Space(96);
                }
            }

            if (LinkGameView.CinemachineActive)
            {
                DisplayText("CINEMACHINE PREVIEW", Styles.cineColor);
            }
            else if (LinkGameView.Active)
            {
                if (LinkGameView.LockedSceneView == sceneView)
                {
                    DisplayText("GAME VIEW LINKED (LOCKED)", Styles.lockedLinkColor);
                }
                else if (LinkGameView.LockedSceneView == null && SceneView.lastActiveSceneView == sceneView)
                {
                    DisplayText("GAME VIEW LINKED", Color.white);
                }
            }

            Handles.EndGUI();
        }
Esempio n. 2
0
        private static void OnSceneGUI(SceneView sceneView)
        {
            var r = new Rect(Vector2.zero, new Vector2(sceneView.position.width, 24));

            Handles.BeginGUI();
            using (new GUILayout.AreaScope(r))
            {
                using (new GUILayout.HorizontalScope(EditorStyles.toolbar))
                {
                    if (PlayFromHere.IsReady)
                    {
                        bool play = GUILayout.Toggle(EditorApplication.isPlaying, Contents.playFromHere, EditorStyles.toolbarButton);

                        if (GUI.changed)
                        {
                            if (play)
                            {
                                PlayFromHere.Play(sceneView);
                            }
                            else
                            {
                                EditorApplication.isPlaying = false;
                            }
                        }

                        GUILayout.Space(24);
                    }

                    Color backup = GUI.color;

                    bool isLinked = LinkGameView.Active;
                    bool isLocked = LinkGameView.LockedSceneView == sceneView;


                    if (isLinked && isLocked)
                    {
                        GUI.color = Color.green * 2;
                    }

                    isLinked = GUILayout.Toggle(isLinked, Contents.linkGameView, EditorStyles.toolbarButton, GUILayout.Width(64));

                    if (GUI.changed)
                    {
                        LinkGameView.Active = isLinked;
                    }

                    isLocked = GUILayout.Toggle(isLocked, Contents.lockLinkGameView, EditorStyles.toolbarButton);

                    if (GUI.changed)
                    {
                        if (isLocked)
                        {
                            LinkGameView.LockedSceneView = sceneView;
                        }
                        else
                        {
                            LinkGameView.LockedSceneView = null;
                        }
                    }

                    GUI.color = backup;

                    // SceneViewPOV
                    GUILayout.Space(16);
                    if (GUILayout.Button("POV", EditorStyles.toolbarDropDown))
                    {
                        Rect btnrect = GUILayoutUtility.GetLastRect();
                        btnrect.yMax += 17;
                        SceneViewPOV.ShowPopup(btnrect, sceneView);
                    }

                    GUILayout.FlexibleSpace();

                    // Custom Code here
                    if (OnSceneViewToolbarGUI != null)
                    {
                        OnSceneViewToolbarGUI.Invoke(sceneView);
                    }

                    // Saving Space not to overlap view controls
                    GUILayout.Space(96);
                }
            }
            Handles.EndGUI();
        }