public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        Safety();

        var newKnots = new List <Vector3>(targetPath.LocalBezier.Knots);

        #region Path Inspector

        settings.PathFoldout = EditorGUILayout.Foldout(settings.PathFoldout, "Path");
        if (settings.PathFoldout)
        {
            // EditorGUI.indentLevel++;

            if (newKnots.Count <= 0)
            {
                if (GUILayout.Button("+"))
                {
                    newKnots.Add(Vector3.right);
                    goto UndoHistory;
                }
            }

            for (int i = 0; i < newKnots.Count; i++)
            {
                newKnots[i] =
                    EditorGUILayout.Vector3Field(i.ToString(), newKnots[i]);

                EditorGUILayout.BeginHorizontal(EditorStyles.inspectorDefaultMargins);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("-", GUILayout.Width(25f)))
                {
                    newKnots.RemoveAt(i);
                    goto UndoHistory;
                }

                if (GUILayout.Button("+", GUILayout.Width(25f)))
                {
                    Vector3 newKnot;
                    var     currentKnot = newKnots[i];

                    if (i == newKnots.Count - 1) // last knot
                    {
                        if (newKnots.Count == 1) // this is the only knot
                        {
                            newKnot = newKnots[0] + Vector3.right;
                        }
                        else
                        {
                            var previousKnot = newKnots[i - 1];
                            newKnot = currentKnot + (currentKnot - previousKnot);
                        }
                    }
                    else
                    {
                        var nextKnot = newKnots[i + 1];
                        newKnot = Vector3.Lerp(currentKnot, nextKnot, 0.5f);
                    }

                    newKnots.Insert(i + 1, newKnot);
                    goto UndoHistory;
                }
                EditorGUILayout.EndHorizontal();
            }

            //EditorGUI.indentLevel--;
        }

        #endregion Path Inspector

        #region Tool Settings Inspector

        PathEditorUtility.Inspector(settings, 1);

        #endregion Tool Settings Inspector

        #region Advanced

        settings.AdvancedFoldout = EditorGUILayout.Foldout(settings.AdvancedFoldout, "Advanced");
        if (settings.AdvancedFoldout)
        {
            //~ LocalSpaceTransform field
            targetPath.LocalSpaceTransform =
                (Transform)EditorGUILayout.ObjectField(
                    "Local Space Transform",
                    targetPath.LocalSpaceTransform,
                    typeof(Transform),
                    allowSceneObjects: true
                    );
        }

        #endregion Advanced

        #region Undo

