private void Merge(int verticalOffset)
        {
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                return;
            }
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Merge endpoints", true);
            mergeEditor.mergeEndpoints = GUI.Toggle(new Rect(130 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), mergeEditor.mergeEndpoints, "");
            int mergeSide = (int)mergeEditor.mergeSide;

            DreamteckEditorGUI.Label(new Rect(120 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Merge side", true);
            bool hover = SplineEditorGUI.DropDown(new Rect(250, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Start", "End" }, true, ref mergeSide);

            mergeEditor.mergeSide = (SplineComputerMergeEditor.MergeSide)mergeSide;
            if (hover)
            {
                mouseHoversToolbar = true;
            }
        }
        private void Translate(int verticalOffset)
        {
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                return;
            }
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            DreamteckEditorGUI.Label(new Rect(110 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Grid snap", true);
            positionEditor.snap = GUI.Toggle(new Rect(200 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), positionEditor.snap, "");

            if (positionEditor.snap)
            {
                DreamteckEditorGUI.Label(new Rect(220 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Grid size:", true);
                positionEditor.snapGridSize = SplineEditorGUI.FloatField(new Rect(300 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), positionEditor.snapGridSize);
                positionEditor.snapGridSize = SplineEditorGUI.FloatDrag(new Rect(220 * scale, verticalOffset + 5 * scale, 80 * scale, 25 * scale), positionEditor.snapGridSize);
                if (positionEditor.snapGridSize < 0.001f)
                {
                    positionEditor.snapGridSize = 0.001f;
                }
            }

            EditSpaceMenu(verticalOffset);
        }
        private void Create2DToolbar(int verticalOffset)
        {
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 105 * scale, 25 * scale), "Place method:", true);
            bool hover = SplineEditorGUI.DropDown(new Rect(110 * scale, verticalOffset + 5 * scale, 130 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Free", "Insert" }, true, ref createPointMode2D);

            if (hover)
            {
                mouseHoversToolbar = true;
            }
            DreamteckEditorGUI.Label(new Rect(230 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Add Node", true);
            createNodeOnCreatePoint = GUI.Toggle(new Rect(320 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), createNodeOnCreatePoint, "");



            minWidth = 790;
            if (createPointMode != 1)
            {
                DreamteckEditorGUI.Label(new Rect(325 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Append:", true);
                if (SplineEditorGUI.DropDown(new Rect(405 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "End", "Beginning" }, true, ref appendMode))
                {
                    mouseHoversToolbar = true;
                }
                minWidth = 1100;
            }
        }
Example #4
0
        protected virtual void OnSceneGUI()
        {
            if (initGUI)
            {
                SplineEditorGUI.Initialize();
                initGUI = false;
            }
            SplineUser user = (SplineUser)target;

            if (user.computer == null)
            {
                SplineUser root = user.rootUser;
                if (root == null)
                {
                    return;
                }
                if (root.computer == null)
                {
                    return;
                }
                List <SplineComputer> allComputers = root.computer.GetConnectedComputers();
                for (int i = 0; i < allComputers.Count; i++)
                {
                    if (allComputers[i] == root.computer)
                    {
                        continue;
                    }
                    SplineEditor.DrawSplineComputer(allComputers[i], SceneView.currentDrawingSceneView.camera, false, false, 0.4f);
                }
                for (int i = 0; i < root.address.depth; i++)
                {
                    if (user.address.elements[i].computer == root.computer)
                    {
                        continue;
                    }
                    SplineEditor.DrawSplineComputer(root.address.elements[i].computer, SceneView.currentDrawingSceneView.camera, false, false, 1f, root.address.elements[i].startPercent, root.address.elements[i].endPercent, false);
                }
            }
            else
            {
                SplineComputer        rootComputer = user.GetComponent <SplineComputer>();
                List <SplineComputer> allComputers = user.computer.GetConnectedComputers();
                for (int i = 0; i < allComputers.Count; i++)
                {
                    if (allComputers[i] == rootComputer)
                    {
                        continue;
                    }
                    SplineEditor.DrawSplineComputer(allComputers[i], SceneView.currentDrawingSceneView.camera, false, false, 0.4f);
                }
                for (int i = 0; i < user.address.depth; i++)
                {
                    if (user.address.elements[i].computer == rootComputer)
                    {
                        continue;
                    }
                    SplineEditor.DrawSplineComputer(user.address.elements[i].computer, SceneView.currentDrawingSceneView.camera, false, false, 1f, user.address.elements[i].startPercent, user.address.elements[i].endPercent, false);
                }
            }
        }
        private void Normals(int verticalOffset)
        {
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                return;
            }
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            if (SplineEditorGUI.Button(new Rect(5 * scale, verticalOffset + 5 * scale, 130 * scale, 25 * scale), "Set Normals:"))
            {
                SetSelectedNormals();
            }
            bool hover = SplineEditorGUI.DropDown(new Rect(160 * scale, verticalOffset + 5 * scale, 150 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "At Camera", "Align with Camera", "Calculate", "Left", "Right", "Up", "Down", "Forward", "Back", "Inverse", "At Avg. Center", "By Direction" }, true, ref normalEditor.setNormalMode);

            if (hover)
            {
                mouseHoversToolbar = true;
            }
        }
Example #6
0
        void RenderConnections()
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            Rect viewRect = new Rect(0, 0, Screen.width - 60, connections.Length * 25);

            GUILayout.Box("Connections", GUILayout.Width(Screen.width - 30), GUILayout.Height(Mathf.Min(Mathf.Max(viewRect.height, 30), 110) + 30));
            Rect rect = GUILayoutUtility.GetLastRect();

            SplineComputer[] addComps;
            SplineComputer   lastComp = addComp;
            bool             dragged  = SplineEditorGUI.DropArea <SplineComputer>(rect, out addComps);

            if (dragged && addComps.Length > 0)
            {
                SelectComputer(addComps[0]);
            }
            if (lastComp != addComp)
            {
                SceneView.RepaintAll();
            }
            rect.x      += 5;
            rect.width  -= 10;
            rect.height -= 30;
            rect.y      += 20;
            if (connections.Length > 0)
            {
                scroll = GUI.BeginScrollView(rect, scroll, viewRect);
                for (int i = 0; i < connections.Length; i++)
                {
                    GUI.Label(new Rect(0, i * 25, viewRect.width * 0.75f, 20), connections[i].computer.name + " at point " + connections[i].pointIndex);
                    if (GUI.Button(new Rect(viewRect.width - 20, i * 25, 20, 20), "x"))
                    {
                        Undo.RecordObject(node, "Remove connection");
                        Undo.RecordObject(connections[i].computer, "Remove node");
                        node.RemoveConnection(connections[i].computer, connections[i].pointIndex);
                    }
                }
                GUI.EndScrollView();
            }
            else
            {
                EditorGUI.HelpBox(rect, "Drag & Drop SplineComputers here to link their points.", MessageType.Info);
            }

            node.transformNormals  = EditorGUILayout.Toggle("Transform Normals", node.transformNormals);
            node.transformSize     = EditorGUILayout.Toggle("Transform Size", node.transformSize);
            node.transformTangents = EditorGUILayout.Toggle("Transform Tangents", node.transformTangents);

            if (connections.Length > 1)
            {
                node.type = (Node.Type)EditorGUILayout.EnumPopup("node type", node.type);
            }
        }
        private void Mirror(int verticalOffset)
        {
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                return;
            }
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            if (SplineEditorGUI.Button(new Rect(5 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Cancel"))
            {
                ExitMirrorMode();
            }
            if (SplineEditorGUI.Button(new Rect(115 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Save"))
            {
                SaveMirror();
            }

            DreamteckEditorGUI.Label(new Rect(215 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Axis", true);
            int  axis  = (int)mirrorEditor.axis;
            bool hover = SplineEditorGUI.DropDown(new Rect(270 * scale, verticalOffset + 5 * scale, 60 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "X", "Y", "Z" }, true, ref axis);

            mirrorEditor.axis = (SplinePointMirrorEditor.Axis)axis;
            if (hover)
            {
                mouseHoversToolbar = true;
            }

            DreamteckEditorGUI.Label(new Rect(315 * scale, verticalOffset + 5 * scale, 60 * scale, 25 * scale), "Flip", true);
            mirrorEditor.flip = GUI.Toggle(new Rect(380 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), mirrorEditor.flip, "");

            DreamteckEditorGUI.Label(new Rect(390 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Weld Distance", true);

            mirrorEditor.weldDistance = SplineEditorGUI.FloatField(new Rect(525 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.weldDistance);
            mirrorEditor.weldDistance = SplineEditorGUI.FloatDrag(new Rect(390 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), mirrorEditor.weldDistance);
            if (mirrorEditor.weldDistance < 0f)
            {
                mirrorEditor.weldDistance = 0f;
            }

            DreamteckEditorGUI.Label(new Rect(570 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Center  X:", true);
            mirrorEditor.center.x = SplineEditorGUI.FloatField(new Rect(700 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.x);

            DreamteckEditorGUI.Label(new Rect(720 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Y:", true);
            mirrorEditor.center.y = SplineEditorGUI.FloatField(new Rect(770 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.y);
            DreamteckEditorGUI.Label(new Rect(790 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), "Z:", true);
            mirrorEditor.center.z = SplineEditorGUI.FloatField(new Rect(840 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), mirrorEditor.center.z);
        }
Example #8
0
 void OnSceneGUI(SceneView sceneView)
 {
     Handles.BeginGUI();
     for (int i = 0; i < pointIndices.Count; i++)
     {
         Vector2 screenPosition = HandleUtility.WorldToGUIPoint(currentComputer.GetPoint(pointIndices[i]).position);
         screenPosition.y -= 25f;
         string pointName = "P" + pointIndices[i];
         SplineEditorGUI.Label(new Rect(screenPosition.x - 120 + pointName.Length * 4, screenPosition.y, 120, 25), pointName);
     }
     Handles.EndGUI();
 }
        private void EditSpaceMenu(int verticalOffset)
        {
            int  lastSpace = editSpace;
            bool hover     = SplineEditorGUI.DropDown(new Rect(5, verticalOffset + 5 * scale, 115 * scale, 25 * scale), SplineEditorGUI.defaultButton, editSpaceText, true, ref editSpace);

            if (hover)
            {
                mouseHoversToolbar = true;
            }
            if (lastSpace != editSpace)
            {
                RefreshPointEditors();
            }
        }
        protected override void BodyGUI()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Length Calculator", EditorStyles.boldLabel);
            base.BodyGUI();
            LengthCalculator calculator = (LengthCalculator)target;

            EditorGUILayout.HelpBox("Length: " + calculator.length, MessageType.Info);

            for (int i = 0; i < calculator.lengthEvents.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                calculator.lengthEvents[i].enabled      = EditorGUILayout.Toggle(calculator.lengthEvents[i].enabled);
                calculator.lengthEvents[i].targetLength = EditorGUILayout.FloatField("Target Length", calculator.lengthEvents[i].targetLength);
                calculator.lengthEvents[i].type         = (LengthCalculator.LengthEvent.Type)EditorGUILayout.EnumPopup(calculator.lengthEvents[i].type);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                SplineEditorGUI.ActionField(calculator.lengthEvents[i].action);
                if (GUILayout.Button("x", GUILayout.Width(20)))
                {
                    LengthCalculator.LengthEvent[] newEvents = new LengthCalculator.LengthEvent[calculator.lengthEvents.Length - 1];
                    for (int n = 0; n < calculator.lengthEvents.Length; n++)
                    {
                        if (i == n)
                        {
                            continue;
                        }
                        else if (n < i)
                        {
                            newEvents[n] = calculator.lengthEvents[n];
                        }
                        else if (n > i)
                        {
                            newEvents[n - 1] = calculator.lengthEvents[n];
                        }
                    }
                    calculator.lengthEvents = newEvents;
                }
                EditorGUILayout.EndHorizontal();
            }
            if (GUILayout.Button("Add Length Event"))
            {
                LengthCalculator.LengthEvent[] newEvents = new LengthCalculator.LengthEvent[calculator.lengthEvents.Length + 1];
                calculator.lengthEvents.CopyTo(newEvents, 0);
                newEvents[newEvents.Length - 1]        = new LengthCalculator.LengthEvent();
                newEvents[newEvents.Length - 1].action = new SplineAction();
                calculator.lengthEvents = newEvents;
            }
        }
Example #11
0
        public override void OnInspectorGUI()
        {
            MeshGenerator generator = (MeshGenerator)target;

            if (generator.baked)
            {
                if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent("Revert Bake", "Makes the mesh dynamic again and allows editing"), true, true))
                {
                    generator.Unbake();
                    EditorUtility.SetDirty(target);
                }
                return;
            }
            base.OnInspectorGUI();
        }
        public void DrawToolbar()
        {
            if (Screen.width < minWidth)
            {
                scale = (float)Screen.width / minWidth;
            }
            else
            {
                scale = 1f;
            }
            SplineEditorGUI.SetScale(scale);
            DreamteckEditorGUI.SetScale(scale);
            mouseHoversToolbar = false;
            minWidth           = 770;
            if (InMirrorMode())
            {
                Mirror(Mathf.RoundToInt(44 * scale));
            }
            else if (InMergeMode())
            {
                Merge(Mathf.RoundToInt(44 * scale));
            }
            else
            {
                switch (tool)
                {
                case PointTool.Create:
                    if (computer.is2D)
                    {
                        Create2DToolbar(Mathf.RoundToInt(44 * scale));
                    }
                    else
                    {
                        CreateToolbar(Mathf.RoundToInt(44 * scale));
                    }
                    break;

                case PointTool.NormalEdit: Normals(Mathf.RoundToInt(44 * scale)); break;

                case PointTool.Move: Translate(Mathf.RoundToInt(44 * scale)); break;

                case PointTool.Scale: Scale(Mathf.RoundToInt(44 * scale)); break;

                case PointTool.Rotate: Rotate(Mathf.RoundToInt(44 * scale)); break;
                }
            }
            Main();
        }
        public SplineEditorToolbar(SplineEditor edit, SplineComputer comp)
        {
            editor   = edit;
            computer = comp;
            Texture2D tex = SplineEditorGUI.LoadTexture("presets.png");

            if (tex != null)
            {
                presetButtonContent.image = tex; presetButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("move.png");
            if (tex != null)
            {
                moveButtonContent.image = tex; moveButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("rotate.png");
            if (tex != null)
            {
                rotateButtonContent.image = tex; rotateButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("scale.png");
            if (tex != null)
            {
                scaleButtonContent.image = tex; scaleButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("normals.png");
            if (tex != null)
            {
                normalsButtonContent.image = tex; normalsButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("mirror.png");
            if (tex != null)
            {
                mirrorButtonContent.image = tex; mirrorButtonContent.text = "";
            }

            tex = SplineEditorGUI.LoadTexture("merge.png");
            if (tex != null)
            {
                mergeButtonContent.image = tex; mergeButtonContent.text = "";
            }
        }
        private void Rotate(int verticalOffset)
        {
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHovers = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            SplineEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Rotate normals", true);
            editor.rotationEditor.rotateNormals = GUI.Toggle(new Rect(130 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), editor.rotationEditor.rotateNormals, "");

            SplineEditorGUI.Label(new Rect(140 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Rotate tangents", true);
            editor.rotationEditor.rotateTangents = GUI.Toggle(new Rect(265 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), editor.rotationEditor.rotateTangents, "");
        }
        public bool EditButton(bool selected)
        {
            float width = 40f;

            editButtonContent.image = ImageDB.GetImage("edit_cursor.png", "Splines/Editor/Icons");
            if (editButtonContent.image != null)
            {
                editButtonContent.text = "";
                width = 25f;
            }
            if (SplineEditorGUI.EditorLayoutSelectableButton(editButtonContent, true, selected, GUILayout.Width(width)))
            {
                SceneView.RepaintAll();
                return(true);
            }
            return(false);
        }
        private void Scale(int verticalOffset)
        {
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHovers = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            SplineEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Scale sizes", true);
            editor.scaleEditor.scaleSize = GUI.Toggle(new Rect(100 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), editor.scaleEditor.scaleSize, "");

            SplineEditorGUI.Label(new Rect(110 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Scale tangents", true);
            editor.scaleEditor.scaleTangents = GUI.Toggle(new Rect(235 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), editor.scaleEditor.scaleTangents, "");
        }
        public void Draw()
        {
            if (Screen.width < minWidth)
            {
                scale = (float)Screen.width / minWidth;
            }
            else
            {
                scale = 1f;
            }
            SplineEditorGUI.SetScale(scale);
            SplineEditorGUI.scale = scale;
            mouseHovers           = false;
            minWidth = 610;
            if (editor.InMirrorMode())
            {
                Mirror(Mathf.RoundToInt(44 * scale));
            }
            else if (editor.InMergeMode())
            {
                Merge(Mathf.RoundToInt(44 * scale));
            }
            else
            {
                if (editor.tool == SplineEditor.PointTool.Create)
                {
                    Create(Mathf.RoundToInt(44 * scale));
                }
                if (editor.tool == SplineEditor.PointTool.NormalEdit)
                {
                    Normals(Mathf.RoundToInt(44 * scale));
                }
                if (editor.tool == SplineEditor.PointTool.Scale)
                {
                    Scale(Mathf.RoundToInt(44 * scale));
                }
                if (editor.tool == SplineEditor.PointTool.Rotate)
                {
                    Rotate(Mathf.RoundToInt(44 * scale));
                }
            }

            Main();
        }
Example #18
0
        void OnGUI()
        {
            if (tools == null)
            {
                Awake();
            }
            GUI.color = new Color(0f, 0f, 0f, 0.15f);
            GUI.DrawTexture(new Rect(0, 0, menuWidth, position.height), SplineEditorGUI.white, ScaleMode.StretchToFill);
            GUI.color = Color.white;
            GUILayout.BeginHorizontal();
            GUILayout.BeginScrollView(scroll, GUILayout.Width(menuWidth), GUILayout.Height(position.height - 10));
            if (tools == null)
            {
                Init();
            }
            for (int i = 0; i < tools.Length; i++)
            {
                if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent(tools[i].GetName()), true, toolIndex == i))
                {
                    if (toolIndex >= 0 && toolIndex < tools.Length)
                    {
                        tools[toolIndex].Close();
                    }
                    toolIndex = i;
                    if (toolIndex < tools.Length)
                    {
                        tools[toolIndex].Open(this);
                    }
                }
            }
            GUILayout.EndScrollView();


            if (toolIndex >= 0 && toolIndex < tools.Length)
            {
                GUILayout.BeginVertical();
                tools[toolIndex].Draw(new Rect(menuWidth, 0, position.width - menuWidth - 5f, position.height - 10));
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();
        }
Example #19
0
        private void Scale(int verticalOffset)
        {
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                return;
            }
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            EditSpaceMenu(verticalOffset);
            SplineEditorGUI.Label(new Rect(120 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Scale sizes", true);
            scaleEditor.scaleSize = GUI.Toggle(new Rect(210 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), scaleEditor.scaleSize, "");
            SplineEditorGUI.Label(new Rect(235 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), "Scale tangents", true);
            scaleEditor.scaleTangents = GUI.Toggle(new Rect(355 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), scaleEditor.scaleTangents, "");
        }
Example #20
0
        public void init()
        {
            minSize = maxSize = new Vector2(450, 500);
#if UNITY_5_0
            title = "Dreamteck Splines " + PluginInfo.version;
#else
            titleContent = new GUIContent("Dreamteck Splines " + PluginInfo.version);
#endif
            position = new Rect(Screen.width / 2f - 200, Screen.height / 2f - 200, 450, 500);

            changeLogPanel               = new WindowPanel();
            supportPanel                 = new WindowPanel();
            homePanel                    = new WindowPanel();
            learnPanel                   = new WindowPanel();
            changeLogPanel.size          = supportPanel.size = homePanel.size = learnPanel.size = new Vector2(maxSize.x, maxSize.y - 82);
            changeLogPanel.slideDuration = supportPanel.slideDuration = homePanel.slideDuration = learnPanel.slideDuration = 0.25f;
            homePanel.SetState(true, false);
            header        = SplineEditorGUI.LoadTexture("plugin_header.png");
            changelogIcon = SplineEditorGUI.LoadTexture("changelog.png");
            learnIcon     = SplineEditorGUI.LoadTexture("get_started.png");
            supportIcon   = SplineEditorGUI.LoadTexture("support.png");
            rateIcon      = SplineEditorGUI.LoadTexture("rate.png");
            pdfIcon       = SplineEditorGUI.LoadTexture("pdf.png");
            videoIcon     = SplineEditorGUI.LoadTexture("video_tutorials.png");

            string path = Application.dataPath + "/Dreamteck/Splines/Editor/";
            if (Directory.Exists(path))
            {
                if (File.Exists(path + "changelog.txt"))
                {
                    string[] lines = File.ReadAllLines(path + "changelog.txt");
                    changelogText = "";
                    for (int i = 0; i < lines.Length; i++)
                    {
                        changelogText += lines[i] + "\r\n";
                    }
                }
            }
        }
        protected override void DrawInspectorLogic()
        {
            if (!allowSelection)
            {
                selected = -1;
            }
            if (selected >= 0 && selected < group.keys.Count)
            {
                if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent("Offset Handle"), true, editOffset))
                {
                    SceneView.RepaintAll();
                    editOffset = !editOffset;
                }
            }

            EditorGUI.BeginChangeCheck();
            for (int i = 0; i < group.keys.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal();
                EditorGUIUtility.labelWidth = 55f;
                group.keys[i].offset        = EditorGUILayout.Vector2Field("Offset", group.keys[i].offset);
                if (group.keys[i].interpolation == null)
                {
                    group.keys[i].interpolation = AnimationCurve.Linear(0f, 0f, 1f, 1f);
                }
                EditorGUIUtility.labelWidth = 90f;
                group.keys[i].interpolation = EditorGUILayout.CurveField("Interpolation", group.keys[i].interpolation);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                if (allowSelection)
                {
                    if (parentEditor.EditButton(selected == i))
                    {
                        if (selected == i)
                        {
                            selected = -1;
                        }
                        else
                        {
                            selected = i;
                        }
                        SceneView.RepaintAll();
                    }
                }
                EditorGUIUtility.labelWidth = 50f;
                group.keys[i].from          = EditorGUILayout.Slider("Start", (float)group.keys[i].from, 0f, 1f);
                group.keys[i].to            = EditorGUILayout.Slider("End", (float)group.keys[i].to, 0f, 1f);
                group.keys[i].center        = EditorGUILayout.Slider("Center", (float)group.keys[i].center, 0f, 1f);
                EditorGUILayout.EndHorizontal();
                EditorGUIUtility.labelWidth = 0f;
                EditorGUILayout.EndVertical();
                if (GUILayout.Button("x", GUILayout.Width(30)))
                {
                    selected = -1;
                    group.keys.RemoveAt(i);
                    i--;
                    EditorGUILayout.EndHorizontal();
                    continue;
                }
                EditorGUILayout.EndHorizontal();
                if (i < group.keys.Count - 1)
                {
                    EditorGUILayout.Space();
                }
            }
            if (group.keys.Count > 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Blend", EditorStyles.boldLabel);
                group.blend = EditorGUILayout.Slider(group.blend, 0f, 1f);
                EditorGUILayout.Space();
            }
            if (GUILayout.Button("Add New Offset"))
            {
                group.AddKey(Vector2.zero, addTime - 0.1, addTime + 0.1, 0.5);
            }

            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
        }
Example #22
0
        protected override void OnSceneGUI()
        {
            base.OnSceneGUI();
            ObjectBender bender = (ObjectBender)target;

            if (selected.Count > 0)
            {
                Handles.BeginGUI();
                for (int i = 0; i < selected.Count; i++)
                {
                    Vector2 screenPosition = HandleUtility.WorldToGUIPoint(bender.bendProperties[selected[i]].transform.transform.position);
                    SplineEditorGUI.Label(new Rect(screenPosition.x - 120 + bender.bendProperties[selected[i]].transform.transform.name.Length * 4, screenPosition.y, 120, 25), bender.bendProperties[selected[i]].transform.transform.name);
                }
                Handles.EndGUI();
            }
            for (int i = 0; i < bender.bendProperties.Length; i++)
            {
                if (bender.bendProperties[i].bendSpline && bender.bendProperties[i].splineComputer != null)
                {
                    SplineDrawer.DrawSplineComputer(bender.bendProperties[i].splineComputer, 0.0, 1.0, 0.2f);
                }
            }

            //Draw bounds
            if (bender.bend)
            {
                return;
            }
            TS_Bounds bound = bender.GetBounds();
            Vector3   a     = bender.transform.TransformPoint(bound.min);
            Vector3   b     = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.min.z));
            Vector3   c     = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.max.z));
            Vector3   d     = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.min.y, bound.max.z));

            Vector3 e = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.min.z));
            Vector3 f = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.min.z));
            Vector3 g = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.max.z));
            Vector3 h = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.max.z));

            Handles.color = Color.gray;
            Handles.DrawLine(a, b);
            Handles.DrawLine(b, c);
            Handles.DrawLine(c, d);
            Handles.DrawLine(d, a);

            Handles.DrawLine(e, f);
            Handles.DrawLine(f, g);
            Handles.DrawLine(g, h);
            Handles.DrawLine(h, e);

            Handles.DrawLine(a, e);
            Handles.DrawLine(b, f);
            Handles.DrawLine(c, g);
            Handles.DrawLine(d, h);

            Vector3 r  = bender.transform.right;
            Vector3 fr = bender.transform.forward;

            switch (bender.axis)
            {
            case ObjectBender.Axis.Z: Handles.color = Color.blue; Handles.DrawLine(r + b, r + c);  break;

            case ObjectBender.Axis.X: Handles.color = Color.red; Handles.DrawLine(b - fr, a - fr); break;

            case ObjectBender.Axis.Y: Handles.color = Color.green; Handles.DrawLine(b - fr + r, f - fr + r); break;
            }
        }
Example #23
0
        void Presets()
        {
            if (presets == null)
            {
                return;
            }
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(position.width * 0.35f), GUILayout.MaxHeight(10 * 22));
            if (presets.Length == 0)
            {
                EditorGUILayout.HelpBox("No saved presets available", MessageType.Info);
            }
            for (int i = 0; i < presets.Length; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent(presets[i].name), true, presetIndex == i))
                {
                    Undo.RecordObject(this, "PresetsWindow state");
                    Undo.RecordObject(computer, "Spline state");
                    presetIndex    = i;
                    primitiveIndex = -1;
                    computer.SetPoints(presets[i].points);
                    ((SplineEditor)editor).Refresh();
                    computer.type = presets[i].type;
                    if (presets[i].isClosed)
                    {
                        computer.Close();
                    }
                    else
                    {
                        computer.Break();
                    }
                    SplineUser[] users = computer.GetComponents <SplineUser>();
                    foreach (SplineUser user in users)
                    {
                        user.Rebuild(true);
                    }
                    computer.Rebuild();
                    ((SplineEditor)editor).Refresh();
                    SceneView.RepaintAll();
                }
                if (GUILayout.Button("X", GUILayout.MaxWidth(30)))
                {
                    if (EditorUtility.DisplayDialog("Delete preset ?", "Do you want to delete this preset ? This action cannot be undone.", "Yes", "No"))
                    {
                        SplinePreset.Delete(presets[i].filename);
                        GetPresets();
                        if (presetIndex >= presets.Length)
                        {
                            presetIndex = -1;
                        }
                        break;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            if (GUILayout.Button("Create Preset"))
            {
                presetIndex = -1;
                newPreset   = new SplinePreset(computer.GetPoints(), computer.isClosed, computer.type);
                GetPresets();
            }
            EditorGUILayout.EndScrollView();

            if (presetIndex >= 0 && presetIndex < presets.Length)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField(presets[presetIndex].name);
                EditorGUILayout.LabelField(presets[presetIndex].description);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Save"))
                {
                    computer.Rebuild();
                    ((SplineEditor)editor).Refresh();
                    SceneView.RepaintAll();
                    presetIndex = -1;
                    this.Close();
                }
                if (GUILayout.Button("Cancel"))
                {
                    presets[presetIndex].Cancel();
                    presetIndex = -1;
                    SplineUser[] users = computer.GetComponents <SplineUser>();
                    foreach (SplineUser user in users)
                    {
                        user.Rebuild(true);
                    }
                    computer.Rebuild();
                    ((SplineEditor)editor).Refresh();
                    SceneView.RepaintAll();
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            else if (computer.pointCount > 0)
            {
                EditorGUILayout.BeginVertical();
                if (newPreset != null)
                {
                    SavePresetDialog();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }
Example #24
0
        public static bool DrawTrigger(SplineTrigger trigger, SplineUser user)
        {
            if (trigger == null)
            {
                return(false);
            }
            Camera       cam    = SceneView.currentDrawingSceneView.camera;
            SplineResult result = user.Evaluate(trigger.position);

            Handles.color = trigger.color;
            float   size           = HandleUtility.GetHandleSize(result.position);
            Vector3 center         = result.position;
            Vector2 screenPosition = HandleUtility.WorldToGUIPoint(center);

            screenPosition.y += 20f;
            Vector3 localPos = cam.transform.InverseTransformPoint(center);

            if (localPos.z > 0f)
            {
                Handles.BeginGUI();
                SplineEditorGUI.Label(new Rect(screenPosition.x - 120 + trigger.name.Length * 4, screenPosition.y, 120, 25), trigger.name);
                Handles.EndGUI();
            }
            bool buttonClick = Button(center, false, Color.white, 0.3f);

            Vector3 right = Vector3.Cross(cam.transform.position - result.position, result.direction).normalized *size * 0.1f;

            if (trigger.type == SplineTrigger.Type.Backward)
            {
                center += result.direction * size * 0.06f;
                Vector3 front = center - result.direction * size * 0.2f;
                Handles.DrawLine(center + right, front);
                Handles.DrawLine(front, center - right);
                Handles.DrawLine(center - right, center + right);
            }
            else if (trigger.type == SplineTrigger.Type.Forward)
            {
                center -= result.direction * size * 0.06f;
                Vector3 front = center + result.direction * size * 0.2f;
                Handles.DrawLine(center + right, front);
                Handles.DrawLine(front, center - right);
                Handles.DrawLine(center - right, center + right);
            }
            else
            {
                center += result.direction * size * 0.025f;
                Vector3 front = center + result.direction * size * 0.17f;
                Handles.DrawLine(center + right, front);
                Handles.DrawLine(front, center - right);
                Handles.DrawLine(center - right, center + right);
                center -= result.direction * size * 0.05f;
                front   = center - result.direction * size * 0.17f;
                Handles.DrawLine(center + right, front);
                Handles.DrawLine(front, center - right);
                Handles.DrawLine(center - right, center + right);
            }
            right = Vector3.Cross(cam.transform.position - result.position, result.direction).normalized *size * 0.25f;
            Handles.DrawLine(result.position + right / 2f, result.position + right);
            Handles.DrawLine(result.position - right / 2f, result.position - right);

            Vector3 lastPos = result.position;

            Handles.color   = new Color(Handles.color.r, Handles.color.g, Handles.color.b, 0.5f);
            result.position = Handles.FreeMoveHandle(result.position, Quaternion.LookRotation(cam.transform.position - result.position), size * 0.2f, Vector3.zero, Handles.CircleCap);
            if (result.position != lastPos)
            {
                double projected = user.address.Project(result.position);
                trigger.position = projected;
            }
            Handles.color = Color.white;
            return(buttonClick);
        }
        public override void OnInspectorGUI()
        {
            BaseGUI();
            SplineFollower user = (SplineFollower)target;

            user.followMode = (SplineFollower.FollowMode)EditorGUILayout.EnumPopup("Follow mode", user.followMode);
            user.wrapMode   = (SplineFollower.Wrap)EditorGUILayout.EnumPopup("Wrap mode", user.wrapMode);
            GUI.color       = Color.white;

            user.findStartPoint = EditorGUILayout.Toggle("Find Start Point", user.findStartPoint);
            if (!user.findStartPoint)
            {
                user.startPercent = EditorGUILayout.Slider("Start percent", (float)user.startPercent, (float)user.clipFrom, (float)user.clipTo);
            }

            user.autoFollow = EditorGUILayout.Toggle("Auto follow", user.autoFollow);
            if (user.autoFollow)
            {
                if (user.followMode == SplineFollower.FollowMode.Uniform)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(20));
                    user.followSpeed = EditorGUILayout.FloatField("Follow speed", user.followSpeed);
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(20));
                    user.followDuration = EditorGUILayout.FloatField("Follow duration", user.followDuration);
                    EditorGUILayout.EndHorizontal();
                }
            }
            user.direction = (Spline.Direction)EditorGUILayout.EnumPopup("Direction", user.direction);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyPosition = EditorGUILayout.Toggle("Apply position", user.applyPosition);
            EditorGUILayout.EndHorizontal();
            if (user.applyPosition)
            {
                user.offset = EditorGUILayout.Vector2Field("Offset", user.offset);
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyRotation = EditorGUILayout.Toggle("Apply rotation", user.applyRotation);
            EditorGUILayout.EndHorizontal();

            if (user.applyRotation)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(40));
                user.applyDirectionRotation = EditorGUILayout.Toggle("Apply follow direction", user.applyDirectionRotation);
                EditorGUILayout.EndHorizontal();
                user.rotationOffset = EditorGUILayout.Vector3Field("Rotation Offset", user.rotationOffset);
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyScale = EditorGUILayout.Toggle("Apply scale", user.applyScale);
            EditorGUILayout.EndHorizontal();

            if (user.applyScale)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(40));
                user.baseScale = EditorGUILayout.Vector3Field("Base scale", user.baseScale);
                EditorGUILayout.EndHorizontal();
            }

            if (GUI.changed && !Application.isPlaying && user.computer != null)
            {
                if (!user.findStartPoint)
                {
                    SplineResult result = GetFollowResult(user, user.startPercent);
                    if (user.autoFollow)
                    {
                        if (user.applyPosition)
                        {
                            user.transform.position = result.position;
                        }
                        if (user.applyRotation)
                        {
                            float dir = 1;
                            if (user.applyDirectionRotation)
                            {
                                dir = user.followSpeed > 0 ? 1f : -1f;
                            }
                            user.transform.rotation = Quaternion.LookRotation(result.direction * dir, result.normal);
                        }
                        if (user.applyScale)
                        {
                            user.transform.localScale = user.baseScale * result.size;
                        }
                    }
                    else
                    {
                        SceneView.RepaintAll();
                    }
                }
            }



            triggerFoldout = EditorGUILayout.Foldout(triggerFoldout, "Triggers");
            if (triggerFoldout)
            {
                int lastTrigger = trigger;
                SplineEditorGUI.TriggerArray(ref user.triggers, ref trigger);
                if (lastTrigger != trigger)
                {
                    Repaint();
                }
            }
        }
        private void Main()
        {
            Rect barRect = new Rect(0f, 0f, Screen.width, 45 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHovers = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                SplineEditorGUI.Label(new Rect(Screen.width / 2f - 200f, 10, 400, 30), "Editing unavailable outside of morph states.");
                return;
            }
            if (computer.hasMorph)
            {
                if (editor.tool == SplineEditor.PointTool.Create || editor.tool == SplineEditor.PointTool.Delete)
                {
                    editor.tool = SplineEditor.PointTool.None;
                }
            }
            else
            {
                if (SplineEditorGUI.BigButton(new Rect(5 * scale, 5 * scale, 35 * scale, 35 * scale), addButtonContent, true, editor.tool == SplineEditor.PointTool.Create))
                {
                    editor.ToggleCreateTool();
                }
                if (SplineEditorGUI.BigButton(new Rect(45 * scale, 5 * scale, 35 * scale, 35 * scale), removeButtonContent, computer.pointCount > 0, editor.tool == SplineEditor.PointTool.Delete))
                {
                    if (editor.tool != SplineEditor.PointTool.Delete)
                    {
                        editor.tool = SplineEditor.PointTool.Delete;
                    }
                    else
                    {
                        editor.tool = SplineEditor.PointTool.None;
                    }
                }
                if (SplineEditorGUI.BigButton(new Rect(85 * scale, 5 * scale, 35 * scale, 35 * scale), presetButtonContent, true, presetWindow != null))
                {
                    if (presetWindow == null)
                    {
                        presetWindow = EditorWindow.GetWindow <PresetsWindow>();
                        presetWindow.init(editor, "Primitives & Presets", new Vector3(200, 200));
                    }
                }
            }

            if (SplineEditorGUI.BigButton(new Rect(150 * scale, 5 * scale, 35 * scale, 35 * scale), moveButtonContent, true, editor.tool == SplineEditor.PointTool.Move))
            {
                if (editor.tool != SplineEditor.PointTool.Move)
                {
                    editor.ToggleMoveTool();
                }
                else
                {
                    editor.tool = SplineEditor.PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(190 * scale, 5 * scale, 35 * scale, 35 * scale), rotateButtonContent, true, editor.tool == SplineEditor.PointTool.Rotate))
            {
                if (editor.tool != SplineEditor.PointTool.Rotate)
                {
                    editor.ToggleRotateTool();
                }
                else
                {
                    editor.tool = SplineEditor.PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(230 * scale, 5 * scale, 35 * scale, 35 * scale), scaleButtonContent, true, editor.tool == SplineEditor.PointTool.Scale))
            {
                if (editor.tool != SplineEditor.PointTool.Scale)
                {
                    editor.ToggleScaleTool();
                }
                else
                {
                    editor.tool = SplineEditor.PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(270 * scale, 5 * scale, 35 * scale, 35 * scale), normalsButtonContent, true, editor.tool == SplineEditor.PointTool.NormalEdit))
            {
                if (editor.tool != SplineEditor.PointTool.NormalEdit)
                {
                    editor.tool = SplineEditor.PointTool.NormalEdit;
                }
                else
                {
                    editor.tool = SplineEditor.PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(330 * scale, 5 * scale, 35 * scale, 35 * scale), mirrorButtonContent, computer.pointCount > 0 || editor.InMirrorMode(), editor.InMirrorMode()))
            {
                if (editor.InMirrorMode())
                {
                    editor.ExitMirrorMode();
                }
                else
                {
                    editor.EnterMirrorMode();
                }
            }

            if (SplineEditorGUI.BigButton(new Rect(370 * scale, 5 * scale, 35 * scale, 35 * scale), mergeButtonContent, computer.pointCount > 0 && !computer.isClosed, editor.InMergeMode()))
            {
                if (editor.InMergeMode())
                {
                    editor.ExitMergeMode();
                }
                else
                {
                    editor.EnterMergeMode();
                }
            }

            int           operation = 0;
            List <string> options   = new List <string>();

            options.Add("Operations");
            if (editor.selectedPointsCount > 0)
            {
                options.Add("Center to Transform");
                options.Add("Move Transform to");
            }
            if (editor.selectedPointsCount >= 2)
            {
                options.Add("Flat X");
                options.Add("Flat Y");
                options.Add("Flat Z");
                options.Add("Mirror X");
                options.Add("Mirror Y");
                options.Add("Mirror Z");
            }
            if (editor.selectedPointsCount >= 3)
            {
                options.Add("Distribute evenly");
            }
            bool hover = SplineEditorGUI.DropDown(new Rect(Screen.width - (190 * scale + 100), 10 * scale, 150 * scale, 25 * scale), SplineEditorGUI.defaultButton, options.ToArray(), editor.HasSelection(), ref operation);

            if (hover)
            {
                mouseHovers = true;
            }
            if (operation > 0)
            {
                if (operation == 1 && editor.selectedPointsCount > 0)
                {
                    editor.CenterSelection();
                }
                else if (operation == 2 && editor.selectedPointsCount > 0)
                {
                    editor.MoveTransformToSelection();
                }
                if (editor.selectedPointsCount >= 2)
                {
                    if (operation <= 5)
                    {
                        editor.FlatSelection(operation - 3);
                    }
                    else if (operation <= 8)
                    {
                        editor.MirrorSelection(operation - 6);
                    }
                    else if (operation == 9)
                    {
                        editor.DistributeEvenly();
                    }
                }
            }
            GUI.color = SplineEditorGUI.activeColor;
            ((SplineComputer)editor.target).editorPathColor = EditorGUI.ColorField(new Rect(Screen.width - (30 * scale + 100), 13 * scale, 40 * scale, 20 * scale), ((SplineComputer)editor.target).editorPathColor);
        }
        private void Create(int verticalOffset)
        {
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHovers = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            SplineEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 105 * scale, 25 * scale), "Place method:", true);
            bool hover = SplineEditorGUI.DropDown(new Rect(115 * scale, verticalOffset + 5 * scale, 140 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Camera Plane", "Insert", "Surface", "Plane-X", "Plane-Y", "Plane-Z" }, true, ref editor.createPointMode);

            if (hover)
            {
                mouseHovers = true;
            }
            SplineEditorGUI.Label(new Rect(280 * scale, verticalOffset + 5 * scale, 135 * scale, 25 * scale), "Normal orientation:", true);
            hover = SplineEditorGUI.DropDown(new Rect(420 * scale, verticalOffset + 5 * scale, 160 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Auto", "Look at Camera", "Align with Camera", "Calculate", "Left", "Right", "Up", "Down", "Forward", "Back" }, true, ref editor.createNormalMode);
            if (hover)
            {
                mouseHovers = true;
            }
            SplineEditorGUI.Label(new Rect(575 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Add Node", true);
            editor.createNodeOnCreatePoint = GUI.Toggle(new Rect(670 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), editor.createNodeOnCreatePoint, "");

            bool showNormalField = false;

            if (editor.createPointMode == 0)
            {
                SplineEditorGUI.Label(new Rect(700 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Far plane:", true);
                showNormalField = true;
            }


            if (editor.createPointMode == 2)
            {
                SplineEditorGUI.Label(new Rect(700 * scale, verticalOffset + 5 * scale, 100 * scale, 30 * scale), "Normal offset:", true);
                showNormalField = true;
            }

            if (editor.createPointMode >= 3 && editor.createPointMode <= 5)
            {
                SplineEditorGUI.Label(new Rect(700 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Grid offset:", true);
                showNormalField = true;
            }
            minWidth = 790;
            if (editor.createPointMode != 1)
            {
                SplineEditorGUI.Label(new Rect(850 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Append:", true);
                if (SplineEditorGUI.DropDown(new Rect(940 * scale, verticalOffset + 5 * scale, 120 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "End", "Beginning" }, true, ref editor.appendMode))
                {
                    mouseHovers = true;
                }
                minWidth = 1100;
            }


            if (showNormalField)
            {
                editor.createPointOffset = SplineEditorGUI.FloatField(new Rect(790 * scale, verticalOffset + 5 * scale, 70 * scale, 25 * scale), editor.createPointOffset);
                editor.createPointOffset = SplineEditorGUI.FloatDrag(new Rect(700 * scale, verticalOffset + 5 * scale, 80 * scale, 25 * scale), editor.createPointOffset);
                if (editor.createPointOffset < 0f && editor.createPointMode < 3)
                {
                    editor.createPointOffset = 0f;
                }
            }
        }
        private void CreateToolbar(int verticalOffset)
        {
            Rect barRect = new Rect(0f, verticalOffset, Screen.width, 35 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;
            DreamteckEditorGUI.Label(new Rect(5 * scale, verticalOffset + 5 * scale, 105 * scale, 25 * scale), "Place method:", true);
            bool hover = SplineEditorGUI.DropDown(new Rect(110 * scale, verticalOffset + 5 * scale, 130 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Camera Plane", "Insert", "Surface", "X Plane", "Y Plane", "Z Plane" }, true, ref createPointMode);

            if (hover)
            {
                mouseHoversToolbar = true;
            }
            DreamteckEditorGUI.Label(new Rect(220 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), "Normal:", true);
            hover = SplineEditorGUI.DropDown(new Rect(320 * scale, verticalOffset + 5 * scale, 160 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "Auto", "Look at Camera", "Align with Camera", "Calculate", "Left", "Right", "Up", "Down", "Forward", "Back" }, true, ref createNormalMode);
            if (hover)
            {
                mouseHoversToolbar = true;
            }
            DreamteckEditorGUI.Label(new Rect(800 * scale, verticalOffset + 5 * scale, 90 * scale, 25 * scale), "Add Node", true);
            createNodeOnCreatePoint = GUI.Toggle(new Rect(890 * scale, verticalOffset + 10 * scale, 25 * scale, 25 * scale), createNodeOnCreatePoint, "");

            bool showNormalField = false;

            if (createPointMode >= 3 && createPointMode <= 5)
            {
                DreamteckEditorGUI.Label(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Grid offset:", true);
                showNormalField = true;
            }
            else if (createPointMode == 2)
            {
                DreamteckEditorGUI.Label(new Rect(480 * scale, verticalOffset + 5 * scale, 100 * scale, 30 * scale), "Normal offset:", true);
                showNormalField = true;
                if (SplineEditorGUI.Button(new Rect(925 * scale, verticalOffset * scale + 5, 95 * scale, 25 * scale), "LayerMask"))
                {
                    LayermaskWindow maskWindow = EditorWindow.GetWindow <LayermaskWindow>(true);
                    maskWindow.position = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 10, 10);
                    maskWindow.Init(this, new Vector2(150, 30), new Vector2(150, 30));
                }
            }
            else if (createPointMode == 0)
            {
                DreamteckEditorGUI.Label(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Far plane:", true);
                showNormalField = true;
            }

            if (showNormalField)
            {
                createPointOffset = SplineEditorGUI.FloatField(new Rect(580 * scale, verticalOffset + 5 * scale, 50 * scale, 25 * scale), createPointOffset);
                createPointOffset = SplineEditorGUI.FloatDrag(new Rect(500 * scale, verticalOffset + 5 * scale, 80 * scale, 25 * scale), createPointOffset);
                if (createPointOffset < 0f && createPointMode < 3)
                {
                    createPointOffset = 0f;
                }
            }

            minWidth = 790;
            if (createPointMode != 1)
            {
                DreamteckEditorGUI.Label(new Rect(625 * scale, verticalOffset + 5 * scale, 80 * scale, 30 * scale), "Append:", true);
                if (SplineEditorGUI.DropDown(new Rect(705 * scale, verticalOffset + 5 * scale, 100 * scale, 25 * scale), SplineEditorGUI.defaultButton, new string[] { "End", "Beginning" }, true, ref appendMode))
                {
                    mouseHoversToolbar = true;
                }
                minWidth = 1100;
            }
        }
        private void Main()
        {
            Rect barRect = new Rect(0f, 0f, Screen.width, 45 * scale);

            if (barRect.Contains(Event.current.mousePosition))
            {
                mouseHoversToolbar = true;
            }
            GUI.color = new Color(1f, 1f, 1f, 0.3f);
            GUI.Box(barRect, "", SplineEditorGUI.whiteBox);
            GUI.color = SplineEditorGUI.activeColor;

            if (computer.hasMorph && !MorphWindow.editShapeMode)
            {
                DreamteckEditorGUI.Label(new Rect(Screen.width / 2f - 200f, 10, 400, 30), "Editing unavailable outside of morph states.");
                return;
            }
            if (computer.hasMorph)
            {
                if (tool == PointTool.Create || tool == PointTool.Delete)
                {
                    tool = PointTool.None;
                }
            }
            else
            {
                if (SplineEditorGUI.BigButton(new Rect(5 * scale, 5 * scale, 35 * scale, 35 * scale), addButtonContent, true, tool == PointTool.Create))
                {
                    ToggleCreateTool();
                }
                if (SplineEditorGUI.BigButton(new Rect(45 * scale, 5 * scale, 35 * scale, 35 * scale), removeButtonContent, computer.pointCount > 0, tool == PointTool.Delete))
                {
                    if (tool != PointTool.Delete)
                    {
                        tool = PointTool.Delete;
                    }
                    else
                    {
                        tool = PointTool.None;
                    }
                }
                if (SplineEditorGUI.BigButton(new Rect(85 * scale, 5 * scale, 35 * scale, 35 * scale), presetButtonContent, true, presetWindow != null))
                {
                    if (presetWindow == null)
                    {
                        presetWindow = EditorWindow.GetWindow <PresetsWindow>(true);
                        presetWindow.Init(this, Vector2.zero, new Vector2(350, 20 * 22));
                    }
                }
            }

            if (SplineEditorGUI.BigButton(new Rect(150 * scale, 5 * scale, 35 * scale, 35 * scale), moveButtonContent, true, tool == PointTool.Move))
            {
                if (tool != PointTool.Move)
                {
                    ToggleMoveTool();
                }
                else
                {
                    tool = PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(190 * scale, 5 * scale, 35 * scale, 35 * scale), rotateButtonContent, true, tool == PointTool.Rotate))
            {
                if (tool != PointTool.Rotate)
                {
                    ToggleRotateTool();
                }
                else
                {
                    tool = PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(230 * scale, 5 * scale, 35 * scale, 35 * scale), scaleButtonContent, true, tool == PointTool.Scale))
            {
                if (tool != PointTool.Scale)
                {
                    ToggleScaleTool();
                }
                else
                {
                    tool = PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(270 * scale, 5 * scale, 35 * scale, 35 * scale), normalsButtonContent, !computer.is2D, tool == PointTool.NormalEdit))
            {
                if (tool != PointTool.NormalEdit)
                {
                    tool = PointTool.NormalEdit;
                }
                else
                {
                    tool = PointTool.None;
                }
            }
            if (SplineEditorGUI.BigButton(new Rect(330 * scale, 5 * scale, 35 * scale, 35 * scale), mirrorButtonContent, computer.pointCount > 0 || InMirrorMode(), InMirrorMode()))
            {
                if (InMirrorMode())
                {
                    ExitMirrorMode();
                }
                else
                {
                    EnterMirrorMode();
                }
            }

            if (SplineEditorGUI.BigButton(new Rect(370 * scale, 5 * scale, 35 * scale, 35 * scale), mergeButtonContent, computer.pointCount > 0 && !computer.isClosed, InMergeMode()))
            {
                if (InMergeMode())
                {
                    ExitMergeMode();
                }
                else
                {
                    EnterMergeMode();
                }
            }

            if (SplineEditorGUI.BigButton(new Rect(410 * scale, 5 * scale, 35 * scale, 35 * scale), splitButtonContent, computer.pointCount > 0 && !computer.isClosed, InSplitMode()))
            {
                if (InSplitMode())
                {
                    ExitSplitMode();
                }
                else
                {
                    EnterSplitMode();
                }
            }
            int   operation          = 0;
            float operationsPosition = Screen.width - (190 * scale + 100);

#if UNITY_EDITOR_OSX
            operationsPosition = 430 * scale;
#endif

            bool hover = SplineEditorGUI.DropDown(new Rect(operationsPosition, 10 * scale, 150 * scale, 25 * scale), SplineEditorGUI.defaultButton, operations, HasSelection(), ref operation);
            if (hover)
            {
                mouseHoversToolbar = true;
            }
            if (selectedPointsCount > 0)
            {
                switch (operation)
                {
                case 1: CenterSelection(); break;

                case 2: MoveTransformToSelection(); break;

                case 3: FlatSelection(0); break;

                case 4: FlatSelection(1); break;

                case 5: FlatSelection(2); break;

                case 6: MirrorSelection(0); break;

                case 7: MirrorSelection(1); break;

                case 8: MirrorSelection(2); break;

                case 9: DistributeEvenly(); break;

                case 10: EditorWindow.GetWindow <RelaxWindow>(true).Init(this, new Vector2(250, 90)); break;
                }
            }
            GUI.color = SplineEditorGUI.activeColor;
            ((SplineComputer)target).editorPathColor = EditorGUI.ColorField(new Rect(operationsPosition + 160 * scale, 13 * scale, 40 * scale, 20 * scale), ((SplineComputer)target).editorPathColor);
        }
Example #30
0
        void RenderConnections()
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            scroll = EditorGUILayout.BeginScrollView(scroll, GUI.skin.box, GUILayout.Width(EditorGUIUtility.currentViewWidth - 30), GUILayout.Height(Mathf.Min(75 + connections.Length * 20, 200)));
            EditorGUILayout.LabelField("Connections");
            EditorGUILayout.Space();

            if (connections.Length > 0)
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(connections[i].computer.name + " at point " + (connections[i].pointIndex + 1));
                    if (GUILayout.Button("Select", GUILayout.Width(70)))
                    {
                        Selection.activeGameObject = connections[i].computer.gameObject;
                    }
                    if (GUILayout.Button("x", GUILayout.Width(20)))
                    {
                        Undo.RecordObject(node, "Remove connection");
                        Undo.RecordObject(connections[i].computer, "Remove node");
                        node.RemoveConnection(connections[i].computer, connections[i].pointIndex);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Drag & Drop SplineComputers here to link their points.", MessageType.Info);
            }

            EditorGUILayout.EndScrollView();

            Rect rect = GUILayoutUtility.GetLastRect();

            SplineComputer[] addComps;
            SplineComputer   lastComp = addComp;
            bool             dragged  = SplineEditorGUI.DropArea <SplineComputer>(rect, out addComps);

            if (dragged && addComps.Length > 0)
            {
                SelectComputer(addComps[0]);
            }
            if (lastComp != addComp)
            {
                SceneView.RepaintAll();
            }

            node.transformNormals  = EditorGUILayout.Toggle("Transform Normals", node.transformNormals);
            node.transformSize     = EditorGUILayout.Toggle("Transform Size", node.transformSize);
            node.transformTangents = EditorGUILayout.Toggle("Transform Tangents", node.transformTangents);

            EditorGUI.BeginChangeCheck();
            if (connections.Length > 1)
            {
                node.type = (Node.Type)EditorGUILayout.EnumPopup("Node type", node.type);
            }
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
                node.UpdateConnectedComputers();
            }
        }