コード例 #1
0
        void OnGUI()
        {
            if (m_solver == null)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();
            m_endJoint = (Transform)EditorGUILayout.ObjectField("endJoint", m_endJoint, typeof(Transform), true);
            m_boneLen  = EditorGUILayout.IntField("boneLen", m_boneLen);
            if (EditorGUI.EndChangeCheck())
            {
                if (m_endJoint == null || m_boneLen <= 0)
                {
                    return;
                }

                m_solver.SetBones(m_endJoint, m_boneLen);
                m_solver.Target = m_endJoint.position;
                EUtil.ShowNotification("Set Bones: endJoint: " + m_endJoint.name + ", bonelen: " + m_boneLen);
            }

            if (GUILayout.Button("Return To endJoint"))
            {
                m_solver.Target = m_endJoint.position;
                EUtil.RepaintSceneView();
            }

            if (GUILayout.Button("Reset all rotation"))
            {
                var joints = m_solver.GetJoints();
                foreach (var j in joints)
                {
                    j.localRotation = Quaternion.identity;
                }
            }

            if (GUILayout.Button("GO"))
            {
                m_solver.Execute();
            }
        }
コード例 #2
0
        private static void _GUI_CAT()
        {
            if (!m_hasCAT)
            {
                _URLBtn();
                return;
            }

            EditorGUI.BeginChangeCheck();

            m_IKConMarkerSize           = EditorGUILayout.FloatField("IK constraint marker size", m_IKConMarkerSize);
            m_IKAngleConstraintArcColor = EditorGUILayout.ColorField("IK angle constraint arc color", m_IKAngleConstraintArcColor);
            m_IKConeConstraintColor     = EditorGUILayout.ColorField("IK cone contraint color", m_IKConeConstraintColor);
            m_IKBoneLinkColor           = EditorGUILayout.ColorField("IK bone link color", m_IKBoneLinkColor);
            m_showInitInfos             = EditorGUILayout.Toggle("Show Init Infos in editor", m_showInitInfos);

            if (EditorGUI.EndChangeCheck())
            {
                _SavePrefs();
                EUtil.RepaintSceneView();
            }
        }
コード例 #3
0
        private void _ShortCut_EditMode(Event e)
        {
            if (e.rawType == EventType.MouseUp)
            {
                if (e.button == 1)
                {
                    m_bRightBtnIsDown = false;
                }
            }

            if (e.type == EventType.MouseDown)
            {
                if (e.button == 1)
                {
                    m_bRightBtnIsDown = true;
                }
            }

            if (e.type == EventType.KeyUp && !m_bRightBtnIsDown)
            {
                switch (e.keyCode)
                {
                case KeyCode.W:
                {
                    m_EditTool = EditTool.Move;
                    EUtil.RepaintSceneView();
                }
                break;

                case KeyCode.E:
                {
                    m_EditTool = EditTool.Rotate;
                    EUtil.RepaintSceneView();
                }
                break;
                }
            }
        }
