Пример #1
0
 public void DrawToolbar()
 {
     if (Screen.width < minWidth)
     {
         scale = (float)Screen.width / minWidth;
     }
     else
     {
         scale = 1f;
     }
     SplineEditorGUI.SetScale(scale);
     DreamteckEditorGUI.SetScale(scale);
     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 override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            spline = (SplineComputer)target;
            Undo.RecordObject(spline, "Edit Points");

            if (splines.Length == 1)
            {
                SplineEditorGUI.BeginContainerBox(ref pathEditor.open, "Edit");
                if (pathEditor.open)
                {
                    SplineEditor.Space lastSpace = pathEditor.space;
                    pathEditor.DrawInspector();
                    if (lastSpace != pathEditor.space)
                    {
                        SplinePrefs.pointEditSpace = (SplineComputer.Space)pathEditor.space;
                        SplinePrefs.SavePrefs();
                    }
                }
                else if (pathEditor.lastEditorTool != Tool.None && Tools.current == Tool.None)
                {
                    Tools.current = pathEditor.lastEditorTool;
                }
                SplineEditorGUI.EndContainerBox();
            }

            SplineEditorGUI.BeginContainerBox(ref computerEditor.open, "Spline Computer");
            if (computerEditor.open)
            {
                computerEditor.DrawInspector();
            }
            SplineEditorGUI.EndContainerBox();

            if (splines.Length == 1)
            {
                SplineEditorGUI.BeginContainerBox(ref triggersEditor.open, "Triggers");
                if (triggersEditor.open)
                {
                    triggersEditor.DrawInspector();
                }
                SplineEditorGUI.EndContainerBox();

                SplineEditorGUI.BeginContainerBox(ref debugEditor.open, "Editor Properties");
                if (debugEditor.open)
                {
                    debugEditor.DrawInspector();
                }
                SplineEditorGUI.EndContainerBox();
            }

            if (GUI.changed)
            {
                if (spline.isClosed)
                {
                    pathEditor.points[pathEditor.points.Length - 1] = pathEditor.points[0];
                }
                EditorUtility.SetDirty(spline);
            }
        }
Пример #3
0
        public bool EditButton(bool selected)
        {
            float width = 40f;

            editButtonContent.image = ResourceUtility.EditorLoadTexture("Splines/Editor/Icons", "edit_cursor");
            if (editButtonContent.image != null)
            {
                editButtonContent.text = "";
                width = 25f;
            }
            if (SplineEditorGUI.EditorLayoutSelectableButton(editButtonContent, true, selected, GUILayout.Width(width)))
            {
                SceneView.RepaintAll();
                return(true);
            }
            return(false);
        }
Пример #4
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))
                {
                    for (int i = 0; i < generators.Length; i++)
                    {
                        generators[i].Unbake();
                        EditorUtility.SetDirty(generators[i]);
                    }
                }
                return;
            }
            base.OnInspectorGUI();
        }
Пример #5
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();
            }
            SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor);
            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();
        }
Пример #6
0
        void ConnectionsGUI()
        {
            Node node = (Node)target;

            Node.Connection[] connections = node.GetConnections();
            EditorGUILayout.Space();

            if (connections.Length > 0)
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(connections[i].spline.name + " at point " + (connections[i].pointIndex + 1));
                    if (GUILayout.Button("Select", GUILayout.Width(70)))
                    {
                        Selection.activeGameObject = connections[i].spline.gameObject;
                    }
                    SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor);
                    if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent("Swap Tangents"), connections[i].spline.type == Spline.Type.Bezier, connections[i].invertTangents))
                    {
                        connections[i].invertTangents = !connections[i].invertTangents;
                        node.UpdateConnectedComputers();
                        SceneView.RepaintAll();
                    }

                    if (GUILayout.Button("x", GUILayout.Width(20)))
                    {
                        Undo.RecordObject(node, "Remove connection");
                        Undo.RecordObject(connections[i].spline, "Remove node");
                        connections[i].spline.DisconnectNode(connections[i].pointIndex);
                        node.RemoveConnection(connections[i].spline, connections[i].pointIndex);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Drag & Drop SplineComputers here to link their points.", MessageType.Info);
            }
        }
