public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfDirtyOrScript();
        if (Event.current.type == EventType.Layout)
        {
            mValid = Target.IsValidSegment;
        }

        if (mValid && (Target.Spline.Closed || !Target.IsFirstSegment))
        {
            EditorGUILayout.PropertyField(tSmoothTangent, new GUIContent("Smooth End Tangent", "Smooth end tangent?"));
        }

        if (Target.Spline.Interpolation == CurvyInterpolation.Bezier)
        {
            EditorGUILayout.LabelField("Handles", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(tFreeHandles, new GUIContent("Free Move", "Move Handles individually?"));
            EditorGUILayout.Slider(tHandleScale, 0, 10, new GUIContent("Scale", "Handle Scaling"));

            Vector3 v = tHandleIn.vector3Value;
            EditorGUILayout.PropertyField(tHandleIn);
            if (v != tHandleIn.vector3Value && !tFreeHandles.boolValue)
            {
                tHandleOut.vector3Value = -tHandleIn.vector3Value;
            }
            v = tHandleIn.vector3Value;
            EditorGUILayout.PropertyField(tHandleOut);
            if (v != tHandleOut.vector3Value && !tFreeHandles.boolValue)
            {
                tHandleIn.vector3Value = -tHandleOut.vector3Value;
            }

            EditorGUILayout.LabelField("Smooth Handles", EditorStyles.boldLabel);

            SmoothingOffset = EditorGUILayout.Slider(new GUIContent("Offset", "Smoothing Offset"), SmoothingOffset, 0.1f, 1f);
            if (GUILayout.Button(new GUIContent("Smooth", "Set Handles by Catmul-Rom")))
            {
                Undo.RegisterUndo(targets, "Smooth Bezier Handles");
                foreach (CurvySplineSegment tgt in targets)
                {
                    CurvyUtility.InterpolateBezierHandles(CurvyInterpolation.CatmulRom, SmoothingOffset, tgt.FreeHandles, tgt);
                }
                Target.Spline.RefreshImmediately(true, true, false);
                SceneView.RepaintAll();
            }
        }


        if (mValid && Target.Spline.Interpolation == CurvyInterpolation.TCB)
        {
            EditorGUILayout.PropertyField(tSyncStartEnd, new GUIContent("Synchronize TCB", "Synchronize Start and End Values"));
            EditorGUILayout.PropertyField(tOT, new GUIContent("Local Tension", "Override Spline Tension?"));
            if (tOT.boolValue)
            {
                EditorGUILayout.PropertyField(tT0, Target.SynchronizeTCB ? new GUIContent("Tension", "Tension") : new GUIContent("Start Tension", "Start Tension"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tT1, new GUIContent("End Tension", "End Tension"));
                }
                else
                {
                    tT1.floatValue = tT0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOC, new GUIContent("Local Continuity", "Override Spline Continuity?"));
            if (tOC.boolValue)
            {
                EditorGUILayout.PropertyField(tC0, Target.SynchronizeTCB ? new GUIContent("Continuity", "Continuity") : new GUIContent("Start Continuity", "Start Continuity"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tC1, new GUIContent("End Continuity", "End Continuity"));
                }
                else
                {
                    tC1.floatValue = tC0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOB, new GUIContent("Local Bias", "Override Spline Bias?"));
            if (tOB.boolValue)
            {
                EditorGUILayout.PropertyField(tB0, Target.SynchronizeTCB ? new GUIContent("Bias", "Bias") : new GUIContent("Start Bias", "Start Bias"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tB1, new GUIContent("End Bias", "End Bias"));
                }
                else
                {
                    tB1.floatValue = tB0.floatValue;
                }
            }

            if (tOT.boolValue || tOC.boolValue || tOB.boolValue)
            {
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Set Catmul"))
                {
                    tT0.floatValue = 0; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Cubic"))
                {
                    tT0.floatValue = -1; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = -1; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Linear"))
                {
                    tT0.floatValue = 0; tC0.floatValue = -1; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = -1; tB1.floatValue = 0;
                }
                EditorGUILayout.EndHorizontal();
            }
        }


        if (Target.UserValues != null && Target.UserValues.Length > 0)
        {
            EditorGUILayout.LabelField("User Values", EditorStyles.boldLabel);
            ArrayGUI(serializedObject, "UserValues", false);
        }


        if ((Target.Connection != null || Target.ConnectedBy.Count > 0))
        {
            GUILayout.Label("Connections", EditorStyles.boldLabel);
            ConnectionGUI();
        }

        GUILayout.Label("Tools", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexConstraints, "Constraints Tools"), GUILayout.ExpandWidth(false)))
        {
            CurvyConstraintsWin.Create();
        }
        GUI.enabled = CurvyEditorUtility.IsSingleSelection && Target.ControlPointIndex > 0;
        if (GUILayout.Button(new GUIContent(mTexSetFirstCP, "Set as first Control Point"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Set First Control Point");
            CurvyUtility.setFirstCP(Target);
        }
        GUI.enabled = CurvyEditorUtility.IsSingleSelection && Target.IsValidSegment && !Target.IsFirstSegment;
        if (GUILayout.Button(new GUIContent(mTexSplit, "Split Spline"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Split Spline");
            CurvyUtility.SplitSpline(Target);
        }
        GUI.enabled = CurvyEditorUtility.IsJoinSelection;
        if (GUILayout.Button(new GUIContent(mTexJoin, CurvyEditorUtility.JoinSelectionInfo), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Join Spline");
            var srcSeg = CurvyEditorUtility.JoinSource;
            var dstSeg = CurvyEditorUtility.JoinTarget;
            CurvyUtility.JoinSpline(srcSeg, dstSeg);
            Selection.activeTransform = dstSeg.Transform;
            SceneView.RepaintAll();
        }

        GUI.enabled = CurvyEditorUtility.IsConnectSelection;
        if (GUILayout.Button(new GUIContent(mTexConnection, CurvyEditorUtility.ConnectSelectionInfo), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Connect");
            var srcSeg = CurvyEditorUtility.ConnectionSource;
            var dstSeg = CurvyEditorUtility.ConnectionTarget;
            srcSeg.ConnectTo(dstSeg);
            srcSeg.SyncConnections();
            srcSeg.Spline.RefreshImmediately();
            dstSeg.Spline.RefreshImmediately();
            Selection.activeTransform = dstSeg.Transform;
        }

        GUI.enabled = true;

        GUILayout.EndHorizontal();

        if ((serializedObject.targetObject && serializedObject.ApplyModifiedProperties()))
        {
            Target.Spline.Refresh(true, true, false);
            SceneView.RepaintAll();
        }

        EditorGUILayout.LabelField("Segment Info", EditorStyles.boldLabel);
        if (mValid)
        {
            EditorGUILayout.LabelField("Distance: " + Target.Distance);
            EditorGUILayout.LabelField("Length: " + Target.Length);
        }
        EditorGUILayout.LabelField("Spline Length: " + Target.Spline.Length);
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        if (Event.current.type == EventType.Layout)
        {
            mValid = Target.IsValidSegment;
        }

        if (mValid && (Target.Spline.Closed || !Target.IsFirstSegment))
        {
            EditorGUILayout.PropertyField(tSmoothTangent, new GUIContent("Smooth End Tangent", "Smooth end tangent?"));
        }


        if (mValid && Target.Spline.Interpolation == CurvyInterpolation.TCB)
        {
            EditorGUILayout.PropertyField(tSyncStartEnd, new GUIContent("Synchronize TCB", "Synchronize Start and End Values"));
            EditorGUILayout.PropertyField(tOT, new GUIContent("Local Tension", "Override Spline Tension?"));
            if (tOT.boolValue)
            {
                EditorGUILayout.PropertyField(tT0, Target.SynchronizeTCB ? new GUIContent("Tension", "Tension") : new GUIContent("Start Tension", "Start Tension"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tT1, new GUIContent("End Tension", "End Tension"));
                }
                else
                {
                    tT1.floatValue = tT0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOC, new GUIContent("Local Continuity", "Override Spline Continuity?"));
            if (tOC.boolValue)
            {
                EditorGUILayout.PropertyField(tC0, Target.SynchronizeTCB ? new GUIContent("Continuity", "Continuity") : new GUIContent("Start Continuity", "Start Continuity"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tC1, new GUIContent("End Continuity", "End Continuity"));
                }
                else
                {
                    tC1.floatValue = tC0.floatValue;
                }
            }
            EditorGUILayout.PropertyField(tOB, new GUIContent("Local Bias", "Override Spline Bias?"));
            if (tOB.boolValue)
            {
                EditorGUILayout.PropertyField(tB0, Target.SynchronizeTCB ? new GUIContent("Bias", "Bias") : new GUIContent("Start Bias", "Start Bias"));
                if (!Target.SynchronizeTCB)
                {
                    EditorGUILayout.PropertyField(tB1, new GUIContent("End Bias", "End Bias"));
                }
                else
                {
                    tB1.floatValue = tB0.floatValue;
                }
            }

            if (tOT.boolValue || tOC.boolValue || tOB.boolValue)
            {
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Set Catmul"))
                {
                    tT0.floatValue = 0; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Cubic"))
                {
                    tT0.floatValue = -1; tC0.floatValue = 0; tB0.floatValue = 0;
                    tT1.floatValue = -1; tC1.floatValue = 0; tB1.floatValue = 0;
                }
                if (GUILayout.Button("Set Linear"))
                {
                    tT0.floatValue = 0; tC0.floatValue = -1; tB0.floatValue = 0;
                    tT1.floatValue = 0; tC1.floatValue = -1; tB1.floatValue = 0;
                }
                EditorGUILayout.EndHorizontal();
            }
        }


        if (Target.UserValues != null && Target.UserValues.Length > 0)
        {
            EditorGUILayout.LabelField("User Values", EditorStyles.boldLabel);
            ArrayGUI(serializedObject, "UserValues", false);
        }

        GUILayout.Label("Tools", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexConstraints, "Constraints Tools"), GUILayout.ExpandWidth(false)))
        {
            CurvyConstraintsWin.Create();
        }
        GUI.enabled = Target.ControlPointIndex > 0;
        if (GUILayout.Button(new GUIContent(mTexSetFirstCP, "Set as first Control Point"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Set First Control Point");
            CurvyUtility.setFirstCP(Target);
        }
        GUI.enabled = true;

        GUILayout.EndHorizontal();

        if (serializedObject.targetObject && serializedObject.ApplyModifiedProperties())
        {
            Target.Spline.Refresh(true, true, false);
            SceneView.RepaintAll();
        }

        if (mValid)
        {
            EditorGUILayout.LabelField("Segment Info", EditorStyles.boldLabel);
            EditorGUILayout.LabelField("Distance: " + Target.Distance);
            EditorGUILayout.LabelField("Length: " + Target.Length);
            EditorGUILayout.LabelField("Spline Length: " + Target.Spline.Length);
        }
    }