public override void OnInspectorGUI()
        {
            ConstraintStack cstack = (ConstraintStack)target;

            serializedObject.Update();

            GUILayout.Space(3f);

            // constraints
            for (int i = 0; i < cstack.constraintCount; ++i)
            {
                BaseConstraint c = cstack.Get(i);
                if (!c)
                { //remove broken reference
                    cstack.RemoveAt(i);
                    --i;
                    continue;
                }

                // draw constraint & buttons
                EditorGUILayout.BeginHorizontal();
                {
                    Color btnColor = c.IsActiveConstraint ? Color.white : Color.red;
                    EUtil.PushBackgroundColor(btnColor);
                    var  content = new GUIContent(c.GetType().Name, "Click to fold other components");
                    Rect rc      = GUILayoutUtility.GetRect(content, EditorStyles.toolbarButton);
                    if (GUI.Button(rc, content, EditorStyles.toolbarButton))
                    {
                        _FoldComponents(cstack);
                        var wnd = EditorEditorWindow.OpenWindowWithActivatorRect(c, rc);
                        EUtil.SetEditorWindowTitle(wnd, content.text);
                    }
                    EditorGUI.ProgressBar(rc, c.Influence, content.text);
                    EUtil.PopBackgroundColor();

                    if (GUILayout.Button(new GUIContent(c.IsActiveConstraint ? EConUtil.activeBtn : EConUtil.inactiveBtn, "Toggle constraint active state"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        c.IsActiveConstraint = !c.IsActiveConstraint;
                        EditorUtility.SetDirty(cstack);
                    }

                    EUtil.PushGUIEnable(i != 0);
                    if (GUILayout.Button(new GUIContent(EConUtil.upBtn, "move up"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i - 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentUp(c);
                    }
                    EUtil.PopGUIEnable();

                    EUtil.PushGUIEnable(i != cstack.constraintCount - 1);
                    if (GUILayout.Button(new GUIContent(EConUtil.downBtn, "move down"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        cstack.Swap(i, i + 1);
                        EditorUtility.SetDirty(cstack);
                        //ComponentUtility.MoveComponentDown(c);
                    }
                    EUtil.PopGUIEnable();

                    if (GUILayout.Button(new GUIContent(EConUtil.deleteBtn, "delete the constraint from stack"), EditorStyles.toolbarButton, GUILayout.Height(20), GUILayout.Width(20)))
                    {
                        MUndo.RecordObject(cstack, "Remove Constraint");
                        cstack.RemoveAt(i);
                        EditorUtility.SetDirty(cstack);
                        _FoldComponents(cstack);
                        EditorGUIUtility.ExitGUI();
                    }
                }
                EditorGUILayout.EndHorizontal();
            } //for(int i=0; i<cstack.constraintCount; ++i)

            GUILayout.Space(2f);

            EditorGUI.BeginChangeCheck();
            int newOrder = EditorGUILayout.IntField(new GUIContent("Exec Order", "used to help decide evaluation order, the smaller the earlier"), cstack.ExecOrder);

            if (EditorGUI.EndChangeCheck())
            {
                cstack.ExecOrder = newOrder;
            }

            { //new constraint window
                EUtil.DrawSplitter(new Color(1, 1, 1, 0.3f));

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(15f);
                var  content = new GUIContent("Add Constraint", "Add new constraint into current stack");
                Rect btnRc   = GUILayoutUtility.GetRect(content, GUI.skin.button);
                if (GUI.Button(btnRc, content))
                {
                    var  wnd   = ScriptableObject.CreateInstance <ConstraintsWindow>();
                    Rect wndRc = EUtil.GetRectByActivatorRect(wnd.position, btnRc);
                    wnd.position = wndRc;
                    wnd.SetConstraintStack(cstack);
                    wnd.ShowPopup();
                    wnd.Focus();
                }
                GUILayout.Space(15f);
                EditorGUILayout.EndHorizontal();
            }


            if (Pref.ShowInitInfos)
            {
                EditorGUILayout.PropertyField(m_spInitInfo, true);
            }



            serializedObject.ApplyModifiedProperties();
        }
示例#2
0
            // public method

            #endregion "public method"

            #region "private method"

            private void _DrawDeformEntry(MorphProc proc, int deformIdx, bool isBasis = true)
            {
                ShapeKeyMorphSO deform = (ShapeKeyMorphSO)m_propDeforms.GetArrayElementAtIndex(deformIdx).objectReferenceValue;

                EditorGUILayout.BeginHorizontal();
                {
                    float newWeight = 0f;

                    // weight
                    if (isBasis)
                    {
                        EUtil.PushGUIEnable(false);
                    }

                    EditorGUI.BeginChangeCheck();
                    newWeight = EditorGUILayout.FloatField(deform.name, m_propAnimWeights[deformIdx].floatValue);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_propAnimWeights[deformIdx].floatValue = Mathf.Clamp(newWeight, 0, 100f);
                    }

                    if (isBasis)
                    {
                        EUtil.PopGUIEnable();
                    }

                    // after weight
                    if (isBasis)
                    { //the basis
                        GUILayout.Space(20f);
                        if (EUtil.Button("R", "Reset as Basis", Color.green, GUILayout.Width(42f)))
                        {
                            Undo.RecordObject(proc, "MorphProc Inspector");
                            proc.ResetToBasisShape();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent(m_texDetail, "Edit details of this deform"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            var e = (BaseMorphSOEditor)Editor.CreateEditor(deform);
                            e.m_MorphProcEditor = this;
                            e.m_MorphProc       = proc;
                            e.m_MorphIdx        = deformIdx;
                            EditorEditorWindow.OpenWindowWithEditor(e);
                        }

                        if (GUILayout.Button(new GUIContent(m_texApply, "Apply only this deform 100%"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            Undo.RecordObject(proc, "MorphProc Inspector");
                            proc.ApplyOnlyMorphAt(deformIdx);
                        }

                        if (GUILayout.Button(new GUIContent(m_texDelete, "Delete this deform"), m_styleBtn, GUILayout.Width(20f)))
                        {
                            if (EditorUtility.DisplayDialog("To be or not to be", "Are you sure to delete this Morph?", "Go Ahead", "No No No"))
                            {
                                Undo.RecordObject(proc, "MorphProc Inspector");
                                proc.RemoveShapeKeyMorphAt(deformIdx);
                            }
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }