示例#1
0
 /// <summary>
 /// Grows/Shrinks a spline or a spline group
 /// </summary>
 /// <param name="spline">the spline or group</param>
 /// <param name="center">the center of the effect</param>
 /// <param name="growByPercent">the percentage to grow/shrink</param>
 internal static void Grow(CurvySplineBase spline, UnityEngine.Vector3 center, float growByPercent)
 {
     if (spline is CurvySplineGroup)
     {
         CurvySplineGroup grp = (CurvySplineGroup)spline;
         foreach (CurvySpline spl in grp.Splines)
         {
             Grow(spl, center, growByPercent);
         }
     }
     else
     {
         CurvySpline spl = (CurvySpline)spline;
         foreach (CurvySplineSegment cp in spl.ControlPoints)
         {
             UnityEngine.Vector3 dir = center - cp.Position;
             float dist = dir.magnitude;
             cp.Position = center + dir.normalized * dist * growByPercent;
         }
     }
 }
示例#2
0
 void OnPostRender()
 {
     if (Splines.Length == 0)
     {
         return;
     }
     for (int s = 0; s < Splines.Length; s++)
     {
         Color col = (s < Colors.Length) ? Colors[s] : Color.green;
         if (Splines[s] is CurvySpline)
         {
             RenderSpline(Splines[s], col);
         }
         else if (Splines[s] is CurvySplineGroup)
         {
             CurvySplineGroup group = Splines[s] as CurvySplineGroup;
             foreach (var spl in group.Splines)
             {
                 RenderSpline(spl, col);
             }
         }
     }
 }
示例#3
0
        static void CreateCurvySplineGroup()
        {
            CurvySplineGroup grp = CurvySplineGroup.Create();

            Selection.activeObject = grp;
        }
