Beispiel #1
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 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);
        }
Beispiel #3
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();
        }
        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();
            }
        }
Beispiel #5
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 (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent("Swap Tangents"), connections[i].computer.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].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();
            }
        }
Beispiel #6
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();
        }
Beispiel #7
0
        void Primitives()
        {
            if (primitives == null)
            {
                return;
            }
            EditorGUILayout.BeginHorizontal();
            scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(position.width * 0.35f), GUILayout.MaxHeight(10 * 22));
            for (int i = 0; i < primitives.Length; i++)
            {
                if (SplineEditorGUI.EditorLayoutSelectableButton(new GUIContent(primitives[i].GetName()), true, primitiveIndex == i))
                {
                    Undo.RecordObject(this, "PresetsWindow state");
                    Undo.RecordObject(computer, "Spline state");
                    if (primitiveIndex >= 0 && primitiveIndex < primitives.Length)
                    {
                        primitives[primitiveIndex].Close();
                    }
                    primitiveIndex = i;
                    primitives[i].Open();
                    primitives[i].origin = GetOrigin((SplineComputer)editor.target);
                    presetIndex          = -1;
                }
            }
            EditorGUILayout.EndScrollView();



            if (primitiveIndex >= 0 && primitiveIndex < primitives.Length)
            {
                EditorGUILayout.BeginVertical();
                primitives[primitiveIndex].Draw();
                ((SplineEditor)editor).Refresh();
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Save"))
                {
                    Undo.RecordObject(this, "PresetsWindow state");
                    Undo.RecordObject(computer, "Spline state");
                    primitiveIndex = -1;
                    this.Close();
                }

                if (GUILayout.Button("Cancel"))
                {
                    Undo.RecordObject(this, "PresetsWindow state");
                    Undo.RecordObject(computer, "Spline state");
                    primitives[primitiveIndex].Close();
                    primitiveIndex = -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();
            }
            EditorGUILayout.EndHorizontal();
        }