Пример #7
0
        public override void DrawInspector()
        {
            base.DrawInspector();
            if (spline == null)
            {
                return;
            }
            SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUI.BeginChangeCheck();
            operationsToolbar.SetContent(0, new GUIContent(spline.isClosed ? "Break" : "Close"));
            operationsToolbar.SetContent(1, new GUIContent("Reverse"));
            operationsToolbar.SetContent(2, new GUIContent(spline.is2D ? "3D Mode" : "2D Mode"));
            operationsToolbar.Draw(ref operation);
            //operation = GUILayout.Toolbar(operation, new string[] { , "Reverse", text2D }, GUILayout.Width(220f));
            if (EditorGUI.EndChangeCheck())
            {
                PerformOperation();
            }
            EditorGUI.BeginChangeCheck();
            if (splines.Length == 1)
            {
                int mod = module;
                utilityToolbar.Draw(ref mod);
                if (EditorGUI.EndChangeCheck())
                {
                    ToggleModule(mod);
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            if (module >= 0 && module < modules.Length)
            {
                modules[module].DrawInspector();
            }
            EditorGUILayout.Space();
            DreamteckEditorGUI.DrawSeparator();

            EditorGUILayout.Space();

            serializedObject.Update();
            SerializedProperty splineProperty            = serializedObject.FindProperty("spline");
            SerializedProperty sampleRate                = serializedObject.FindProperty("spline").FindPropertyRelative("sampleRate");
            SerializedProperty type                      = serializedObject.FindProperty("spline").FindPropertyRelative("type");
            SerializedProperty linearAverageDirection    = splineProperty.FindPropertyRelative("linearAverageDirection");
            SerializedProperty space                     = serializedObject.FindProperty("_space");
            SerializedProperty sampleMode                = serializedObject.FindProperty("_sampleMode");
            SerializedProperty optimizeAngleThreshold    = serializedObject.FindProperty("_optimizeAngleThreshold");
            SerializedProperty updateMode                = serializedObject.FindProperty("updateMode");
            SerializedProperty rebuildOnAwake            = serializedObject.FindProperty("rebuildOnAwake");
            SerializedProperty multithreaded             = serializedObject.FindProperty("multithreaded");
            SerializedProperty customNormalInterpolation = splineProperty.FindPropertyRelative("customNormalInterpolation");
            SerializedProperty customValueInterpolation  = splineProperty.FindPropertyRelative("customValueInterpolation");

            EditorGUI.BeginChangeCheck();
            Spline.Type lastType = (Spline.Type)type.intValue;
            EditorGUILayout.PropertyField(type);
            if (lastType == Spline.Type.CatmullRom && type.intValue == (int)Spline.Type.Bezier)
            {
                if (EditorUtility.DisplayDialog("Hermite to Bezier", "Would you like to retain the Catmull Rom shape in Bezier mode?", "Yes", "No"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].CatToBezierTangents();
                    }

                    serializedObject.Update();
                    pathEditor.Refresh();
                }
            }
            if (spline.type == Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(linearAverageDirection);
            }
            int lastSpace = space.intValue;

            EditorGUILayout.PropertyField(space, new GUIContent("Space"));
            EditorGUILayout.PropertyField(sampleMode, new GUIContent("Sample Mode"));
            if (sampleMode.intValue == (int)SplineComputer.SampleMode.Optimized)
            {
                EditorGUILayout.PropertyField(optimizeAngleThreshold);
            }
            EditorGUILayout.PropertyField(updateMode);
            if (updateMode.intValue == (int)SplineComputer.UpdateMode.None && Application.isPlaying)
            {
                if (GUILayout.Button("Rebuild"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].RebuildImmediate(true, true);
                    }
                }
            }
            if (spline.type != Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(sampleRate, new GUIContent("Sample Rate"));
            }
            EditorGUILayout.PropertyField(rebuildOnAwake);
            EditorGUILayout.PropertyField(multithreaded);

            EditorGUI.indentLevel++;
            bool curveUpdate = false;

            interpolationFoldout = EditorGUILayout.Foldout(interpolationFoldout, "Point Value Interpolation");
            if (interpolationFoldout)
            {
                if (customValueInterpolation.animationCurveValue == null || customValueInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Size & Color Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0, 0, 0));
                        curve.AddKey(new Keyframe(1, 1, 0, 0));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customValueInterpolation, new GUIContent("Size & Color Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customValueInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (customNormalInterpolation.animationCurveValue == null || customNormalInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Normal Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0));
                        curve.AddKey(new Keyframe(1, 1));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customNormalInterpolation, new GUIContent("Normal Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customNormalInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck() || curveUpdate)
            {
                if (sampleRate.intValue < 2)
                {
                    sampleRate.intValue = 2;
                }
                if (lastSpace != space.intValue)
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].space = (SplineComputer.Space)space.intValue;
                    }
                    serializedObject.Update();
                    if (splines.Length == 1)
                    {
                        pathEditor.Refresh();
                    }
                }
                serializedObject.ApplyModifiedProperties();
                for (int i = 0; i < splines.Length; i++)
                {
                    splines[i].Rebuild(true);
                }
            }


            if (pathEditor.currentModule != null)
            {
                transformTool = 0;
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Edit Transform");
            GUILayout.FlexibleSpace();
            int lastTool = transformTool;

            transformToolbar.Draw(ref transformTool);
            if (lastTool != transformTool && transformTool > 0)
            {
                pathEditor.UntoggleCurrentModule();
            }
            EditorGUILayout.EndHorizontal();
        }
