예제 #1
0
        public override void Action()
        {
#if OLD_UNDO
            Undo.RegisterSceneUndo("Set first CP");
#else
            CurvyEditorUtility.UndoRegisterSplineControlPoints(Toolbar.SelectedControlPoint.Spline, "Set first CP");
#endif
            CurvyUtility.SetFirstCP(Toolbar.SelectedControlPoint);
        }
예제 #2
0
        public override void Action()
        {
            var sel = Toolbar.SelectedControlPoint;

            if (sel)
            {
                sel = sel.PreviousControlPoint;
            }
            CurvyEditorUtility.UndoDeleteControlPoints(Toolbar.SelectedControlPoints.ToArray());
            Selection.activeObject = sel;
        }
예제 #3
0
        public override void Action()
        {
            var         lastOld   = Toolbar.SelectedControlPoint.PreviousControlPoint;
            CurvySpline newSpline = CurvyEditorUtility.UndoSplitSpline(Toolbar.SelectedControlPoint);

            if (lastOld && newSpline.ControlPointCount > 0)
            {
                Selection.activeGameObject = lastOld.gameObject; // to set the active connection to the other. Strange...
                Selection.objects          = new GameObject[2] {
                    lastOld.gameObject, newSpline.ControlPoints[0].gameObject
                };;
            }
        }
예제 #4
0
        public override void Action()
        {
            var sel    = Toolbar.SelectedControlPoints;
            var source = sel[1];
            var dest   = sel[0];

#if OLD_UNDO
            Undo.RegisterSceneUndo("Join Spline");
            CurvyUtility.JoinSpline(source, dest);
#else
            CurvyEditorUtility.UndoJoinSpline(source, dest);
#endif
            Selection.activeObject = dest;
        }
예제 #5
0
        public override void Action()
        {
#if OLD_UNDO
            Undo.RegisterSceneUndo("Flip Spline(s)");
            foreach (var spline in Toolbar.SelectedSplines)
            {
                CurvyUtility.FlipSpline(spline);
            }
#else
            foreach (var spline in Toolbar.SelectedSplines)
            {
                CurvyEditorUtility.UndoRegisterSplineControlPoints(spline, "Flip Spline(s)");
                CurvyUtility.FlipSpline(spline);
            }
#endif
        }
