Exemplo n.º 1
0
        private void DrawComponentInspector()
        {
            const float kBoxMargin = 4;  // GML wtf get rid of this
            const float indentSize = 15; // GML wtf get rid of this

            int index = (int)mStage;

            EditorGUILayout.BeginVertical(GUI.skin.box);
            EditorGUIUtility.labelWidth -= kBoxMargin;

            Rect rect = EditorGUILayout.GetControlRect(true);

            // Don't use PrefixLabel() because it will link the enabled status of field and label
            GUIContent label = new GUIContent(InspectorUtility.NicifyClassName(mStage.ToString()));

            if (mStageError)
            {
                label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
            }
            float labelWidth = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * indentSize;
            Rect  r          = rect; r.width = labelWidth; r.x -= kBoxMargin;

            EditorGUI.LabelField(r, label);

            r = rect; r.width -= labelWidth; r.x += labelWidth;
            bool wasEnabled = GUI.enabled;

            if (TypeIsLocked)
            {
                GUI.enabled = false;
            }
            int newSelection = EditorGUI.Popup(r, mStageSelection, sStageData[index].PopupOptions);

            GUI.enabled = wasEnabled;

            Type type = sStageData[index].types[newSelection];

            if (newSelection != mStageSelection)
            {
                if (mComponent != null)
                {
                    if (DestroyComponent != null)
                    {
                        DestroyComponent(mComponent);
                    }
                }
                if (newSelection != 0)
                {
                    sStageData[index].IsExpanded = true;
                    if (SetComponent != null)
                    {
                        SetComponent(type);
                    }
                }
                mComponent = null;
                GUIUtility.ExitGUI();
                return; // let the component editor be recreated
            }

            // Draw the embedded editor
            if (type != null)
            {
                r = new Rect(rect.x - kBoxMargin, rect.y, labelWidth, rect.height);
                sStageData[index].IsExpanded = EditorGUI.Foldout(
                    r, sStageData[index].IsExpanded, GUIContent.none, true);
                if (sStageData[index].IsExpanded)
                {
                    // Make the editor for that stage
                    if (mComponentEditor != null)
                    {
                        ++EditorGUI.indentLevel;
                        EditorGUILayout.Separator();
                        mComponentEditor.OnInspectorGUI();
                        EditorGUILayout.Separator();
                        --EditorGUI.indentLevel;
                    }
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUIUtility.labelWidth += kBoxMargin;
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            // Ordinary properties
            base.OnInspectorGUI();

            // Pipeline - call this first
            UpdateInstanceData();

            // Here are the pipeline stages
            CinemachineCore.Stage[] sections = new CinemachineCore.Stage[]
            {
                CinemachineCore.Stage.Lens,
                CinemachineCore.Stage.Aim,
                CinemachineCore.Stage.Body,
                CinemachineCore.Stage.Noise
            };
            for (int i = 0; i < sections.Length; ++i)
            {
                CinemachineCore.Stage stage = sections[i];
                int index = (int)stage;

                // Skip pipeline stages that have no implementations
                if (sStageData[index].PopupOptions.Length <= 1)
                {
                    continue;
                }

                GUIStyle stageBoxStyle = GUI.skin.box;
                stageBoxStyle.margin.left = 16;
                EditorGUILayout.BeginVertical(stageBoxStyle);

                Rect rect = EditorGUILayout.GetControlRect(true);
                rect.height = EditorGUIUtility.singleLineHeight;

                GUI.enabled = !StageIsLocked(stage);
                int newSelection = EditorGUI.Popup(rect,
                                                   NicifyName(stage.ToString()), m_stageState[index],
                                                   sStageData[index].PopupOptions);
                GUI.enabled = true;
                Type type = sStageData[index].types[newSelection];
                if (newSelection != m_stageState[index])
                {
                    SetPipelineStage(stage, type);
                    if (newSelection != 0)
                    {
                        sStageData[index].isExpanded = true;
                    }
                    UpdateInstanceData(); // because we changed it
                    return;
                }
                if (type != null)
                {
                    int  indentOffset = 6;
                    Rect stageRect    = new Rect(
                        rect.x - indentOffset, rect.y, rect.width + indentOffset, rect.height);
                    sStageData[index].isExpanded = EditorGUI.Foldout(
                        stageRect, sStageData[index].isExpanded, GUIContent.none);
                    if (sStageData[index].isExpanded)
                    {
                        // Make the editor for that stage
                        UnityEditor.Editor e = GetEditorForPipelineStage(stage);
                        if (e != null)
                        {
                            ++EditorGUI.indentLevel;
                            EditorGUILayout.Separator();
                            e.OnInspectorGUI();
                            EditorGUILayout.Separator();
                            --EditorGUI.indentLevel;
                        }
                    }
                }
                EditorGUILayout.EndVertical();
            }
        }
        private void DrawComponentInspector()
        {
            const float indentSize = 15; // GML wtf get rid of this
            int         index      = (int)m_Stage;
            Rect        rect       = EditorGUILayout.GetControlRect(true);

            // Don't use PrefixLabel() because it will link the enabled status of field and label
            GUIContent label = new GUIContent(InspectorUtility.NicifyClassName(m_Stage.ToString()));

            if (m_StageError)
            {
                label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
            }
            float labelWidth = EditorGUIUtility.labelWidth - EditorGUI.indentLevel * indentSize;
            Rect  r          = rect; r.width = labelWidth;

            EditorGUI.LabelField(r, label);

            r = rect; r.width -= labelWidth; r.x += labelWidth;

            EditorGUI.BeginChangeCheck();
            bool wasEnabled = GUI.enabled;

            if (TypeIsLocked)
            {
                GUI.enabled = false;
            }
            EditorGUI.showMixedValue = m_IsMixedType;
            m_StageSelection         = EditorGUI.Popup(r, m_StageSelection, sStageData[index].PopupOptions);
            EditorGUI.showMixedValue = false;
            GUI.enabled = wasEnabled;
            Type type = sStageData[index].types[m_StageSelection];

            if (EditorGUI.EndChangeCheck())
            {
                SetComponent(m_Stage, type);
                if (m_StageSelection != 0)
                {
                    sStageData[index].IsExpanded = true;
                }
                Shutdown();
                GUIUtility.ExitGUI();
                return; // let the component editor be recreated
            }

            // Draw the embedded editor
            if (type != null)
            {
                r = new Rect(rect.x, rect.y, labelWidth, rect.height);
                var isExpanded = m_IsMixedType ? false : EditorGUI.Foldout(
                    r, sStageData[index].IsExpanded, GUIContent.none, true);
                if (isExpanded || isExpanded != sStageData[index].IsExpanded)
                {
                    // Make the editor for that stage
                    ActiveEditorRegistry.SetActiveEditor(m_ComponentEditor, isExpanded);
                    if (isExpanded && m_ComponentEditor != null)
                    {
                        ++EditorGUI.indentLevel;
                        m_ComponentEditor.OnInspectorGUI();
                        --EditorGUI.indentLevel;
                    }
                }
                sStageData[index].IsExpanded = isExpanded;
            }
        }