Пример #8
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            Node node = (Node)target;

            if (nodes.Length == 1)
            {
                if (addComp != null)
                {
                    string[] pointNames = new string[availablePoints.Length];
                    for (int i = 0; i < pointNames.Length; i++)
                    {
                        pointNames[i] = "Point " + (availablePoints[i] + 1);
                    }
                    if (availablePoints.Length > 0)
                    {
                        addPoint = EditorGUILayout.Popup("Link point", addPoint, pointNames);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("No Points Available");
                    }

                    if (GUILayout.Button("Cancel"))
                    {
                        addComp  = null;
                        addPoint = 0;
                    }
                    if (addPoint >= 0 && availablePoints.Length > addPoint)
                    {
                        if (node.HasConnection(addComp, availablePoints[addPoint]))
                        {
                            EditorGUILayout.HelpBox("Connection already exists (" + addComp.name + "," + availablePoints[addPoint], MessageType.Error);
                        }
                        else if (GUILayout.Button("Link"))
                        {
                            AddConnection(addComp, availablePoints[addPoint]);
                        }
                    }
                }
                else
                {
                    SplineEditorGUI.BeginContainerBox(ref connectionsOpen, "Connections");
                    if (connectionsOpen)
                    {
                        ConnectionsGUI();
                    }
                    SplineEditorGUI.EndContainerBox();

                    Rect             rect = GUILayoutUtility.GetLastRect();
                    SplineComputer[] addComps;
                    SplineComputer   lastComp = addComp;
                    bool             dragged  = DreamteckEditorGUI.DropArea <SplineComputer>(rect, out addComps);
                    if (dragged && addComps.Length > 0)
                    {
                        SelectComputer(addComps[0]);
                    }

                    if (lastComp != addComp)
                    {
                        SceneView.RepaintAll();
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Connection UI not available when multiple Nodes are selected.", MessageType.Info);
            }

            SplineEditorGUI.BeginContainerBox(ref settingsOpen, "Settings");
            if (settingsOpen)
            {
                SettingsGUI();
            }
            SplineEditorGUI.EndContainerBox();
        }