Example #1
0
        public override void DrawInspector()
        {
            base.DrawInspector();
            if (Event.current.type == EventType.MouseUp)
            {
                GetSplineLength();
            }

            spline.editorPathColor = EditorGUILayout.ColorField("Color in Scene", spline.editorPathColor);
            bool lastAlwaysDraw = spline.alwaysDraw;

            spline.alwaysDraw = EditorGUILayout.Toggle("Always Draw Spline", spline.alwaysDraw);
            if (lastAlwaysDraw != spline.alwaysDraw)
            {
                if (spline.alwaysDraw)
                {
                    DSSplineDrawer.RegisterComputer(spline);
                }
                else
                {
                    DSSplineDrawer.UnregisterComputer(spline);
                }
            }
            spline.drawThinckness = EditorGUILayout.Toggle("Draw thickness", spline.drawThinckness);
            if (spline.drawThinckness)
            {
                EditorGUI.indentLevel++;
                spline.billboardThickness = EditorGUILayout.Toggle("Always face camera", spline.billboardThickness);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Samples: " + spline.samples.Length + "\n\r" + "Length: " + length, MessageType.Info);
        }
Example #2
0
        void OnEnable()
        {
            splines = new SplineComputer[targets.Length];
            for (int i = 0; i < splines.Length; i++)
            {
                splines[i] = (SplineComputer)targets[i];
                splines[i].EditorAwake();
                if (splines[i].alwaysDraw)
                {
                    DSSplineDrawer.RegisterComputer(splines[i]);
                }
            }
            spline = splines[0];
            InitializeSplineEditor();
            InitializeComputerEditor();
            debugEditor                    = new SplineDebugEditor(spline);
            debugEditor.undoHandler       += RecordUndo;
            debugEditor.repaintHandler    += OnRepaint;
            triggersEditor                 = new SplineTriggersEditor(spline);
            triggersEditor.undoHandler    += RecordUndo;
            triggersEditor.repaintHandler += OnRepaint;
            hold = false;
#if UNITY_2019_1_OR_NEWER
            SceneView.beforeSceneGui += BeforeSceneGUI;
#else
            SceneView.onSceneGUIDelegate += BeforeSceneGUI;
#endif
            Undo.undoRedoPerformed += UndoRedoPerformed;
        }
Example #3
0
 void OnScene(SceneView current)
 {
     for (int i = 0; i < imported.Count; i++)
     {
         DSSplineDrawer.DrawSplineComputer(imported[i]);
     }
 }
Example #4
0
        public override void DrawScene()
        {
            base.DrawScene();
            if (spline.isClosed)
            {
                return;
            }
            Camera editorCamera = SceneView.currentDrawingSceneView.camera;

            for (int i = 0; i < availableMergeComputers.Length; i++)
            {
                DSSplineDrawer.DrawSplineComputer(availableMergeComputers[i]);
                SplinePoint startPoint = availableMergeComputers[i].GetPoint(0);
                SplinePoint endPoint   = availableMergeComputers[i].GetPoint(availableMergeComputers[i].pointCount - 1);
                Handles.color = availableMergeComputers[i].editorPathColor;

                if (SplineEditorHandles.CircleButton(startPoint.position, Quaternion.LookRotation(editorCamera.transform.position - startPoint.position), HandleUtility.GetHandleSize(startPoint.position) * 0.15f, 1f, availableMergeComputers[i].editorPathColor))
                {
                    Merge(i, MergeSide.Start);
                    break;
                }
                if (SplineEditorHandles.CircleButton(endPoint.position, Quaternion.LookRotation(editorCamera.transform.position - endPoint.position), HandleUtility.GetHandleSize(endPoint.position) * 0.15f, 1f, availableMergeComputers[i].editorPathColor))
                {
                    Merge(i, MergeSide.End);
                    break;
                }
            }
            Handles.color = Color.white;
        }
Example #5
0
 void OnScene(SceneView current)
 {
     for (int i = 0; i < collections.Count; i++)
     {
         if (collections[i].spline != null)
         {
             DSSplineDrawer.DrawSplineComputer(collections[i].spline);
         }
     }
 }
Example #6
0
        protected override void OnSceneGUI()
        {
            base.OnSceneGUI();
            SurfaceGenerator user = (SurfaceGenerator)target;

            if (user.extrudeSpline != null)
            {
                DSSplineDrawer.DrawSplineComputer(user.extrudeSpline, 0.0, 1.0, 0.5f);
            }
        }
Example #7
0
 void OnScene(SceneView current)
 {
     if (selected.Count > 1)
     {
         for (int i = 0; i < selected.Count; i++)
         {
             if (!sceneSplines[selected[i]].alwaysDraw)
             {
                 DSSplineDrawer.DrawSplineComputer(sceneSplines[selected[i]]);
             }
         }
     }
 }
Example #8
0
        protected virtual void OnSceneGUI()
        {
            if (doRebuild)
            {
                DoRebuild();
            }
            SplineUser user = (SplineUser)target;

            if (user == null)
            {
                return;
            }
            if (user.spline != null)
            {
                SplineComputer        rootComputer = user.GetComponent <SplineComputer>();
                List <SplineComputer> allComputers = user.spline.GetConnectedComputers();
                for (int i = 0; i < allComputers.Count; i++)
                {
                    if (allComputers[i] == rootComputer && _editIndex == -1)
                    {
                        continue;
                    }
                    if (allComputers[i].alwaysDraw)
                    {
                        continue;
                    }
                    DSSplineDrawer.DrawSplineComputer(allComputers[i], 0.0, 1.0, 0.4f);
                }
                DSSplineDrawer.DrawSplineComputer(user.spline);
            }
            if (_editIndex == 0)
            {
                SceneClipEdit();
            }
            if (offsetModifierEditor != null)
            {
                offsetModifierEditor.DrawScene();
            }
            if (rotationModifierEditor != null)
            {
                rotationModifierEditor.DrawScene();
            }
            if (colorModifierEditor != null)
            {
                colorModifierEditor.DrawScene();
            }
            if (sizeModifierEditor != null)
            {
                sizeModifierEditor.DrawScene();
            }
        }
Example #9
0
        void ApplyPoints()
        {
            if (originalPoints.Count != imported.Count)
            {
                return;
            }
            if (imported.Count == 0)
            {
                return;
            }
            Quaternion lookRot = Quaternion.identity;

            switch (importAxis)
            {
            case Axis.X: lookRot = Quaternion.LookRotation(Vector3.right); break;

            case Axis.Y: lookRot = Quaternion.LookRotation(Vector3.down); break;

            case Axis.Z: lookRot = Quaternion.LookRotation(Vector3.forward); break;
            }
            for (int i = 0; i < imported.Count; i++)
            {
                SplinePoint[] transformed = new SplinePoint[originalPoints[i].Length];
                originalPoints[i].CopyTo(transformed, 0);
                for (int j = 0; j < transformed.Length; j++)
                {
                    transformed[j].position *= scaleFactor;
                    transformed[j].tangent  *= scaleFactor;
                    transformed[j].tangent2 *= scaleFactor;

                    transformed[j].position = lookRot * transformed[j].position;
                    transformed[j].tangent  = lookRot * transformed[j].tangent;
                    transformed[j].tangent2 = lookRot * transformed[j].tangent2;
                    transformed[j].normal   = lookRot * transformed[j].normal;
                }
                imported[i].SetPoints(transformed);
                if (alwaysDraw)
                {
                    DSSplineDrawer.RegisterComputer(imported[i]);
                }
                else
                {
                    DSSplineDrawer.UnregisterComputer(imported[i]);
                }
            }
            SceneView.RepaintAll();
        }
Example #10
0
        public override void DrawScene()
        {
            bool   change       = false;
            Camera editorCamera = SceneView.currentDrawingSceneView.camera;

            for (int i = 0; i < spline.pointCount; i++)
            {
                Vector3 pos = spline.GetPointPosition(i);
                if (SplineEditorHandles.CircleButton(pos, Quaternion.LookRotation(editorCamera.transform.position - pos), HandleUtility.GetHandleSize(pos) * 0.12f, 1f, spline.editorPathColor))
                {
                    SplitAtPoint(i);
                    change = true;
                    break;
                }
            }
            SplineSample projected = spline.Evaluate(ProjectMouse());

            if (!change)
            {
                float   pointValue = (float)projected.percent * (spline.pointCount - 1);
                int     pointIndex = Mathf.FloorToInt(pointValue);
                float   size       = HandleUtility.GetHandleSize(projected.position) * 0.3f;
                Vector3 up         = Vector3.Cross(editorCamera.transform.forward, projected.forward).normalized *size + projected.position;
                Vector3 down       = Vector3.Cross(projected.forward, editorCamera.transform.forward).normalized *size + projected.position;
                Handles.color = spline.editorPathColor;
                Handles.DrawLine(up, down);
                Handles.color = Color.white;
                if (pointValue - pointIndex > spline.moveStep)
                {
                    if (SplineEditorHandles.CircleButton(projected.position, Quaternion.LookRotation(editorCamera.transform.position - projected.position), HandleUtility.GetHandleSize(projected.position) * 0.12f, 1f, spline.editorPathColor))
                    {
                        SplitAtPercent(projected.percent);
                        change = true;
                    }
                }
                SceneView.RepaintAll();
            }
            Handles.color = Color.white;
            DSSplineDrawer.DrawSplineComputer(spline, 0.0, projected.percent, 1f);
            DSSplineDrawer.DrawSplineComputer(spline, projected.percent, 1.0, 0.4f);
        }
Example #11
0
        public override void DrawScene()
        {
            base.DrawScene();
            if (drawComputer)
            {
                for (int i = 0; i < splines.Length; i++)
                {
                    DSSplineDrawer.DrawSplineComputer(splines[i]);
                }
            }
            if (drawConnectedComputers)
            {
                for (int i = 0; i < splines.Length; i++)
                {
                    List <SplineComputer> computers = splines[i].GetConnectedComputers();
                    for (int j = 1; j < computers.Count; j++)
                    {
                        DSSplineDrawer.DrawSplineComputer(computers[j], 0.0, 1.0, 0.5f);
                    }
                }
            }



            if (pathEditor.currentModule == null)
            {
                switch (transformTool)
                {
                case 1:
                    for (int i = 0; i < splines.Length; i++)
                    {
                        Vector3 position = splines[i].transform.position;
                        position = Handles.PositionHandle(position, splines[i].transform.rotation);
                        if (position != splines[i].transform.position)
                        {
                            RecordUndo("Move spline computer");
                            Undo.RecordObject(splines[i].transform, "Move spline computer");
                            splines[i].transform.position = position;
                            splines[i].SetPoints(pathEditor.points);
                            pathEditor.Refresh();
                        }
                    }
                    break;

                case 2:
                    for (int i = 0; i < splines.Length; i++)
                    {
                        Quaternion rotation = splines[i].transform.rotation;
                        rotation = Handles.RotationHandle(rotation, splines[i].transform.position);
                        if (rotation != splines[i].transform.rotation)
                        {
                            RecordUndo("Rotate spline computer");
                            Undo.RecordObject(splines[i].transform, "Rotate spline computer");
                            splines[i].transform.rotation = rotation;
                            splines[i].SetPoints(pathEditor.points);
                            pathEditor.Refresh();
                        }
                    }
                    break;

                case 3:
                    for (int i = 0; i < splines.Length; i++)
                    {
                        Vector3 scale = splines[i].transform.localScale;
                        scale = Handles.ScaleHandle(scale, splines[i].transform.position, splines[i].transform.rotation,
                                                    HandleUtility.GetHandleSize(splines[i].transform.position));
                        if (scale != splines[i].transform.localScale)
                        {
                            RecordUndo("Scale spline computer");
                            Undo.RecordObject(splines[i].transform, "Scale spline computer");
                            splines[i].transform.localScale = scale;
                            splines[i].SetPoints(pathEditor.points);
                            pathEditor.Refresh();
                        }
                    }
                    break;
                }
                if (transformTool > 0)
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        Vector2 screenPosition = HandleUtility.WorldToGUIPoint(splines[i].transform.position);
                        screenPosition.y += 20f;
                        Handles.BeginGUI();
                        DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + splines[i].name.Length * 4, screenPosition.y, 120, 25), splines[i].name);
                        Handles.EndGUI();
                    }
                }
            }
            if (module >= 0 && module < modules.Length)
            {
                modules[module].DrawScene();
            }
        }
