public override void OnInspectorGUI()
        {
            if (!Target.m_HideHeaderInInspector)
            {
                // Is the camera navel-gazing?
                CameraState state = Target.State;
                if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
                {
                    EditorGUILayout.HelpBox(
                        "The camera is positioned on the same point at which it is trying to look.",
                        MessageType.Warning);
                }

                // Active status and Solo button
                Rect rect      = EditorGUILayout.GetControlRect(true);
                Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);
                rect.width -= rectLabel.width;
                rect.x     += rectLabel.width;

                Color color  = GUI.color;
                bool  isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);
                if (isSolo)
                {
                    GUI.color = CinemachineBrain.GetSoloGUIColor();
                }

                bool isLive = CinemachineCore.Instance.IsLive(Target);
                GUI.enabled = isLive;
                GUI.Label(rectLabel, isLive ? "Status: Live"
                    : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
                GUI.enabled = true;
                if (GUI.Button(rect, "Solo", "Button"))
                {
                    isSolo = !isSolo;
                    CinemachineBrain.SoloCamera = isSolo ? Target : null;
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
                GUI.color = color;
                if (isSolo)
                {
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
            }
            List <string> excluded = GetExcludedPropertiesInInspector();

            serializedObject.Update();
            DrawPropertiesExcluding(serializedObject, excluded.ToArray());
            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            if (!Target.m_HideHeaderInInspector)
            {
                // Active status and Solo button
                Rect rect      = EditorGUILayout.GetControlRect(true);
                Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);
                rect.width -= rectLabel.width;
                rect.x     += rectLabel.width;

                Color color  = GUI.color;
                bool  isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);
                if (isSolo)
                {
                    GUI.color = CinemachineBrain.GetSoloGUIColor();
                }

                bool isLive = CinemachineCore.Instance.IsLive(Target);
                GUI.enabled = isLive;
                GUI.Label(rectLabel, isLive ? "Status: Live"
                    : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
                GUI.enabled = true;
                if (GUI.Button(rect, "Solo", "Button"))
                {
                    isSolo = !isSolo;
                    CinemachineBrain.SoloCamera = isSolo ? Target : null;
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
                GUI.color = color;
                if (isSolo)
                {
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
            }
            string[] excluded = GetExcludedPropertiesInInspector();
            if (excluded == null)
            {
                base.OnInspectorGUI();
            }
            else
            {
                serializedObject.Update();
                DrawPropertiesExcluding(serializedObject, excluded);
                serializedObject.ApplyModifiedProperties();
            }
        }
        private void DrawProportionIndicator(
            CinemachineVirtualCameraBase[] children, int numCameras, float totalWeight)
        {
            var style       = EditorStyles.centeredGreyMiniLabel;
            var bkg         = new Color(0.27f, 0.27f, 0.27f); // ack! no better way than this?
            var fg          = Color.Lerp(CinemachineBrain.GetSoloGUIColor(), bkg, 0.8f);
            var totalHeight = (style.lineHeight + style.margin.vertical) * numCameras;
            var r           = EditorGUILayout.GetControlRect(true, totalHeight);

            r.height /= numCameras;
            r.height -= 1;
            var fullWidth = r.width;

            for (var i = 0; i < numCameras; ++i)
            {
                float p     = 0;
                var   label = children[i].Name;
                if (totalWeight > UnityVectorExtensions.Epsilon)
                {
                    if (children[i].isActiveAndEnabled)
                    {
                        p = Target.GetWeight(i) / totalWeight;
                    }
                    else
                    {
                        label += " (disabled)";
                    }
                }

                r.width = fullWidth * p;
                EditorGUI.DrawRect(r, fg);

                var r2 = r;
                r2.x    += r.width;
                r2.width = fullWidth - r.width;
                EditorGUI.DrawRect(r2, bkg);

                r.width = fullWidth;
                EditorGUI.LabelField(r, label, style);

                r.y += r.height + 1;
            }
        }
Esempio n. 4
0
        protected void DrawCameraStatusInInspector()
        {
            // Is the camera navel-gazing?
            CameraState state = Target.State;

            if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
            {
                EditorGUILayout.HelpBox(
                    "The camera is positioned on the same point at which it is trying to look.",
                    MessageType.Warning);
            }

            // Active status and Solo button
            Rect rect      = EditorGUILayout.GetControlRect(true);
            Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);

            rect.width -= rectLabel.width;
            rect.x     += rectLabel.width;

            Color color  = GUI.color;
            bool  isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);

            if (isSolo)
            {
                GUI.color = CinemachineBrain.GetSoloGUIColor();
            }

            bool isLive = CinemachineCore.Instance.IsLive(Target);

            GUI.enabled = isLive;
            GUI.Label(rectLabel, isLive ? "Status: Live"
                : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
            GUI.enabled = true;

            float      labelWidth = 0;
            GUIContent updateText = GUIContent.none;

            UpdateTracker.UpdateClock updateMode = CinemachineCore.Instance.GetVcamUpdateStatus(Target);
            if (Application.isPlaying)
            {
                updateText = new GUIContent(
                    updateMode == UpdateTracker.UpdateClock.Fixed ? " Fixed Update" : " Late Update");
                var textDimensions = GUI.skin.label.CalcSize(updateText);
                labelWidth = textDimensions.x;
            }
            rect.width -= labelWidth;
            if (GUI.Button(rect, "Solo", "Button"))
            {
                isSolo = !isSolo;
                CinemachineBrain.SoloCamera = isSolo ? Target : null;
#if UNITY_2019_1_OR_NEWER
                EditorUtility.SetDirty(Target);
#else
                UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
#endif
            }
            GUI.color = color;
            if (isSolo && !Application.isPlaying)
            {
                InspectorUtility.RepaintGameView(Target);
            }

            if (labelWidth > 0)
            {
                GUI.enabled = false;
                rect.x     += rect.width; rect.width = labelWidth;
                GUI.Label(rect, updateText);
                GUI.enabled = true;
            }
        }
        public override void OnInspectorGUI()
        {
            if (!Target.m_HideHeaderInInspector)
            {
                // Is the camera navel-gazing?
                CameraState state = Target.State;
                if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
                {
                    EditorGUILayout.HelpBox(
                        "The camera is positioned on the same point at which it is trying to look.",
                        MessageType.Warning);
                }

                bool hasInconsistentAnimation, hadInconsistentAnimation;
                CinemachineCore.UpdateFilter updateMode;
                CinemachineCore.Instance.GetVcamUpdateStatus(
                    Target, out updateMode, out hasInconsistentAnimation, out hadInconsistentAnimation);
#if false // Not sure these warning are still valid or helpful
                if (hasInconsistentAnimation)
                {
                    EditorGUILayout.HelpBox(
                        "This camera is currently looking at or following a target that is being moved in both FixedUpdate and Update.  This is a potential source of camera jitter.  One possible cause of this is the use of Interpolation in the RigidBody of the target.  Try turning that off.",
                        MessageType.Error);
                }
                else if (hadInconsistentAnimation)
                {
                    EditorGUILayout.HelpBox(
                        "This camera was at some time looking at or following a target that was being moved in both FixedUpdate and Update.  This is a potential source of camera jitter.  One possible cause of this is the use of Interpolation in the RigidBody of the target.  Try turning that off.",
                        MessageType.Warning);
                }
#endif
                // Active status and Solo button
                Rect rect      = EditorGUILayout.GetControlRect(true);
                Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);
                rect.width -= rectLabel.width;
                rect.x     += rectLabel.width;

                Color color  = GUI.color;
                bool  isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);
                if (isSolo)
                {
                    GUI.color = CinemachineBrain.GetSoloGUIColor();
                }

                bool isLive = CinemachineCore.Instance.IsLive(Target);
                GUI.enabled = isLive;
                GUI.Label(rectLabel, isLive ? "Status: Live"
                    : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
                GUI.enabled = true;

                GUIContent updateText = new GUIContent(
                    updateMode == CinemachineCore.UpdateFilter.Fixed ? " Fixed Update" : " Late Update");
                var   textDimensions = GUI.skin.label.CalcSize(updateText);
                float labelWidth     = textDimensions.x;
                if (Application.isPlaying)
                {
                    rect.width -= labelWidth;
                }
                if (GUI.Button(rect, "Solo", "Button"))
                {
                    isSolo = !isSolo;
                    CinemachineBrain.SoloCamera = isSolo ? Target : null;
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }
                GUI.color = color;
                if (isSolo)
                {
                    UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
                }

                if (Application.isPlaying)
                {
                    GUI.enabled = false;
                    rect.x     += rect.width; rect.width = labelWidth;
                    GUI.Label(rect, updateText);
                    GUI.enabled = true;
                }
                CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides
                    = EditorGUILayout.Toggle(
                          new GUIContent(
                              "Game Window Guides",
                              "Enable the display of overlays in the Game window.  You can adjust colours and opacity in Edit/Preferences/Cinemachine."),
                          CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides);

                SaveDuringPlay.SaveDuringPlay.Enabled
                    = EditorGUILayout.Toggle(
                          new GUIContent(
                              "Save During Play",
                              "If checked, Virtual Camera settings changes made during Play Mode will be propagated back to the scene when Play Mode is exited."),
                          SaveDuringPlay.SaveDuringPlay.Enabled);
                if (Application.isPlaying && SaveDuringPlay.SaveDuringPlay.Enabled)
                {
                    EditorGUILayout.HelpBox(
                        " Virtual Camera settings changes made during Play Mode will be propagated back to the scene when Play Mode is exited.",
                        MessageType.Info);
                }
            }

            List <string> excluded = GetExcludedPropertiesInInspector();
            serializedObject.Update();
            DrawPropertiesExcluding(serializedObject, excluded.ToArray());
            serializedObject.ApplyModifiedProperties();
        }