コード例 #4
0
        public override void OnInspectorGUI()
        {
            if (targets.Length > 1)
            {
                EditorGUILayout.HelpBox("Cannot edit multiple spline together", MessageType.Info, true);
                ms_isMultiEdit = true;
                return;
            }
            else
            {
                ms_isMultiEdit = false;
            }

            CatmullRomCentripetalBehaviour behaviour = (CatmullRomCentripetalBehaviour)target;
            CatmullRomCentripetal          spline    = (CatmullRomCentripetal)behaviour.Spline;

            GUILayout.Space(5f);
            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button(new GUIContent("Add Point", "hotkey: I"), EditorStyles.toolbarButton))
                {
                    _AddPoint(spline);
                }
                if (GUILayout.Button(new GUIContent("Del Point", "hotkey: X"), EditorStyles.toolbarButton))
                {
                    _DelPoint(spline);
                }
                if (GUILayout.Button(spline.Cycle ? "Break Cycle" : "Make Cycle", EditorStyles.toolbarButton))
                {
                    _ToggleCycle(spline);
                }
            }
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5f);

            if (m_curPtIdx >= 0)
            {
                EditorGUILayout.BeginHorizontal();
                {
                    MUndo.RecordObject(this, "change current point");
                    GUILayout.Label("Current Point");
                    if (GUILayout.Button("<<"))
                    {
                        m_curPtIdx = Mathf.Max(0, m_curPtIdx - 1);
                    }

                    EditorGUI.BeginChangeCheck();
                    m_curPtIdx = EditorGUILayout.IntField(m_curPtIdx);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_curPtIdx = Mathf.Clamp(m_curPtIdx, 0, spline.PointCount);
                    }

                    GUILayout.Label(" / " + (spline.PointCount - 1));
                    if (GUILayout.Button(">>"))
                    {
                        m_curPtIdx = Mathf.Min(m_curPtIdx + 1, spline.PointCount - 1);
                    }
                }
                EditorGUILayout.EndHorizontal();

                MUndo.RecordObject(target, "modify control point");
                EUtil.PushLabelWidth(80f);
                spline[m_curPtIdx] = EUtil.DrawV3P(new GUIContent("Position"), spline[m_curPtIdx]);
                spline.SetTilt(m_curPtIdx, EditorGUILayout.FloatField("Tilt", spline.GetTilt(m_curPtIdx)));
                EUtil.PopLabelWidth();
            }

            ms_foldoutSettings = EditorGUILayout.Foldout(ms_foldoutSettings, "Settings");
            if (ms_foldoutSettings)
            {
                MUndo.RecordObject(this, "change setting");
                spline.Resolution = EditorGUILayout.IntField("Point/Seg", spline.Resolution);
                spline.TwistMtd   = (ETwistMethod)EditorGUILayout.EnumPopup(new GUIContent("Twist Method", "Decide how to calculate the base-up direction before applying tilt"), spline.TwistMtd);
                ms_drawArrow      = EditorGUILayout.Toggle("Draw Arrow", ms_drawArrow);
                ms_drawUp         = EditorGUILayout.Toggle("Draw Up", ms_drawUp);
                ms_arrowLineLen   = EditorGUILayout.FloatField("Arrow LineLen", ms_arrowLineLen);

                ms_drawPts = EditorGUILayout.Toggle("Draw points", ms_drawPts);
                ms_ptSize  = EditorGUILayout.FloatField("Point size", ms_ptSize);

                ms_lookAtDist = EditorGUILayout.FloatField(new GUIContent("LookAt dist", "the distance from camera to target point when camera in follow mode"), ms_lookAtDist);
            }

            ms_foldoutTSlider = EditorGUILayout.Foldout(ms_foldoutTSlider, "T slider");
            if (ms_foldoutTSlider)
            {
                EditorGUI.BeginChangeCheck();
                EUtil.PushLabelWidth(20f);
                m_tSlider = EditorGUILayout.Slider("T", m_tSlider, 0, 1f);
                EUtil.PopLabelWidth();
                if (EditorGUI.EndChangeCheck())
                {
                    //Transform tr = behaviour.transform;
                    EUtil.SceneViewLookAt(
                        behaviour.GetTransformedPosition(m_tSlider),
                        Quaternion.LookRotation(behaviour.GetTransformedTangent(m_tSlider), behaviour.GetTransformedUp(m_tSlider)),
                        ms_lookAtDist);
                }
            }

            if (GUI.changed)
            {
                EUtil.RepaintSceneView();
            }
        }