예제 #6
0
        public void LoadData()
        {
            // Build TypeByModuleInfo and ModuleInfoByInput dictionaries
            TypeByModuleInfo.Clear();
            ModuleInfoByInput.Clear();
            TypeByModuleInfo = new SortedDictionary <ModuleInfoAttribute, System.Type>(DTUtility.GetTypesWithAttribute <ModuleInfoAttribute, CGModule>());

            foreach (var kv in TypeByModuleInfo)
            {
                var T      = kv.Value;
                var fields = T.GetFields(BindingFlags.Public | BindingFlags.Instance);
                foreach (var f in fields)
                {
                    if (f.FieldType == typeof(CGModuleInputSlot))
                    {
                        var slotAttrib = f.GetCustomAttributes(typeof(InputSlotInfo), true);
                        if (slotAttrib.Length > 0)
                        {
                            var si = (InputSlotInfo)slotAttrib[0];
                            List <ModuleInfoAttribute> lst;
                            for (int x = 0; x < si.DataTypes.Length; x++)
                            {
                                if (!ModuleInfoByInput.TryGetValue(si.DataTypes[x], out lst))
                                {
                                    lst = new List <ModuleInfoAttribute>();
                                    ModuleInfoByInput.Add(si.DataTypes[x], lst);
                                }

                                lst.Add(kv.Key);
                            }
                        }
                    }
                }
            }
            // load Templates
            TemplatesByMenuName.Clear();
            string[] baseFolders;
            if (AssetDatabase.IsValidFolder("Assets/" + CurvyProject.Instance.CustomizationRootPath + CurvyProject.RELPATH_CGTEMPLATES))
            {
                baseFolders = new string[2] {
                    "Assets/" + CurvyEditorUtility.GetPackagePath("CG Templates"),
                    "Assets/" + CurvyProject.Instance.CustomizationRootPath + CurvyProject.RELPATH_CGTEMPLATES
                }
            }
            ;
            else
            {
                baseFolders = new string[1] {
                    "Assets/" + CurvyEditorUtility.GetPackagePath("CG Templates")
                }
            };

            string[] prefabs = AssetDatabase.FindAssets("t:gameobject", baseFolders);

            foreach (var guid in prefabs)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                // Store under a unique menu name
                string name     = AssetDatabase.LoadAssetAtPath(path, typeof(Transform)).name;
                string menuPath = System.IO.Path.GetDirectoryName(path);
                foreach (var s in baseFolders)
                {
                    menuPath = menuPath.TrimStart(s);
                }
                menuPath = menuPath.TrimStart('/');

                string menuName = string.IsNullOrEmpty(menuPath) ? name : menuPath + "/" + name;
                int    i        = 0;
                while (TemplatesByMenuName.ContainsKey((i == 0) ? menuName :menuName + i.ToString()))
                {
                    i++;
                }
                TemplatesByMenuName.Add((i == 0) ? menuName : menuName + i.ToString(), path);
            }
        }
    void OnSceneGUI()
    {
        Handles.ArrowCap(0, Target.Position, Quaternion.LookRotation(Target.Transform.up), 2);

        // Handle custom Tools
        if (Tools.current == Tool.Rotate || Tools.current == Tool.Scale || Tools.current == Tool.View)
        {
            customMoveTool = false;
        }
        else
        {
            Tools.current  = Tool.None;
            customMoveTool = true;
        }

        if (IsActive)
        {
            bool hasLocalHandles = Target.Spline.Interpolation == CurvyInterpolation.Bezier;
            int  controlID       = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);


            if (customMoveTool)
            {
                Vector3 delta = CurvyEditorUtility.PositionHandle(controlID, Tools.handlePosition, Tools.handleRotation, 1f,
                                                                  ConstrainXAxis,
                                                                  ConstrainYAxis,
                                                                  ConstrainZAxis) - Tools.handlePosition;
                if (GUI.changed)
                {
                    Transform[] transforms = Selection.transforms;
                    for (int i = 0; i < transforms.Length; i++)
                    {
                        transforms[i].position += delta;
                    }
                    Target.Spline.Refresh(true, true, false);
                    if (ConstraintSplineLength > 0 && Target.Spline.Length > ConstraintSplineLength)
                    {
                        for (int i = 0; i < transforms.Length; i++)
                        {
                            transforms[i].position -= delta;
                        }
                        Target.Spline.Refresh(true, true, false);
                    }
                }
            }


            // Bezier-Handles
            if (hasLocalHandles)
            {
                Handles.color = Color.grey;
                Vector3 handleOut = Target.HandleOutPosition;
                Vector3 handleIn  = Target.HandleInPosition;


                Target.HandleOutPosition = CurvyEditorUtility.PositionHandle(GUIUtility.GetControlID(FocusType.Passive), Target.HandleOutPosition, Tools.handleRotation, 0.5f,
                                                                             ConstrainXAxis,
                                                                             ConstrainYAxis,
                                                                             ConstrainZAxis);
                Handles.CubeCap(0, Target.HandleOutPosition, Quaternion.identity, HandleUtility.GetHandleSize(Target.HandleOutPosition) * 0.1f);
                Handles.DrawLine(Target.HandleOutPosition, Target.Position);

                Target.HandleInPosition = CurvyEditorUtility.PositionHandle(GUIUtility.GetControlID(FocusType.Passive), Target.HandleInPosition, Tools.handleRotation, 0.5f,
                                                                            ConstrainXAxis,
                                                                            ConstrainYAxis,
                                                                            ConstrainZAxis);
                Handles.CubeCap(0, Target.HandleInPosition, Quaternion.identity, HandleUtility.GetHandleSize(Target.HandleInPosition) * 0.1f);
                Handles.DrawLine(Target.HandleInPosition, Target.Position);

                if (GUI.changed)
                {
                    Target.Spline.RefreshImmediately(true, true, false);
                    if (ConstraintSplineLength > 0 && Target.Spline.Length > ConstraintSplineLength)
                    {
                        Target.HandleOutPosition = handleOut;
                        Target.HandleInPosition  = handleIn;
                        Target.Spline.RefreshImmediately(true, true, false);
                    }
                }
            }

            // Window
            Handles.BeginGUI();
            GUILayout.Window(GetInstanceID(), new Rect(10, 40, 150, 20), DoWin, Target.name);
            Handles.EndGUI();

            // Shortcut-Keys

            if (CurvyPreferences.kNext.IsKeyDown(Event.current) && Target.NextControlPoint)
            {
                Selection.activeObject = Target.NextControlPoint;
            }
            else if (CurvyPreferences.kPrev.IsKeyDown(Event.current) && Target.PreviousControlPoint)
            {
                Selection.activeObject = Target.PreviousControlPoint;
            }
            else if (CurvyPreferences.kInsertBefore.IsKeyDown(Event.current))
            {
                InsBefore();
            }
            else if (CurvyPreferences.kInsertAfter.IsKeyDown(Event.current))
            {
                InsAfter();
            }
            else if (CurvyPreferences.kDelete.IsKeyDown(Event.current))
            {
                Delete();
            }
            else if (CurvyPreferences.kToggleFreeMove.IsKeyDown(Event.current))
            {
                Target.FreeHandles = !Target.FreeHandles;
            }
        }
    }
예제 #8
0
    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();
    }