Example #12
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);
                    DreamteckEditorGUI.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)
                {
                    DSSplineDrawer.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 #13
0
        protected virtual void OnSceneGUI()
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            for (int i = 0; i < connections.Length; i++)
            {
                DSSplineDrawer.DrawSplineComputer(connections[i].spline, 0.0, 1.0, 0.5f);
            }

            bool update = false;

            if (position != node.transform.position)
            {
                position = node.transform.position;
                update   = true;
            }
            if (scale != node.transform.localScale)
            {
                scale  = node.transform.localScale;
                update = true;
            }
            if (rotation != node.transform.rotation)
            {
                rotation = node.transform.rotation;
                update   = true;
            }
            if (update)
            {
                node.UpdateConnectedComputers();
            }

            if (addComp == null)
            {
                if (connections.Length > 0)
                {
                    bool bezier = false;
                    for (int i = 0; i < connections.Length; i++)
                    {
                        if (connections[i].spline == null)
                        {
                            continue;
                        }
                        if (connections[i].spline.type == Spline.Type.Bezier)
                        {
                            bezier = true;
                            continue;
                        }
                    }
                    if (bezier && node.type == Node.Type.Smooth)
                    {
                        if (connections[0].spline != null)
                        {
                            SplinePoint point = node.GetPoint(0, true);
                            Handles.DrawDottedLine(node.transform.position, point.tangent, 6f);
                            Handles.DrawDottedLine(node.transform.position, point.tangent2, 6f);
                            Vector3 lastPos  = point.tangent;
                            bool    setPoint = false;
                            point.SetTangentPosition(Handles.PositionHandle(point.tangent, node.transform.rotation));
                            if (lastPos != point.tangent)
                            {
                                setPoint = true;
                            }
                            lastPos = point.tangent2;
                            point.SetTangent2Position(Handles.PositionHandle(point.tangent2, node.transform.rotation));
                            if (lastPos != point.tangent2)
                            {
                                setPoint = true;
                            }

                            if (setPoint)
                            {
                                node.SetPoint(0, point, true);
                                node.UpdateConnectedComputers();
                            }
                        }
                    }
                }
                return;
            }
            SplinePoint[] points       = addComp.GetPoints();
            Transform     camTransform = SceneView.currentDrawingSceneView.camera.transform;

            DSSplineDrawer.DrawSplineComputer(addComp, 0.0, 1.0, 0.5f);
            TextAnchor originalAlignment = GUI.skin.label.alignment;
            Color      originalColor     = GUI.skin.label.normal.textColor;

            GUI.skin.label.alignment        = TextAnchor.MiddleCenter;
            GUI.skin.label.normal.textColor = addComp.editorPathColor;
            for (int i = 0; i < availablePoints.Length; i++)
            {
                if (addComp.isClosed && i == points.Length - 1)
                {
                    break;
                }

                Handles.Label(points[i].position + Camera.current.transform.up * HandleUtility.GetHandleSize(points[i].position) * 0.3f, (i + 1).ToString());
                if (SplineEditorHandles.CircleButton(points[availablePoints[i]].position, Quaternion.LookRotation(-camTransform.forward, camTransform.up), HandleUtility.GetHandleSize(points[availablePoints[i]].position) * 0.1f, 2f, addComp.editorPathColor))
                {
                    AddConnection(addComp, availablePoints[i]);
                    break;
                }
            }
            GUI.skin.label.alignment        = originalAlignment;
            GUI.skin.label.normal.textColor = originalColor;
        }