コード例 #5
0
        public override void OnInspectorGUI()
        {
            AngleConstraintMB mb = (AngleConstraintMB)target;

            mb.enabled = EditorGUILayout.Toggle("Enabled", mb.enabled);

            EditorGUI.BeginChangeCheck();
            mb.nextJoint = EditorGUILayout.ObjectField("nextJoint", mb.nextJoint, typeof(Transform), true) as Transform;
            if (EditorGUI.EndChangeCheck())
            {
                EUtil.SetDirty(mb);
                EUtil.RepaintSceneView();
            }

            if (mb.nextJoint == null)
            {
                EditorGUILayout.LabelField("Set the nextJoint first...");
                return;
            }
            else
            {
                EUtil.PushGUIEnable(mb.enabled);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(30f);
                    if (EUtil.Button("ReInit", "decide all the parameters with default method", Color.green))
                    {
                        Undo.RecordObject(mb, "ReInit");
                        mb.AutoSetParameters();
                        EUtil.SetDirty(mb);
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(30f);
                }
                GUILayout.EndHorizontal();

                // min/max limit
                float min = mb.minLimit;
                float max = mb.maxLimit;
                EditorGUI.BeginChangeCheck();
                EUtil.DrawMinMaxSlider("Angle Limits", ref min, ref max, -180f, 180f);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Angle limits");
                    mb.minLimit = min;
                    mb.maxLimit = max;
                    EUtil.SetDirty(mb);
                    EUtil.RepaintSceneView();
                }

                EditorGUI.BeginChangeCheck();
                Vector3 newRotAxis  = EUtil.DrawV3P(new GUIContent("Rotation Axis", "in parent space, in world space if no parent joint"), mb.rotAxis);
                Vector3 newPrimAxis = EUtil.DrawV3P(new GUIContent("Primary Axis", "in parent space, in world space if no parent joint"), mb.primAxis);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Constraint parameters");
                    mb.rotAxis  = newRotAxis;
                    mb.primAxis = newPrimAxis;
                    mb.CalcInitData(); //!! recalc the startLocalRot
                    EUtil.SetDirty(mb);
                    EUtil.RepaintSceneView();
                }

                ms_showDisplaySetting = EditorGUILayout.Foldout(ms_showDisplaySetting, "Display Settings:");
                if (ms_showDisplaySetting)
                {
                    EditorGUI.BeginChangeCheck();
                    ms_markerSize = EditorGUILayout.FloatField("ArcSize", ms_markerSize);
                    ms_arcColor   = EditorGUILayout.ColorField("ArcColor", ms_arcColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EUtil.RepaintSceneView();
                    }
                }

                EUtil.PopGUIEnable();
            }
        }
コード例 #6
0
        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
            }
        }
コード例 #7
0
        private void _OnGUI_IKPanel_Debug(CCDSolverMB cp)
        {
            // line 1
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button(CONT_ZeroAll, EditorStyles.toolbarButton))
                { //zero-out all rotation
                    var solver = cp.GetSolver();
                    var joints = solver.GetJoints();
                    Undo.RecordObjects(joints, "Zero-out IK joints");
                    foreach (var j in joints)
                    {
                        j.localRotation = Quaternion.identity;
                    }
                }
                if (GUILayout.Button(CONT_Reset, EditorStyles.toolbarButton))
                { // return target to endJoint
                    var solver = cp.GetSolver();
                    solver.Target = cp.transform.position;
                    EUtil.RepaintSceneView();
                }
            }
            GUILayout.EndHorizontal();

            // line 2
            GUILayout.BeginHorizontal();
            {
                bool   bStartedStep = m_dbgStepIE != null;
                Color  c            = bStartedStep ? Color.red : Color.green;
                string s            = bStartedStep ? "StopStep" : "StartStep";
                if (EUtil.Button(s, c))
                {
                    var solver = cp.GetSolver();
                    if (!bStartedStep)
                    {
                        m_dbgStepIE = solver.DBGExecute();
                    }
                    else
                    {
                        solver.dbg_interrupt = true;
                        m_dbgStepIE.MoveNext();
                        m_dbgStepIE  = null;
                        bStartedStep = false;
                    }
                }

                EUtil.PushGUIEnable(bStartedStep);
                {
                    if (GUILayout.Button(CONT_Step))
                    {
                        bool bNotOver = m_dbgStepIE.MoveNext();
                        if (!bNotOver)
                        {
                            m_dbgStepIE  = null;
                            bStartedStep = false;
                        }
                    }
                    if (GUILayout.Button(CONT_Continue))
                    {
                        while (m_dbgStepIE.MoveNext() == true)
                        {
                            ;
                        }
                        m_dbgStepIE  = null;
                        bStartedStep = false;
                    }
                }
                EUtil.PopGUIEnable();
            }
            GUILayout.EndHorizontal();
        }