示例#4
0
 public override void Action()
 {
     Selection.activeGameObject = CurvySplineGroup.Create(Toolbar.SelectedSplines.ToArray()).gameObject;
     Undo.RegisterCreatedObjectUndo(Selection.activeGameObject, "Create Spline Group");
 }
    public override void OnInspectorGUI()
    {
        EditorGUILayout.PropertyField(tInterpolation, new GUIContent("Interpolation", "Interpolation Method"));
        EditorGUILayout.PropertyField(tClosed, new GUIContent("Close Spline", "Close spline?"));
        GUI.enabled = !tClosed.boolValue && tInterpolation.enumNames[tInterpolation.enumValueIndex] != "Linear" && tInterpolation.enumNames[tInterpolation.enumValueIndex] != "Bezier";
        EditorGUILayout.PropertyField(tAutoEndTangents, new GUIContent("Auto End Tangents", "Handle End Control Points automatically?"));
        GUI.enabled = true;
        EditorGUILayout.PropertyField(tGranularity, new GUIContent("Granularity", "Approximation resolution"));
        tGranularity.intValue = UnityEngine.Mathf.Max(1, tGranularity.intValue);
        EditorGUILayout.LabelField("Orientation", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tOrientation, new GUIContent("Orientation", "How the Up-Vector should be calculated"));
        GUI.enabled = Target.Interpolation != CurvyInterpolation.Bezier;
        EditorGUILayout.PropertyField(tSetCPRotation, new GUIContent("Set CP Rotation", "Rotate CP to match calculated Up-UnityEngine.Vector3"));
        GUI.enabled = true;
        if (tOrientation.enumNames[tOrientation.enumValueIndex] == "Tangent")
        {
            EditorGUILayout.PropertyField(tInitialUp, new GUIContent("Initial Up-Vector", "How the first Up-Vector should be determined"));
            EditorGUILayout.PropertyField(tSwirl, new GUIContent("Swirl", "Orientation swirl mode"));
            if (tSwirl.enumNames[tSwirl.enumValueIndex] != "None")
            {
                EditorGUILayout.PropertyField(tSwirlTurns, new GUIContent("Turns", "Swirl turns"));
            }
        }
        EditorGUILayout.LabelField("Updates", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tAutoRefresh, new GUIContent("Auto Refresh", "Refresh when Control Point position change?"));
        EditorGUILayout.PropertyField(tAutoRefreshLength, new GUIContent("Auto Refresh Length", "Recalculate Length on Refresh?"));
        EditorGUILayout.PropertyField(tAutoRefreshOrientation, new GUIContent("Auto Refresh Orientation", "Recalculate tangent normals and Up-Vectors on Refresh?"));

        if (tInterpolation.enumNames[tInterpolation.enumValueIndex] == "TCB")
        {
            EditorGUILayout.LabelField("TCB", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(tT, new GUIContent("Tension", "Tension for TCB-Spline"));
            EditorGUILayout.PropertyField(tC, new GUIContent("Continuity", "Continuity for TCB-Spline"));
            EditorGUILayout.PropertyField(tB, new GUIContent("Bias", "Bias for TCB-Spline"));

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Set Catmul", "Set TCB to match Catmul Rom")))
            {
                tT.floatValue = 0; tC.floatValue = 0; tB.floatValue = 0;
            }
            if (GUILayout.Button(new GUIContent("Set Cubic", "Set TCB to match Simple Cubic")))
            {
                tT.floatValue = -1; tC.floatValue = 0; tB.floatValue = 0;
            }
            if (GUILayout.Button(new GUIContent("Set Linear", "Set TCB to match Linear")))
            {
                tT.floatValue = 0; tC.floatValue = -1; tB.floatValue = 0;
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.LabelField("Miscellaneous", EditorStyles.boldLabel);
        int cnt = tUserValueSize.intValue;

        EditorGUILayout.PropertyField(tUserValueSize, new GUIContent("User Value Size", "Size of User Value array"));
        if (cnt != tUserValueSize.intValue)
        {
            tUserValueSize.intValue = UnityEngine.Mathf.Max(0, tUserValueSize.intValue);
        }

        EditorGUILayout.LabelField("Gizmos & Handles", EditorStyles.boldLabel);
        EditorGUILayout.PropertyField(tShowGizmos, new GUIContent("Show Gizmos", "Show Spline Gizmos"));
        EditorGUILayout.PropertyField(tShowApprox, new GUIContent("Show Approximation", "Show Approximation"));
        EditorGUILayout.PropertyField(tShowTangents, new GUIContent("Show Tangents", "Show Tangents"));
        EditorGUILayout.PropertyField(tShowOrientation, new GUIContent("Show Orientation", "Show Orientation"));
        EditorGUILayout.PropertyField(tShowLabels, new GUIContent("Show Labels", "Show Labels in Scene View"));
        EditorGUILayout.PropertyField(tShowUserValues, new GUIContent("Show User Values", "Show User Values in Scene View"));
        if (serializedObject.targetObject && serializedObject.ApplyModifiedProperties())
        {
            Target.Refresh(true, true, false);
            SceneView.RepaintAll();
        }

        EditorGUILayout.LabelField("Spline Info", EditorStyles.boldLabel);
        EditorGUILayout.LabelField("Total Length: " + Target.Length);
        EditorGUILayout.LabelField("Control Points: " + Target.ControlPointCount);
        EditorGUILayout.LabelField("Segments: " + Target.Count);

        EditorGUILayout.LabelField("Tools", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        GUI.enabled = CurvyEditorUtility.IsSingleSelection;
        if (GUILayout.Button(new GUIContent(mTexAlignWizard, "Align wizard"), GUILayout.ExpandWidth(false)))
        {
            CurvySplineAlignWizard.Create();
        }
        if (GUILayout.Button(new GUIContent(mTexExportWizard, "Mesh Export wizard"), GUILayout.ExpandWidth(false)))
        {
            CurvySplineExportWizard.Create();
        }
        GUI.enabled = true;
        if (GUILayout.Button(new GUIContent(mTexCenterPivot, "Center Pivot"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterUndo(EditorUtility.CollectDeepHierarchy(new UnityEngine.Object[] { Target }), "Center Spline Pivot");
            CurvyUtility.centerPivot(Target);
        }
        if (GUILayout.Button(new GUIContent(mTexFlip, "Flip Direction"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterUndo(EditorUtility.CollectDeepHierarchy(new UnityEngine.Object[] { Target }), "Flip Direction");
            CurvyUtility.FlipSpline(Target);
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.LabelField("Components", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        GUI.enabled = CurvyEditorUtility.IsSingleSelection;
        if (GUILayout.Button(new GUIContent(mTexClonePath, "Create Clone Path"), GUILayout.ExpandWidth(false)))
        {
            CurvySplinePathCloneBuilderInspector.CreateCloneBuilder();
        }
        if (GUILayout.Button(new GUIContent(mTexMeshPath, "Create Mesh Path"), GUILayout.ExpandWidth(false)))
        {
            CurvySplinePathMeshBuilderInspector.CreateMeshBuilder();
        }
        GUI.enabled = true;
        if (GUILayout.Button(new GUIContent(mTexGroup, "Form SplineGroup"), GUILayout.ExpandWidth(false)))
        {
            Undo.RegisterSceneUndo("Form SplineGroup");
            Selection.activeObject = CurvySplineGroup.Create(CurvyEditorUtility.GetSelection <CurvySpline>());
        }
        GUILayout.EndHorizontal();
        EditorGUILayout.LabelField("General", EditorStyles.boldLabel);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent(mTexPrefs, "Preferences"), GUILayout.ExpandWidth(false)))
        {
            CurvyPreferences.Open();
        }

        if (GUILayout.Button(new GUIContent(mTexHelp, "Help"), GUILayout.ExpandWidth(false)))
        {
            var mnu = new GenericMenu();
            mnu.AddItem(new GUIContent("Online Manual"), false, new GenericMenu.MenuFunction(OnShowManual));
            mnu.AddItem(new GUIContent("Website"), false, new GenericMenu.MenuFunction(OnShowWeb));
            mnu.AddSeparator("");
            mnu.AddItem(new GUIContent("Report a bug"), false, new GenericMenu.MenuFunction(OnBugReport));
            mnu.ShowAsContext();
        }

        GUILayout.EndHorizontal();
        EditorGUILayout.LabelField("Curvy v" + CurvySpline.Version, EditorStyles.miniLabel);


        //Repaint();
    }