UndoHistory:

        if (!targetPath.LocalBezier.Knots.SequenceEqual(newKnots) || targetPath.LocalBezier.Knots.Count != newKnots.Count)
        {
            Undo.RecordObject(target, "Edit Dynamic Bezier");
            targetPath.LocalBezier.Knots = newKnots;
            EditorUtility.SetDirty(target);
        }

        SceneView.RepaintAll();

        #endregion Undo
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        Safety();

        var newStartPosition = cubicBezierPath.LocalBezier.StartPosition;
        var newStartTangent  = cubicBezierPath.LocalBezier.StartTangent;
        var newEndPosition   = cubicBezierPath.LocalBezier.EndPosition;
        var newEndTangent    = cubicBezierPath.LocalBezier.EndTangent;

        #region Path Inspector

        settings.PathFoldout =
            EditorGUILayout.Foldout(settings.PathFoldout, "Path");
        if (settings.PathFoldout)
        {
            EditorGUI.indentLevel++;

            //~ Knots
            //cubicBezierPath.LocalBezier.StartPosition = EditorGUILayout.Vector3Field("Start Position", cubicBezierPath.LocalBezier.StartPosition);
            //cubicBezierPath.LocalBezier.StartTangent = EditorGUILayout.Vector3Field("Start Tangent", cubicBezierPath.LocalBezier.StartTangent);
            //cubicBezierPath.LocalBezier.EndPosition = EditorGUILayout.Vector3Field("End Position", cubicBezierPath.LocalBezier.EndPosition);
            //cubicBezierPath.LocalBezier.EndTangent = EditorGUILayout.Vector3Field("End Tangent", cubicBezierPath.LocalBezier.EndTangent);

            newStartPosition = EditorGUILayout.Vector3Field("Start Position", cubicBezierPath.LocalBezier.StartPosition);
            newStartTangent  = EditorGUILayout.Vector3Field("Start Tangent", cubicBezierPath.LocalBezier.StartTangent);
            newEndPosition   = EditorGUILayout.Vector3Field("End Position", cubicBezierPath.LocalBezier.EndPosition);
            newEndTangent    = EditorGUILayout.Vector3Field("End Tangent", cubicBezierPath.LocalBezier.EndTangent);

            EditorGUI.indentLevel--;
        }

        #endregion Path Inspector

        #region Tool Settings Inspector

        PathEditorUtility.Inspector(settings, 1);

        #endregion Tool Settings Inspector

        #region Advanced

        settings.AdvancedFoldout = EditorGUILayout.Foldout(settings.AdvancedFoldout, "Advanced");
        if (settings.AdvancedFoldout)
        {
            //~ LocalSpaceTransform field
            cubicBezierPath.LocalSpaceTransform =
                (Transform)EditorGUILayout.ObjectField(
                    "Local Space Transform",
                    cubicBezierPath.LocalSpaceTransform,
                    typeof(Transform),
                    allowSceneObjects: true
                    );
        }

        #endregion Advanced

        #region Undo

        if (newStartPosition != cubicBezierPath.LocalBezier.StartPosition ||
            newStartTangent != cubicBezierPath.LocalBezier.StartTangent ||
            newEndPosition != cubicBezierPath.LocalBezier.EndPosition ||
            newEndTangent != cubicBezierPath.LocalBezier.EndTangent)
        {
            Undo.RecordObject(target, "Edit Cubic Bezier");
            cubicBezierPath.LocalBezier.StartPosition = newStartPosition;
            cubicBezierPath.LocalBezier.StartTangent  = newStartTangent;
            cubicBezierPath.LocalBezier.EndPosition   = newEndPosition;
            cubicBezierPath.LocalBezier.EndTangent    = newEndTangent;
            EditorUtility.SetDirty(target);
        }

        #endregion Undo

        SceneView.RepaintAll();
    }
Ejemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        Safety();

        var newCenter   = circlePath.LocalCircle.Center;
        var newRadius   = circlePath.LocalCircle.Radius;
        var newMaxAngle = circlePath.MaxAngle;

        #region Path Inspector

        settings.PathFoldout
            = EditorGUILayout.Foldout(settings.PathFoldout, "Path");
        if (settings.PathFoldout)
        {
            EditorGUI.indentLevel++;

            //~ Fields
            newCenter   = EditorGUILayout.Vector3Field("Local Center", circlePath.LocalCircle.Center);
            newRadius   = EditorGUILayout.FloatField("Radius", circlePath.LocalCircle.Radius);
            newMaxAngle = EditorGUILayout.FloatField("Max Angle (Degrees)", circlePath.MaxAngle * Mathf.Rad2Deg) * Mathf.Deg2Rad;

            EditorGUI.indentLevel--;
        }

        #endregion Path Inspector

        #region Tool Settings Inspector

        PathEditorUtility.Inspector(settings);

        #endregion Tool Settings Inspector

        #region Advanced

        settings.AdvancedFoldout = EditorGUILayout.Foldout(settings.AdvancedFoldout, "Advanced");
        if (settings.AdvancedFoldout)
        {
            //~ LocalSpaceTransform field
            circlePath.LocalSpaceTransform
                = (Transform)EditorGUILayout.ObjectField(
                      "Local Space Transform",
                      circlePath.LocalSpaceTransform,
                      typeof(Transform),
                      allowSceneObjects: true
                      );
        }

        #endregion Advanced

        #region Undo

        if (newCenter != circlePath.LocalCircle.Center ||
            newRadius != circlePath.LocalCircle.Radius ||
            newMaxAngle != circlePath.MaxAngle)
        {
            Undo.RecordObject(target, "Edit Circle");
            circlePath.LocalCircle.Center = newCenter;
            circlePath.LocalCircle.Radius = newRadius;
            circlePath.MaxAngle           = newMaxAngle;
            EditorUtility.SetDirty(target);
        }

        #endregion Undo

        SceneView.RepaintAll();
    }