コード例 #8
0
        public override void OnInspectorGUI()
        {
            ConeConstraintMB mb = (ConeConstraintMB)target;

            mb.enabled = EditorGUILayout.Toggle("Enabled", mb.enabled);

            EditorGUI.BeginChangeCheck();
            mb.nextJoint = EditorGUILayout.ObjectField("nextJoint", mb.nextJoint, typeof(Transform), true) as Transform;
            if (EditorGUI.EndChangeCheck())
            {
                EUtil.RepaintSceneView();
            }

            if (mb.nextJoint == null)
            {
                EditorGUILayout.LabelField("Set the nextJoint first...");
                return;
            }
            else
            {
                EUtil.PushGUIEnable(mb.enabled);

                EditorGUILayout.BeginHorizontal();
                {
                    GUILayout.Space(30f);
                    if (EUtil.Button("ReInit", "decide all the parameters with default method", Color.green))
                    {
                        Undo.RecordObject(mb, "AutoInit");
                        mb._AutoSetParameters();
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(30f);
                }
                EditorGUILayout.EndHorizontal();

                // angle limit
                EditorGUI.BeginChangeCheck();
                float newAngleLimit = EditorGUILayout.Slider(CONT_AngleLimit, mb.angleLimit, 0, 180f);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify Angle Limit");
                    mb.angleLimit = newAngleLimit;
                    EUtil.RepaintSceneView();
                }

                // ref-Axis
                EditorGUI.BeginChangeCheck();
                Vector3 newRefAxis = EUtil.DrawV3P(CONT_RefAxis, mb.refAxis);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(mb, "Modify ref axis");
                    mb.refAxis = newRefAxis;
                    mb.CalcInitData(); //!! recalc the startTwistRot
                    EUtil.RepaintSceneView();
                }

                mb.limitTwist = EditorGUILayout.Toggle(CONT_LimitTwist, mb.limitTwist);
                if (mb.limitTwist)
                {
                    float min = mb.minTwistLimit;
                    float max = mb.maxTwistLimit;
                    EditorGUI.BeginChangeCheck();
                    EUtil.DrawMinMaxSlider("Twist Limits", ref min, ref max, -180f, 180f);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(mb, "Modify twist limits");
                        mb.minTwistLimit = min;
                        mb.maxTwistLimit = max;
                        EUtil.RepaintSceneView();
                    }

                    EditorGUILayout.LabelField("Current twist: " + mb.CalcTwist());
                }

                ms_showDisplaySetting = EditorGUILayout.Foldout(ms_showDisplaySetting, "Display Settings:");
                if (ms_showDisplaySetting)
                {
                    EditorGUI.BeginChangeCheck();
                    ms_markerSize  = EditorGUILayout.FloatField("Marker size", ms_markerSize);
                    ms_markerColor = EditorGUILayout.ColorField("Marker color", ms_markerColor);
                    if (EditorGUI.EndChangeCheck())
                    {
                        EUtil.RepaintSceneView();
                    }
                }

                EUtil.PopGUIEnable();
            }
        }
コード例 #9
0
 private void _SetTempPivotToZero()
 {
     m_PivotPos = Vector3.zero;
     m_PivotRot = Quaternion.identity;
     EUtil.RepaintSceneView();
 }
コード例 #10
0
        private void _OnGUI_Started()
        {
            _OnGUI_Started_Toolbar();

            switch (m_EditMode)
            {
            case EditMode.Fixer:
            {
                GUILayout.Space(3f);

                GUILayout.BeginHorizontal(GUILayout.Height(40f));
                {
                    GUILayout.Space(10f);
                    if (GUILayout.Button("Reset", GUILayout.ExpandHeight(true)))
                    {
                        _SetTempPivotToZero();         // call repaint
                    }
                    GUILayout.Space(3f);
                    if (GUILayout.Button("Center", GUILayout.ExpandHeight(true)))
                    {
                        m_PivotPos = _GetCenterPoint();
                        EUtil.RepaintSceneView();
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10f);
                    if (EUtil.Button("Confirm", "Apply the pivot change to mesh", Color.green, GUILayout.ExpandHeight(true)))
                    {
                        MeshPivotFixer.Apply(m_InEditMF, m_PivotPos, m_PivotRot, m_bInplace);
                        _SetTempPivotToZero();
                        Dbg.Log("Modify Pivot: parameter: {0}, {1}", m_PivotPos, m_PivotRot);
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                m_bInplace = EditorGUILayout.ToggleLeft("Try Edit In-place (no Undo!)", m_bInplace);

                GUILayout.Space(10f);
            }
            break;

            case EditMode.Saver:
            {
                GUILayout.Space(10f);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10f);
                    if (GUILayout.Button("Save Mesh", GUILayout.ExpandHeight(true)))
                    {
                        EUtil.SaveMeshToAssetDatabase(m_InEditMF.sharedMesh);
                    }
                    GUILayout.Space(10f);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(10f);
            }
            break;
            }
        }