Beispiel #1
0
        private void _AddPoint(CatmullRomCentripetal spline)
        {
            MUndo.RecordObject(target, "add point");
            MUndo.RecordObject(this, "add ppoint");

            if (m_curPtIdx < 0)
            {
                m_curPtIdx = spline.PointCount - 1;
            }

            if (m_curPtIdx != spline.PointCount - 1)
            {
                Vector3 p0     = spline[m_curPtIdx];
                Vector3 p1     = spline[m_curPtIdx + 1];
                Vector3 newPos = (p0 + p1) * 0.5f;
                spline.InsertPointAfter(m_curPtIdx, newPos);
            }
            else
            {
                float   unitLen = spline.CurveLength / (spline.PointCount - 1);
                Vector3 dir     = spline.Tangent(1f);
                spline.InsertPointAfter(m_curPtIdx, spline[m_curPtIdx] + dir * unitLen);
            }

            m_curPtIdx++;
        }
Beispiel #2
0
        private void DrawHandles(CatmullRomCentripetal spline, Transform tr)
        {
            if (m_curPtIdx >= 0 && m_curPtIdx < spline.PointCount)
            {
                Tools.current = Tool.None;
            }
            else
            {
                m_curPtIdx = -1;
                return;
            }

            Event e = Event.current;

            if (e.keyCode == KeyCode.Escape && e.rawType == EventType.KeyDown)
            {
                m_curPtIdx = -1;
                return;
            }

            Vector3 pt = tr.TransformPoint(spline[m_curPtIdx]);

            pt = Handles.PositionHandle(pt, Quaternion.identity);
            if (GUI.changed)
            {
                MUndo.RecordObject(target, "move point");
                spline[m_curPtIdx] = tr.InverseTransformPoint(pt);
            }
        }
        private void _AddPoint(CatmullRomUniform spline)
        {
            MUndo.RecordObject(target, "add point");
            MUndo.RecordObject(this, "add point");

            if (m_curPtIdx < 0)
            {
                m_curPtIdx = spline.PointCount - 1;
            }

            if (m_curPtIdx != spline.PointCount - 1)
            {
                float   v      = (float)m_curPtIdx + 0.5f;
                Vector3 newPos = spline.Interp(v / (spline.PointCount - 1));
                spline.InsertPointAfter(m_curPtIdx, newPos);
            }
            else
            {
                float   unitLen = spline.CurveLength / (spline.PointCount - 1);
                Vector3 dir     = spline.Tangent(1f);
                spline.InsertPointAfter(m_curPtIdx, spline[m_curPtIdx] + dir * unitLen);
            }

            m_curPtIdx++;
        }
Beispiel #4
0
        private void _DelPoint(CatmullRomCentripetal spline)
        {
            if (spline.PointCount <= 2)
            {
                EUtil.ShowNotification("The spline needs at least 2 points");
                return;
            }
            if (spline.Cycle && spline.PointCount <= 4)
            {
                EUtil.ShowNotification("Cannot delete any points to maintain cycle");
                return;
            }
            if (m_curPtIdx < 0)
            {
                return;
            }

            MUndo.RecordObject(target, "del point");
            MUndo.RecordObject(this, "del point");
            spline.RemovePoint(m_curPtIdx);
            m_curPtIdx = Mathf.Min(spline.PointCount - 1, m_curPtIdx);
        }
        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();
        }
Beispiel #6
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();
            }
        }