Esempio n. 6
0
        private void DrawCameraStatusInInspector()
        {
            // Is the camera navel-gazing?
            var state = Target.State;

            if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
            {
                EditorGUILayout.HelpBox(
                    "The camera is positioned on the same point at which it is trying to look.",
                    MessageType.Warning);
            }

            // Active status and Solo button
            var rect      = EditorGUILayout.GetControlRect(true);
            var rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);

            rect.width -= rectLabel.width;
            rect.x     += rectLabel.width;

            var color  = GUI.color;
            var isSolo = (T)CinemachineBrain.SoloCamera == Target;

            if (isSolo)
            {
                GUI.color = CinemachineBrain.GetSoloGUIColor();
            }

            var isLive = CinemachineCore.Instance.IsLive(Target);

            GUI.enabled = isLive;
            GUI.Label(rectLabel, isLive
                ? "Status: Live"
                : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
            GUI.enabled = true;

            float labelWidth = 0;
            var   updateText = GUIContent.none;
            var   updateMode = CinemachineCore.Instance.GetVcamUpdateStatus(Target);

            if (Application.isPlaying)
            {
                updateText = new GUIContent(
                    updateMode < CinemachineCore.UpdateFilter.Late ? " Fixed Update" : " Late Update");
                var textDimensions = GUI.skin.label.CalcSize(updateText);
                labelWidth = textDimensions.x;
            }

            rect.width -= labelWidth;
            if (GUI.Button(rect, "Solo", "Button"))
            {
                isSolo = !isSolo;
                CinemachineBrain.SoloCamera = isSolo ? Target : null;
                InternalEditorUtility.RepaintAllViews();
            }

            GUI.color = color;
            if (isSolo)
            {
                InternalEditorUtility.RepaintAllViews();
            }

            if (!(labelWidth > 0))
            {
                return;
            }

            GUI.enabled = false;
            rect.x     += rect.width;
            rect.width  = labelWidth;
            GUI.Label(rect, updateText);
            GUI.enabled = true;
        }