Example #14
0
        public override void Draw(Rect rect)
        {
            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (Event.current.button == 0)
                {
                    mouseLeft = true;
                }
                break;

            case EventType.MouseUp: if (Event.current.button == 0)
                {
                    mouseLeft = false;
                }
                break;
            }

            Rect lastRect;

            scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(rect.width), GUILayout.Height(rect.height));
            EditorGUILayout.BeginHorizontal(normalRow);
            EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(rect.width - 200));
            EditorGUILayout.LabelField("Color", EditorStyles.boldLabel, GUILayout.Width(65));
            EditorGUILayout.LabelField("Draw", EditorStyles.boldLabel, GUILayout.Width(40));
            EditorGUILayout.LabelField("Thickness", EditorStyles.boldLabel, GUILayout.Width(60));
            EditorGUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            for (int i = 0; i < sceneSplines.Count; i++)
            {
                bool isSelected = selected.Contains(i);
                if (isSelected)
                {
                    GUI.backgroundColor = SplinePrefs.highlightColor;
                }

                EditorGUILayout.BeginHorizontal(isSelected ? selectedRow : normalRow);
                EditorGUILayout.LabelField(sceneSplines[i].name, isSelected ? selectedRow : normalRow, GUILayout.Width(rect.width - 200));
                GUI.backgroundColor = Color.white;
                Color pathColor = sceneSplines[i].editorPathColor;
                pathColor = EditorGUILayout.ColorField(pathColor, GUILayout.Width(65));
                if (pathColor != sceneSplines[i].editorPathColor)
                {
                    foreach (int index in selected)
                    {
                        sceneSplines[index].editorPathColor = pathColor;
                    }
                }
                bool alwaysDraw = sceneSplines[i].alwaysDraw;
                alwaysDraw = EditorGUILayout.Toggle(alwaysDraw, GUILayout.Width(40));
                if (alwaysDraw != sceneSplines[i].alwaysDraw)
                {
                    foreach (int index in selected)
                    {
                        if (alwaysDraw)
                        {
                            DSSplineDrawer.RegisterComputer(sceneSplines[index]);
                        }
                        else
                        {
                            DSSplineDrawer.UnregisterComputer(sceneSplines[index]);
                        }
                    }
                }
                bool thickness = sceneSplines[i].drawThinckness;
                thickness = EditorGUILayout.Toggle(thickness, GUILayout.Width(40));
                if (thickness != sceneSplines[i].drawThinckness)
                {
                    foreach (int index in selected)
                    {
                        sceneSplines[index].drawThinckness = thickness;
                    }
                }
                EditorGUILayout.EndHorizontal();
                lastRect = GUILayoutUtility.GetLastRect();
                if (mouseLeft)
                {
                    if (lastRect.Contains(Event.current.mousePosition))
                    {
                        if (Event.current.control)
                        {
                            if (!selected.Contains(i))
                            {
                                selected.Add(i);
                            }
                        }
                        else if (selected.Count > 0 && Event.current.shift)
                        {
                            int closest = selected[0];
                            int delta   = sceneSplines.Count;
                            for (int j = 0; j < selected.Count; j++)
                            {
                                int d = Mathf.Abs(i - selected[j]);
                                if (d < delta)
                                {
                                    delta   = d;
                                    closest = selected[j];
                                }
                            }
                            if (closest < i)
                            {
                                for (int j = closest + 1; j <= i; j++)
                                {
                                    if (selected.Contains(j))
                                    {
                                        continue;
                                    }
                                    selected.Add(j);
                                }
                            }
                            else
                            {
                                for (int j = closest - 1; j >= i; j--)
                                {
                                    if (selected.Contains(j))
                                    {
                                        continue;
                                    }
                                    selected.Add(j);
                                }
                            }
                        }
                        else
                        {
                            selected = new List <int>(new int[] { i });
                        }
                        List <GameObject> selectGo = new List <GameObject>();
                        foreach (int index in selected)
                        {
                            selectGo.Add(sceneSplines[index].gameObject);
                        }
                        Selection.objects = selectGo.ToArray();
                        Repaint();
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
            EditorGUILayout.EndScrollView();
            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (selected.Count > 0)
                    {
                        selected = new List <int>(new int[] { selected[0] });
                    }
                    else
                    {
                        selected[0]++;
                    }
                }
                else if (Event.current.keyCode == KeyCode.UpArrow)
                {
                    if (selected.Count > 0)
                    {
                        selected = new List <int>(new int[] { selected[selected.Count - 1] });
                    }
                    else
                    {
                        selected[0]++;
                    }
                }
                if (selected.Count == 0)
                {
                    return;
                }
                if (selected[0] < 0)
                {
                    selected[0] = sceneSplines.Count - 1;
                }
                if (selected[0] >= sceneSplines.Count)
                {
                    selected[0] = 0;
                }
                if (sceneSplines.Count > 0)
                {
                    Selection.activeGameObject = sceneSplines[selected[0]].gameObject;
                }
            }
        }