// public method

        #endregion "public method"

        #region "private method"



        private void _OnGUI_IKPanel(CCDSolverMB cp)
        {
            switch (m_panel)
            {
            case EPanel.Normal: break;

            case EPanel.Continuous: break;

            case EPanel.Manual:
            {
                EUtil.DrawSplitter();
                if (GUILayout.Button(CONT_GO, EditorStyles.toolbarButton))
                {
                    var solver = cp.GetSolver();
                    Undo.RecordObjects(solver.GetJoints(), "IK Follow");
                    solver.Execute();
                }
            }
            break;

            case EPanel.Debug:
            {
                EUtil.DrawSplitter();
                _OnGUI_IKPanel_Debug(cp);
            }
            break;

            default:
                Dbg.LogErr("CCDSolverEditor._OnGUI_IKPanel: unexpected panel mode: {0}", m_panel);
                break;
            }
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            LookAt cp = (LookAt)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                cp.LookAxis = (EAxisD)EConUtil.DrawEnumBtns(AllLookAxis, AllLookAxisStr, cp.LookAxis, "LookAxis", "the axis to point towards target");
                cp.UpAxis   = (EAxisD)EConUtil.DrawEnumBtns(AllLookAxis, AllLookAxisStr, cp.UpAxis, "UpAxis", "the axis to point upward");

                cp.UpAxis = ConUtil.EnsureAxisNotColinear(cp.LookAxis, cp.UpAxis);

                GUILayout.Space(5f);

                //influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #3
0
        public override void OnInspectorGUI()
        {
            ShrinkWrap cp = (ShrinkWrap)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            var newTarget = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            if (newTarget != null &&
                (newTarget.GetComponent <MeshFilter>() == null || newTarget.GetComponent <Collider>() == null)
                )
            {
                EUtil.ShowNotification("Target must have MeshFilter & Collider");
            }
            else
            {
                cp.Target = newTarget;
            }

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                cp.Method = (ShrinkWrap.EShrinkWrapMethod)EditorGUILayout.EnumPopup(new GUIContent("ShrinkWrap Method", "select the algorithm for the action"), cp.Method);
                if (cp.Method == ShrinkWrap.EShrinkWrapMethod.NearestVertex)
                {
                    EUtil.GetSceneView().renderMode = DrawCameraMode.TexturedWire;
                }
                else
                {
                    EUtil.GetSceneView().renderMode = DrawCameraMode.Textured;
                }

                cp.Distance = EditorGUILayout.FloatField(new GUIContent("Distance", "keep distance to the projected point"), cp.Distance);

                if (cp.Method == ShrinkWrap.EShrinkWrapMethod.Project)
                {
                    cp.ProjectDir         = (EAxisD)EConUtil.DrawEnumBtns(EConUtil.AxisDs, EConUtil.AxisDStrs, cp.ProjectDir, "ProjectDir", "the direction or project ray, from origin of owner");
                    cp.OwnerSpace         = (ESpace)EditorGUILayout.EnumPopup(new GUIContent("OwnerSpace", "the space used for project dir"), cp.OwnerSpace);
                    cp.MaxProjectDistance = Mathf.Max(0, EditorGUILayout.FloatField(new GUIContent("Max Project Dist", "only execute wrap when the projected point is within the dist; 0 means infinite distance"), cp.MaxProjectDistance));
                }
                else if (cp.Method == ShrinkWrap.EShrinkWrapMethod.NearestVertex)
                {
                    //nothing here
                }

                //cp.ModifyInitInfo = EditorGUILayout.Toggle(new GUIContent("Modify InitInfo", "the constraint result will be written back to the initInfo"), cp.ModifyInitInfo);

                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #4
0
        public override void OnInspectorGUI()
        {
            LockedTrack cp = (LockedTrack)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                cp.LookAxis = (EAxisD)EConUtil.DrawEnumBtns(EConUtil.AxisDs, EConUtil.AxisDStrs, cp.LookAxis, "LookAxis", "Owner's local axis used to aim at the target", 80f);
                GUILayout.Space(5f);

                cp.RotateAxis = (EAxisD)EConUtil.DrawEnumBtns(EConUtil.AxisDsPositive, EConUtil.AxisDStrsPositive, cp.RotateAxis, "Rotate Axis", "Owner's local axis used to rotate around", 80f);
                GUILayout.Space(5f);

                cp.RotateAxis = ConUtil.EnsureAxisNotColinear(cp.LookAxis, cp.RotateAxis);

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #5
0
        public override void OnInspectorGUI()
        {
            ClampTo cp = (ClampTo)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Spline = (BaseSplineBehaviour)EditorGUILayout.ObjectField("Target Spline", cp.Spline, typeof(BaseSplineBehaviour), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Spline);
            {
                //axis and offset
                m_foldoutAxis = EditorGUILayout.Foldout(m_foldoutAxis, "Affect");
                if (m_foldoutAxis)
                {
                    cp.MainAxis = (EAxis)EConUtil.DrawEnumBtns(AllAxis, AllAxisStr, cp.MainAxis, "Main Axis", "Choose the axis used to decide the parameter t for evaluate spline");

                    // offset
                    cp.UseOffset = EditorGUILayout.Toggle(new GUIContent("Use Offset", "Add offset onto the result"), cp.UseOffset);
                    if (cp.UseOffset)
                    {
                        cp.Offset = EUtil.DrawV3P(new GUIContent("Offset", "Offset in world space"), cp.Offset);
                    }

                    cp.Cyclic = EditorGUILayout.Toggle(new GUIContent("Cyclic", "the object will revert to the beginning of spline when exceed the dimension"), cp.Cyclic);

                    GUILayout.Space(5f);
                }

                // dimension and startVal
                m_foldoutPos = EditorGUILayout.Foldout(m_foldoutPos, "Pos Define");
                if (m_foldoutPos)
                {
                    cp.Dimension = EditorGUILayout.FloatField(new GUIContent("Dimension", "the projection length on mainAxis"), cp.Dimension);
                    cp.StartVal  = EditorGUILayout.FloatField(new GUIContent("StartVal", "the low value on mainAxis"), cp.StartVal);
                    if (GUILayout.Button(new GUIContent("Recalculate Dimension", "Recalculate dimension & startVal based on spline")))
                    {
                        var    behaviour = cp.Spline;
                        Bounds bd        = behaviour.CalculateTransformedBounds();
                        _SetDimensionByBounds(cp, bd);
                    }
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        public override void OnInspectorGUI()
        {
            LimitScale cp = (LimitScale)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                //affect X/Y/Z
                m_foldoutLimit = EditorGUILayout.Foldout(m_foldoutLimit, "Limits");
                if (m_foldoutLimit)
                {
                    ELimitAffect eAffect  = cp.LimitAffect;
                    Vector3      limitMin = cp.LimitMin;
                    Vector3      limitMax = cp.LimitMax;

                    limitMin.x = EConUtil.DrawLimitField(ref eAffect, "XMin", "min value of X", limitMin.x, ELimitAffect.MinX);
                    limitMax.x = EConUtil.DrawLimitField(ref eAffect, "XMax", "max value of X", limitMax.x, ELimitAffect.MaxX);
                    limitMin.y = EConUtil.DrawLimitField(ref eAffect, "YMin", "min value of Y", limitMin.y, ELimitAffect.MinY);
                    limitMax.y = EConUtil.DrawLimitField(ref eAffect, "YMax", "max value of Y", limitMax.y, ELimitAffect.MaxY);
                    limitMin.z = EConUtil.DrawLimitField(ref eAffect, "ZMin", "min value of Z", limitMin.z, ELimitAffect.MinZ);
                    limitMax.z = EConUtil.DrawLimitField(ref eAffect, "ZMax", "max value of Z", limitMax.z, ELimitAffect.MaxZ);

                    EConUtil.LimitFieldMinMaxFix(eAffect, ref limitMin, ref limitMax);

                    cp.LimitAffect = eAffect;
                    cp.LimitMin    = limitMin;
                    cp.LimitMax    = limitMax;

                    GUILayout.Space(5f);
                }

                m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                if (m_foldoutSpace)
                {
                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                //record modify
                cp.ModifyInternalData = EditorGUILayout.Toggle(new GUIContent("Modify Internal Data", "This modification will modify the ConstraintStack's internal transform data"), cp.ModifyInternalData);

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        public override void OnInspectorGUI()
        {
            ChildOf cp = (ChildOf)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            if (cp.Target && !ConstraintEditorUtil.IsTargetHasAllUniformScaleInHierarchy(cp.Target))
            {
                ConstraintEditorUtil.NonUniformScaleWarning(cp.Target);
            }

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                //affect X/Y/Z
                m_foldoutAffect.val = EditorGUILayout.Foldout(m_foldoutAffect.val, "Affect");
                if (m_foldoutAffect.val)
                {
                    cp.AffectPos = EConUtil.DrawAxisBtnMask(new GUIContent("Position", "which fields of position are affected"), cp.AffectPos);
                    cp.AffectRot = EConUtil.DrawAxisBtnMask(new GUIContent("Rotation", "which fields of rotation are affected"), cp.AffectRot);
                    cp.AffectSca = EConUtil.DrawAxisBtnMask(new GUIContent("Scale", "which fields of scale are affected"), cp.AffectSca);

                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            var pseuLocTr = cp.PseudoLocTr;

            pseuLocTr.pos   = EUtil.DrawV3P(new GUIContent("position", "the pseudo local position"), pseuLocTr.pos);
            pseuLocTr.rot   = Quaternion.Euler(EUtil.DrawV3P(new GUIContent("rotation", "the pseudo local rotation"), pseuLocTr.rot.eulerAngles));
            pseuLocTr.scale = EUtil.DrawV3P(new GUIContent("scale", "the pseudo local scale"), pseuLocTr.scale);
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(50f);
                if (GUILayout.Button(new GUIContent("Sample Data", "Use current transform data to calculate the pseudo local transform's data"), EditorStyles.toolbarButton))
                {
                    cp.RecalcPseudoLocalTransformData();
                }
                GUILayout.Space(50f);
            }
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #8
0
        public override void OnInspectorGUI()
        {
            LimitRotation cp = (LimitRotation)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                //affect X/Y/Z
                m_foldoutLimit = EditorGUILayout.Foldout(m_foldoutLimit, "Limits");
                if (m_foldoutLimit)
                {
                    ELimitEuler eLimit   = cp.LimitEuler;
                    Vector3     limitMin = cp.LimitMin;
                    Vector3     limitMax = cp.LimitMax;

                    EConUtil.DrawEulerLimitField(ref eLimit, "X", ref limitMin, ref limitMax, ELimitEuler.X, -180f, 180f);
                    EConUtil.DrawEulerLimitField(ref eLimit, "Y", ref limitMin, ref limitMax, ELimitEuler.Y, -180f, 180f);
                    EConUtil.DrawEulerLimitField(ref eLimit, "Z", ref limitMin, ref limitMax, ELimitEuler.Z, -180f, 180f);

                    cp.LimitEuler = eLimit;
                    cp.LimitMin   = limitMin;
                    cp.LimitMax   = limitMax;

                    GUILayout.Space(5f);
                }

                //space mapping
                //m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                //if (m_foldoutSpace)
                //{
                //    // owner space
                //    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                //    GUILayout.Space(5f);
                //}

                //record modify
                //cp.ModifyInternalData = EditorGUILayout.Toggle(new GUIContent("Modify Internal Data", "This modification will modify the ConstraintStack's internal transform data"), cp.ModifyInternalData);

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        public override void OnInspectorGUI()
        {
            LimitDistance cp = (LimitDistance)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                // distance & reset
                EditorGUILayout.BeginHorizontal();
                cp.Distance = EditorGUILayout.FloatField(new GUIContent("Distance", "limit distance"), cp.Distance);
                if (GUILayout.Button(new GUIContent("R", "recalculate the distance"), EditorStyles.miniButton, GUILayout.Width(20)))
                {
                    Transform tr = cp.transform;
                    cp.Distance = (tr.position - cp.Target.position).magnitude;
                }
                EditorGUILayout.EndHorizontal();

                // clamp region
                cp.ClampRegion = (EClampRegion)EditorGUILayout.EnumPopup(new GUIContent("Clamp Region", "decide how to limit the distance"), cp.ClampRegion);

                // space mapping
                m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                if (m_foldoutSpace)
                {
                    // target space
                    cp.TargetSpace = (ESpace)EditorGUILayout.EnumPopup("Target Space", cp.TargetSpace);

                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #10
0
        public override void OnInspectorGUI()
        {
            Floor cp = (Floor)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                cp.PlaneDir = (EAxisD)EConUtil.DrawEnumBtns(EConUtil.AxisDs, EConUtil.AxisDStrs, cp.PlaneDir, "Plane Normal", "the normal direction of floor plane");

                // offset
                cp.UseOffset = EditorGUILayout.Toggle(new GUIContent("Use Offset", "Add offset onto the result"), cp.UseOffset);
                if (cp.UseOffset)
                {
                    cp.Offset = EditorGUILayout.FloatField(new GUIContent("Offset", "offset along normal direction"), cp.Offset);
                }

                // raycast
                cp.UseRaycast = EditorGUILayout.Toggle(new GUIContent("Use Raycast", "use raycast to decide contact point"), cp.UseRaycast);

                EditorGUILayout.BeginHorizontal();
                {
                    EUtil.PushLabelWidth(100f);
                    EUtil.PushFieldWidth(20f);
                    cp.Sticky      = EditorGUILayout.Toggle(new GUIContent("Sticky", "Prevent sliding on plane"), cp.Sticky);
                    cp.UseRotation = EditorGUILayout.Toggle(new GUIContent("Use Rotation", "Use the rotation from target object"), cp.UseRotation);
                    EUtil.PopFieldWidth();
                    EUtil.PopLabelWidth();
                }
                EditorGUILayout.EndHorizontal();

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #11
0
        public override void OnInspectorGUI()
        {
            FollowPath cp = (FollowPath)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Spline = (BaseSplineBehaviour)EditorGUILayout.ObjectField("Target Spline", cp.Spline, typeof(BaseSplineBehaviour), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Spline);
            {
                EUtil.PushLabelWidth(100f);
                cp.Offset = EditorGUILayout.Slider(new GUIContent("Offset", "t parameter for the spline"), cp.Offset, 0, 1f);

                //axis and offset
                cp.FollowCurve = EditorGUILayout.Toggle(new GUIContent("Follow Curve", "owner's rotation will follow the spline"), cp.FollowCurve);
                if (cp.FollowCurve)
                {
                    cp.ForwardDir = (EAxisD)EConUtil.DrawEnumBtns(AllAxis, AllAxisStr, cp.ForwardDir, "Forward Axis", "the axis of owner, which will be taken as the forward direction when follow the spline");
                    cp.UpDir      = (EAxisD)EConUtil.DrawEnumBtns(AllAxis, AllAxisStr, cp.UpDir, "Up Axis", "the axis of owner, which will be taken as the up direction when follow the spline");

                    cp.UpDir = ConUtil.EnsureAxisNotColinear(cp.ForwardDir, cp.UpDir);

                    GUILayout.Space(5f);
                }
                EUtil.PopLabelWidth();

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        public override void OnInspectorGUI()
        {
            CopyTransform cp = (CopyTransform)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);
            if (cp.Target && !ConstraintEditorUtil.IsTargetHasAllUniformScaleInHierarchy(cp.Target))
            {
                ConstraintEditorUtil.NonUniformScaleWarning(cp.Target);
            }

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                if (m_foldoutSpace)
                {
                    // target space
                    cp.TargetSpace = (ESpace)EditorGUILayout.EnumPopup("Target Space", cp.TargetSpace);

                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        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();
        }
        public override void OnInspectorGUI()
        {
            TransformMapping cp = (TransformMapping)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);
            if (cp.Target && !ConstraintEditorUtil.IsTargetHasAllUniformScaleInHierarchy(cp.Target))
            {
                ConstraintEditorUtil.NonUniformScaleWarning(cp.Target);
            }

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                //mapping
                m_foldoutMapping = EditorGUILayout.Foldout(m_foldoutMapping, "Mapping");
                if (m_foldoutMapping)
                {
                    //source (from target)
                    ETransformData eSrcType = cp.SrcDataType;
                    EConUtil.DrawChooseTransformData(ref eSrcType, "Src data type", "which data of transform of target is taken as source");
                    cp.SrcDataType = eSrcType;

                    //destination (to owner)
                    ETransformData eDstType = cp.DstDataType;
                    EConUtil.DrawChooseTransformData(ref eDstType, "Dst data type", "which data of transform of target is taken as source");
                    cp.DstDataType = eDstType;

                    // XYZ mapping
                    GUILayout.Label("Source to Destination Mapping:");
                    for (int i = 0; i < 3; ++i)
                    {
                        EditorGUILayout.BeginHorizontal();
                        cp.Mapping[i] = (EAxis)EditorGUILayout.EnumPopup(cp.Mapping[i]);
                        GUILayout.Label(" >> " + (char)('X' + i));
                        EditorGUILayout.EndHorizontal();
                    }

                    // extrapolate
                    cp.Extrapolate = EditorGUILayout.Toggle(new GUIContent("Extrapolate", "will extend the range outside specified range"), cp.Extrapolate);

                    GUILayout.Space(5f);
                }

                //source data range
                m_foldoutSrcRange = EditorGUILayout.Foldout(m_foldoutSrcRange, "Source Range");
                if (m_foldoutSrcRange)
                {
                    Vector3 srcFrom = cp.SrcFrom;
                    Vector3 srcTo   = cp.SrcTo;
                    EConUtil.DrawAxisRange(ref srcFrom, ref srcTo);
                    cp.SrcFrom = srcFrom;
                    cp.SrcTo   = srcTo;
                    GUILayout.Space(5f);
                }

                //dest data range
                m_foldoutDstRange = EditorGUILayout.Foldout(m_foldoutDstRange, "Destination Range");
                if (m_foldoutDstRange)
                {
                    Vector3 dstFrom = cp.DstFrom;
                    Vector3 dstTo   = cp.DstTo;
                    EConUtil.DrawAxisRange(ref dstFrom, ref dstTo);
                    cp.DstFrom = dstFrom;
                    cp.DstTo   = dstTo;
                    GUILayout.Space(5f);
                }

                // space mapping
                m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                if (m_foldoutSpace)
                {
                    // target space
                    cp.TargetSpace = (ESpace)EditorGUILayout.EnumPopup("Target Space", cp.TargetSpace);

                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #15
0
        void OnGUI()
        {
            EditorGUI.BeginChangeCheck();
            _bones[(int)Bones.Root] = (Transform)EditorGUILayout.ObjectField(new GUIContent("Root", "the one at topmost with Animator componnet"), _bones[(int)Bones.Root], typeof(Transform), true);
            if (EditorGUI.EndChangeCheck())
            {
                _ClearBonesRefExceptRoot();
                _TryFindBones();
            }

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            {
                _refOpen = EditorGUILayout.Foldout(_refOpen, "bones");
                if (_refOpen)
                {
                    for (Bones eBone = (Bones)0; eBone < Bones.END; ++eBone)
                    {
                        Transform t = _bones[(int)eBone];
                        _bones[(int)eBone] = (Transform)EditorGUILayout.ObjectField(eBone.ToString(), t, typeof(Transform), true);
                    }
                }

                _optionOpen = EditorGUILayout.Foldout(_optionOpen, "options");
                if (_optionOpen)
                {
                    _addIKTarget = EditorGUILayout.Toggle(new GUIContent("Add IKTarget", "Add IK Targets for limbs"), _addIKTarget);

                    if (_addIKTarget)
                    {
                        _addFloor = EditorGUILayout.Toggle(new GUIContent("Floor Constraint", "Add Floor constraint on feet"), _addFloor);
                        if (_addFloor)
                        {
                            EditorGUI.indentLevel++;
                            _floorObj = (Transform)EditorGUILayout.ObjectField(new GUIContent("Floor Obj", "the object be taken as floor"), _floorObj, typeof(Transform), true);
                            EditorGUI.indentLevel--;
                        }

                        _addPelvisFollow = EditorGUILayout.Toggle(new GUIContent("Pelvis Follow", "Pelvis position is calculated with two feet"), _addPelvisFollow);
                    }
                }

                bool isAllFound = _IsAllFound();
                EditorGUILayout.HelpBox(isAllFound ? "All bones are found, you might check if the mappings are correct" : "Not all bones are setup, you might want to manually set those left out", MessageType.Info);

                if (_execLog.Length > 0)
                {
                    EditorGUILayout.HelpBox(_execLog.ToString(), MessageType.Info);
                }

                EUtil.DrawSplitter();
                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Space(0.1f * position.width);
                    EUtil.PushGUIEnable(_bones[(int)Bones.Root] != null);
                    if (EUtil.Button("Add Constraints", "If not all bones are set up, constraints will be only setup on those qualified", isAllFound ? Color.green : Color.yellow, GUILayout.Height(50f)))
                    {
                        _ExecuteAddConstraints();
                    }
                    if (EUtil.Button("Clear Constraints", "Clear all constraints on qualified joints", Color.white, GUILayout.Height(50f)))
                    {
                        _ExecuteDelConstraints();
                    }
                    EUtil.PopGUIEnable();
                    GUILayout.Space(0.1f * position.width);
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();
        }
Example #16
0
        public override void OnInspectorGUI()
        {
            CopyRotation cp = (CopyRotation)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Obj", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint && cp.Target);
            {
                //affect X/Y/Z
                m_foldoutAffect.val = EditorGUILayout.Foldout(m_foldoutAffect.val, "Affect");
                if (m_foldoutAffect.val)
                {
                    EUtil.PushLabelWidth(12f);
                    EUtil.PushFieldWidth(16f);
                    EditorGUILayout.BeginHorizontal();
                    {
                        EAxisD eAffect = cp.Affect;

                        eAffect = EConUtil.DrawAffectField(eAffect, "+X", "apply X from target to owner", EAxisD.X, EAxisD.InvX);
                        eAffect = EConUtil.DrawAffectField(eAffect, "-X", "apply -X from target to owner", EAxisD.InvX, EAxisD.X);
                        eAffect = EConUtil.DrawAffectField(eAffect, "+Y", "apply Y from target to owner", EAxisD.Y, EAxisD.InvY);
                        eAffect = EConUtil.DrawAffectField(eAffect, "-Y", "apply -Y from target to owner", EAxisD.InvY, EAxisD.Y);
                        eAffect = EConUtil.DrawAffectField(eAffect, "+Z", "apply Z from target to owner", EAxisD.Z, EAxisD.InvZ);
                        eAffect = EConUtil.DrawAffectField(eAffect, "-Z", "apply -Z from target to owner", EAxisD.InvZ, EAxisD.Z);

                        cp.Affect = eAffect;
                    }
                    EditorGUILayout.EndHorizontal();
                    EUtil.PopFieldWidth();
                    EUtil.PopLabelWidth();

                    // offset
                    cp.UseOffset = EditorGUILayout.Toggle(new GUIContent("Use Offset", "Add offset onto the result"), cp.UseOffset);
                    if (cp.UseOffset)
                    {
                        cp.Offset = EUtil.DrawV3P(new GUIContent("Offset", "Offset in owner space"), cp.Offset);
                    }

                    GUILayout.Space(5f);
                }


                m_foldoutSpace.val = EditorGUILayout.Foldout(m_foldoutSpace.val, "Space Mapping");
                if (m_foldoutSpace.val)
                {
                    // target space
                    cp.TargetSpace = (ESpace)EditorGUILayout.EnumPopup("Target Space", cp.TargetSpace);

                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
        public override void OnInspectorGUI()
        {
            CCDSolverMB cp = (CCDSolverMB)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            //constraint target
            cp.Target = (Transform)EditorGUILayout.ObjectField("Target Object", cp.Target, typeof(Transform), true);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                // reset button
                GUILayout.BeginHorizontal();
                GUILayout.Space(30f);
                if (EUtil.Button("Recollect IKConstraints", "click this when add new IK-constraint on this IK-link", Color.green))
                {
                    cp.GetSolver(true);
                    EUtil.RepaintSceneView();
                }
                GUILayout.Space(30f);
                GUILayout.EndHorizontal();


                // jointList
                if (!m_manualSetJoints)
                {
                    m_autoCollectBoneCount = EditorGUILayout.IntField(CONT_BoneCnt, m_autoCollectBoneCount);
                }
                else
                {
                    var jointList = cp.jointList;
                    Undo.RecordObject(cp, "JointList");
                    for (int i = 0; i < jointList.Count; ++i)
                    {
                        EditorGUILayout.BeginHorizontal();
                        jointList[i] = (Transform)EditorGUILayout.ObjectField(jointList[i], typeof(Transform), true);
                        if (GUILayout.Button(new GUIContent("+", "add new entry")))
                        {
                            jointList.Insert(i, null);
                            GUIUtility.ExitGUI();
                        }
                        if (GUILayout.Button(new GUIContent("-", "delete this entry")))
                        {
                            jointList.RemoveAt(i);
                            GUIUtility.ExitGUI();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(m_manualSetJoints ? CONT_ManualSetJoints : CONT_AutoSetJoints, EditorStyles.toolbarButton))
                {
                    m_manualSetJoints = !m_manualSetJoints;
                }

                bool isIdentical = _CheckJointListIdentical(cp);
                EUtil.PushBackgroundColor(isIdentical ? Color.white : Color.blue);
                if (GUILayout.Button(new GUIContent("Apply", "Apply the joint list"), EditorStyles.toolbarButton))
                {
                    if (m_manualSetJoints)
                    {
                        if (_CheckManualSetJointList(cp))
                        {
                            cp._RenewInitInfoAndSolver();
                        }
                    }
                    else
                    {
                        cp._RenewByCollectJointsWithBontCount(m_autoCollectBoneCount);
                    }
                    m_autoCollectBoneCount = cp.boneCount;
                }
                EUtil.PopBackgroundColor();

                EditorGUILayout.EndHorizontal();

                EUtil.DrawSplitter();

                // dist thres
                EditorGUI.BeginChangeCheck();
                float newDistThres = EditorGUILayout.FloatField(CONT_DistThres, cp.distThres);
                if (EditorGUI.EndChangeCheck())
                {
                    if (newDistThres > 0f)
                    {
                        Undo.RecordObject(cp, "Set Dist Thres");
                        cp.distThres = newDistThres;
                    }
                }

                cp.useDamp = EditorGUILayout.Toggle(CONT_Damp, cp.useDamp);
                if (cp.useDamp)
                {
                    cp.globalDamp = EditorGUILayout.FloatField("Global damp", cp.globalDamp);
                }

                cp.useTargetRotation = EditorGUILayout.Toggle(CONT_UseTargetRotation, cp.useTargetRotation);
                cp.maxIteration      = EditorGUILayout.IntField(CONT_MaxIteration, cp.maxIteration);

                cp.revertOpt = (CCDSolver.RevertOption)EditorGUILayout.EnumPopup(CONT_RevertOpt, cp.revertOpt);

                m_markerSize.val = Mathf.Max(0, EditorGUILayout.FloatField(CONT_BoneMarkSize, m_markerSize.val));

                EUtil.PushGUIEnable(!cp.Target);
                {
                    if (GUILayout.Button("Control Mode:  " + (cp.Target ? "Target" : m_panel.ToString()), EditorStyles.toolbarButton))
                    {
                        m_panel = (EPanel)((int)(m_panel + 1) % (int)EPanel.END);
                        cp.GetSolver().Target = cp.transform.position;
                    }
                    _OnGUI_IKPanel(cp);
                }
                EUtil.PopGUIEnable();

                // influence
                GUILayout.Space(5f);
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");

                //initInfos
                if (Pref.ShowInitInfos)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("m_initInfos"), true);
                }
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
    private void _OnGUI_SMR()
    {
        m_RootBone = EditorGUILayout.ObjectField(new GUIContent("Top GO", "fill the topmost GameObject of model"), m_RootBone, typeof(Transform), true) as Transform;
        GUIUtil.PushGUIEnable(m_RootBone != null);
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(60f);
            if (EUtil.Button("AutoFind", "Automatically collect all SMR & MF on this model", Color.blue))
            {
                _AutoFindRenderers();
            }
            GUILayout.Space(60f);
            GUILayout.EndHorizontal();
        }
        GUIUtil.PopGUIEnable();

        EUtil.DrawSplitter();

        //SMR
        for (int idx = 0; idx < m_SMRs.Count; ++idx)
        {
            GUILayout.BeginHorizontal();

            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_SMRs.RemoveAt(idx);
                --idx;
                continue;
            }

            Color oc = GUI.backgroundColor;
            GUI.backgroundColor = Color.green;
            m_SMRs[idx]         = EditorGUILayout.ObjectField(m_SMRs[idx], typeof(SkinnedMeshRenderer), true) as SkinnedMeshRenderer;
            GUI.backgroundColor = oc;

            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add SMR Entry", "manually add \"Skinned-Mesh Renderer\"")))
        {
            m_SMRs.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        //MF
        for (int idx = 0; idx < m_MFs.Count; ++idx)
        {
            GUILayout.BeginHorizontal();
            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_MFs.RemoveAt(idx);
                --idx;
                continue;
            }

            Color oc = GUI.backgroundColor;
            GUI.backgroundColor = Color.yellow;
            m_MFs[idx]          = EditorGUILayout.ObjectField(m_MFs[idx], typeof(MeshFilter), true) as MeshFilter;
            GUI.backgroundColor = oc;

            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add MF Entry", "manually add \"Mesh Filter\"")))
        {
            m_MFs.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        //export clips
        for (int idx = 0; idx < m_Clips.Count; ++idx)
        {
            GUILayout.BeginHorizontal();
            if (EUtil.Button("X", "delete", Color.red, GUILayout.Width(30f)))
            {
                m_Clips.RemoveAt(idx);
                --idx;
                continue;
            }
            m_Clips[idx] = EditorGUILayout.ObjectField(m_Clips[idx], typeof(AnimationClip), true) as AnimationClip;
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button(new GUIContent("Add Clip", "add another animation clip to export")))
        {
            m_Clips.Add(null);
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();

        EUtil.DrawSplitter();

        bool  bHasValidEntry = _HasValidEntry();
        Color c = (bHasValidEntry) ? Color.green : Color.red;

        EUtil.PushBackgroundColor(c);
        GUIUtil.PushGUIEnable(bHasValidEntry);
        GUILayout.BeginHorizontal();
        GUILayout.Space(60f);
        if (GUILayout.Button("Export!"))
        {
            string saveDir  = _GetSaveDirectory();
            string filePath = EditorUtility.SaveFilePanel("Select export file path", saveDir, "anim", "dae");
            if (filePath.Length > 0)
            {
                string recDir = System.IO.Path.GetDirectoryName(filePath);
                _RecordSaveDirectory(recDir);

                SkinnedMeshRenderer[] smrArr = m_SMRs.TakeWhile(x => x != null).ToArray();
                MeshFilter[]          mfArr  = m_MFs.TakeWhile(x => x != null).ToArray();
                m_Clips.RemoveAll(x => x == null);

                DaeExporter exp = new DaeExporter(smrArr, mfArr, m_RootBone);
                exp.Export(m_Clips, filePath);

                AssetDatabase.Refresh();
            }
            else
            {
                EUtil.ShowNotification("Export Cancelled...");
            }
        }
        GUILayout.Space(60f);
        GUILayout.EndHorizontal();
        GUIUtil.PopGUIEnable();
        EUtil.PopBackgroundColor();
    }
        void OnGUI()
        {
            if (m_CurAnimator == null)
            {
                GUILayout.Label("Select animator gameobject first !");
                return;
            }
            if (!EUtil.HasAnimatorController(m_CurAnimator))
            {
                GUILayout.Label("The Animator doesn't have AnimatorController set!");
                return;
            }

            var stateInfo = m_CurAnimator.GetCurrentAnimatorStateInfo(0);

            GUILayout.Label(string.Format("Cur: {0}, state: {1}", m_CurAnimator.name, EUtil.GetStateNameHash(stateInfo)));
            float nt  = stateInfo.normalizedTime;
            float len = stateInfo.length;
            float t   = nt * len;

            GUILayout.Label(string.Format("Cur time: nt:{0}, t:{1}", nt, t));

            Event e = Event.current;

            if (e.type == EventType.KeyDown)
            {
                float delta = 0;
                if (e.keyCode == KeyCode.RightArrow)
                {
                    delta = m_step;
                }
                else if (e.keyCode == KeyCode.LeftArrow)
                {
                    delta = -m_step;
                }
                else if (e.keyCode == KeyCode.Home)
                {
                    delta = -t;
                }

                if (!Mathf.Approximately(0, delta))
                {
                    m_CurAnimator.Update(delta);
                    Repaint();
                }
            }

            m_transBool.target = EditorGUILayout.ToggleLeft("Set Param", m_transBool.target);
            if (EditorGUILayout.BeginFadeGroup(m_transBool.faded))
            {
                var allParamNames = new List <string>();
                EUtil.GetAllParameterNames(allParamNames, m_CurAnimator);
                int idx = Mathf.Max(0, allParamNames.IndexOf(m_paramName));
                idx = EditorGUILayout.Popup("paramName", idx, allParamNames.ToArray());
                if (allParamNames.Count > 0)
                {
                    m_paramName = allParamNames[idx];
                }

                m_type = (PType)EditorGUILayout.EnumPopup("type", m_type);
                switch (m_type)
                {
                case PType.Bool: m_bool = EditorGUILayout.Toggle("bool", m_bool); break;

                case PType.Float: m_float = EditorGUILayout.FloatField("float", m_float); break;

                case PType.Int: m_int = EditorGUILayout.IntField("int", m_int); break;
                }
                EUtil.PushGUIEnable(!string.IsNullOrEmpty(m_paramName));
                if (GUILayout.Button("execute"))
                {
                    switch (m_type)
                    {
                    case PType.Bool: m_CurAnimator.SetBool(m_paramName, m_bool); break;

                    case PType.Float: m_CurAnimator.SetFloat(m_paramName, m_float); break;

                    case PType.Int: m_CurAnimator.SetInteger(m_paramName, m_int); break;

                    case PType.Trigger: m_CurAnimator.SetTrigger(m_paramName); break;
                    }
                }
                EUtil.PopGUIEnable();
            }
            EditorGUILayout.EndFadeGroup();

            List <string> allNames = new List <string>();

            EUtil.GetAllStateNames(allNames, m_CurAnimator);
            m_jumpToggle.target = EditorGUILayout.ToggleLeft("jump to", m_jumpToggle.target);
            if (EditorGUILayout.BeginFadeGroup(m_jumpToggle.faded))
            {
                int idx = Mathf.Max(0, allNames.IndexOf(m_stateName));
                idx = EditorGUILayout.Popup("stateName", idx, allNames.ToArray());
                if (allNames.Count > 0)
                {
                    m_stateName = allNames[idx];
                }

                m_fadeTime = Mathf.Max(0, EditorGUILayout.FloatField("fade time", m_fadeTime));
                if (GUILayout.Button("execute"))
                {
                    if (!EUtil.HasState(m_CurAnimator, m_stateName))
                    {
                        Dbg.Log("unknown stateName: {0}", m_stateName);
                    }
                    else
                    {
                        if (m_fadeTime > 0)
                        {
                            m_CurAnimator.CrossFade(m_stateName, m_fadeTime);
                        }
                        else
                        {
                            m_CurAnimator.Play(m_stateName);
                        }
                    }
                }
            }
            EditorGUILayout.EndFadeGroup();

            EUtil.DrawSplitter();
            EUtil.DrawSplitter();

            m_step = EditorGUILayout.Slider("Step", m_step, 0, 1f);

            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("<-", GUILayout.Height(40f)))
                {
                    m_CurAnimator.Update(-m_step);
                }
                GUILayout.Space(5f);
                if (GUILayout.Button("->", GUILayout.Height(40f)))
                {
                    m_CurAnimator.Update(m_step);
                }
            }
            GUILayout.EndHorizontal();

            if (EUtil.Button("Rebind", Color.red))
            {
                m_CurAnimator.Rebind();
                m_CurAnimator.Update(0);
            }
        }
        public override void OnInspectorGUI()
        {
            MaintainVolume cp = (MaintainVolume)target;

            EditorGUI.BeginChangeCheck();

            EConUtil.DrawActiveLine(cp);

            EUtil.DrawSplitter();

            EUtil.PushGUIEnable(cp.IsActiveConstraint);
            {
                // base volume
                cp.BaseVolume = EditorGUILayout.FloatField(new GUIContent("Base", "the base value of volume, the product of xyz component of scale"), cp.BaseVolume);
                cp.BaseVolume = Mathf.Max(cp.BaseVolume, 0.01f);

                //affect X/Y/Z
                m_foldoutAxis = EditorGUILayout.Foldout(m_foldoutAxis, "Axis");
                if (m_foldoutAxis)
                {
                    EAxis eAffect = cp.FreeAxis;

                    EditorGUILayout.BeginHorizontal();
                    {
                        EUtil.PushBackgroundColor(eAffect == EAxis.X ? EConUtil.kSelectedBtnColor : Color.white);
                        if (GUILayout.Button(new GUIContent("X", "X axis as main axis"), EditorStyles.toolbarButton))
                        {
                            eAffect = EAxis.X;
                        }
                        EUtil.PopBackgroundColor();

                        EUtil.PushBackgroundColor(eAffect == EAxis.Y ? EConUtil.kSelectedBtnColor : Color.white);
                        if (GUILayout.Button(new GUIContent("Y", "Y axis as main axis"), EditorStyles.toolbarButton))
                        {
                            eAffect = EAxis.Y;
                        }
                        EUtil.PopBackgroundColor();

                        EUtil.PushBackgroundColor(eAffect == EAxis.Z ? EConUtil.kSelectedBtnColor : Color.white);
                        if (GUILayout.Button(new GUIContent("Z", "Z axis as main axis"), EditorStyles.toolbarButton))
                        {
                            eAffect = EAxis.Z;
                        }
                        EUtil.PopBackgroundColor();
                    }
                    EditorGUILayout.EndHorizontal();

                    cp.FreeAxis = eAffect;

                    GUILayout.Space(5f);
                }

                // vol mul
                cp.VolMul = EditorGUILayout.FloatField(new GUIContent("Multiplier", "extra multiplier on base volume"), cp.VolMul);

                // space
                m_foldoutSpace = EditorGUILayout.Foldout(m_foldoutSpace, "Space Mapping");
                if (m_foldoutSpace)
                {
                    // owner space
                    cp.OwnerSpace = (ESpace)EditorGUILayout.EnumPopup("Owner Space", cp.OwnerSpace);
                    GUILayout.Space(5f);
                }

                // influence
                cp.Influence = EUtil.ProgressBar(cp.Influence, 0, 1f, "Influence: {0:F2}");
            }
            EUtil.PopGUIEnable();

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(cp); //so ConstraintStack.Update can be called in edit-mode
            }
        }
Example #21
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            AnimatorData mb = target as AnimatorData;

            Dbg.Assert(mb != null, "AnimatorDataEditor.OnInspectorGUI: cannot get target: {0}", target.name);

            EditorGUILayout.HelpBox("If you want to modify the takes list, do it via the Timeline editor", MessageType.Info);

            if (EUtil.Button("Open Timeline Editor", Color.green))
            {
                AMTimeline.ResetWithAnimatorData((AnimatorData)target);
            }

            string playOnStartName = (m_spPlayOnStart.objectReferenceValue != null) ? ((AMTake)m_spPlayOnStart.objectReferenceValue).name : "None";

            EditorGUILayout.LabelField("Play On Start:  " + playOnStartName);

            EUtil.DrawSplitter();

            for (int i = 0; i < m_spTakes.arraySize; ++i)
            {
                var oneTake = m_spTakes.GetArrayElementAtIndex(i);

                GUILayout.BeginHorizontal();
                {
                    if (oneTake != null && oneTake.objectReferenceValue != null)
                    {
                        AMTake takeObj = oneTake.objectReferenceValue as AMTake;
                        EditorGUILayout.LabelField(string.Format("{0}: \"{1} fr, {2} fps\"", takeObj.name, takeObj.numFrames, takeObj.frameRate));
                        if (GUILayout.Button(new GUIContent(ms_inspectTex, "inspect this take's content"), GUILayout.Height(20f), GUILayout.Width(30f)))
                        {
                            Selection.activeObject = takeObj;
                        }
                        //EUtil.PushGUIColor(EditorUtility.IsPersistent(takeObj) ? Color.yellow : Color.green);
                        //if (GUILayout.Button(new GUIContent("S", "save asset to disk"), GUILayout.Width(30f)))
                        //{
                        //    string path = null;
                        //    if (!EditorUtility.IsPersistent(takeObj))
                        //        path = EditorUtility.SaveFilePanelInProject("Save Take", takeObj.name, "asset", "Select asset path");
                        //    else
                        //        path = AssetDatabase.GetAssetPath(takeObj);

                        //    if (!string.IsNullOrEmpty(path))
                        //    {
                        //        takeObj.SaveAsset(mb, path);
                        //        EUtil.ShowNotification("Saved Take at: " + path, 3f);
                        //    }
                        //}
                        //EUtil.PopGUIColor();
                    }
                    else
                    {
                        GUILayout.Label("This slot is null reference");
                    }
                }
                GUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();
        }