Exemple #1
0
        void CustomPathUI()
        {
            LevelSegment segment = (LevelSegment)target;

            showCustomPaths = EditorGUILayout.Foldout(showCustomPaths, "Custom Paths (" + segment.customPaths.Length + ")");
            if (showCustomPaths)
            {
                Undo.RecordObject(segment, "Edit Custom Paths");
                if (segment.type == LevelSegment.Type.Custom)
                {
                    if (laneIndices.Length != segment.customPaths.Length + 1)
                    {
                        laneIndices = new int[segment.customPaths.Length + 1];
                        laneNames   = new string[segment.customPaths.Length + 1];
                    }
                    laneIndices[0] = -1;
                    laneNames[0]   = "None";
                    for (int i = 0; i < segment.customPaths.Length; i++)
                    {
                        laneNames[i + 1]   = (i + 1) + " - " + segment.customPaths[i].name;
                        laneIndices[i + 1] = i;
                    }
                    segment.customMainPath = EditorGUILayout.IntPopup("Main Path", segment.customMainPath, laneNames, laneIndices);
                }

                input.Update();
                GUI.backgroundColor = DreamteckEditorGUI.lightColor;
                for (int i = 0; i < segment.customPaths.Length; i++)
                {
                    GUILayout.BeginVertical(boxStyle);
                    EditorGUILayout.BeginHorizontal();
                    segment.customPaths[i].color = EditorGUILayout.ColorField(segment.customPaths[i].color, GUILayout.Width(40));
                    if (renameCustomPath == i)
                    {
                        if (input.enterDown)
                        {
                            input.Use();
                            renameCustomPath = -1;
                        }
                        segment.customPaths[i].name = EditorGUILayout.TextField(segment.customPaths[i].name);
                    }
                    else
                    {
                        GUIStyle style = i == segment.customMainPath ? EditorStyles.boldLabel : EditorStyles.label;
                        EditorGUILayout.LabelField(segment.customPaths[i].name, style);
                    }
                    EditorGUILayout.EndHorizontal();
                    Rect lastRect = GUILayoutUtility.GetLastRect();

                    if (input.mouseRightDown)
                    {
                        if (lastRect.Contains(Event.current.mousePosition))
                        {
                            int         index = i;
                            GenericMenu menu  = new GenericMenu();
                            menu.AddItem(new GUIContent("Close"), false, delegate { selectedPath = -1; pathEditor = null; Repaint(); SceneView.RepaintAll(); });
                            menu.AddItem(new GUIContent("Rename"), false, delegate { renameCustomPath = index; Repaint(); SceneView.RepaintAll(); });
                            menu.AddItem(new GUIContent("Duplicate"), false, delegate { ArrayUtility.Insert(ref segment.customPaths, index + 1, segment.customPaths[index].Copy()); Repaint(); SceneView.RepaintAll(); });
                            menu.AddSeparator("");
                            if (i == 0)
                            {
                                menu.AddDisabledItem(new GUIContent("Move Up"));
                            }
                            else
                            {
                                menu.AddItem(new GUIContent("Move Up"), false, delegate {
                                    LevelSegment.LevelSegmentPath temp = segment.customPaths[index];
                                    segment.customPaths[index]         = segment.customPaths[index - 1];
                                    segment.customPaths[index - 1]     = temp;
                                    if (selectedPath == index)
                                    {
                                        selectedPath--;
                                    }
                                    Repaint();
                                    SceneView.RepaintAll();
                                });
                            }
                            if (i == segment.customPaths.Length - 1)
                            {
                                menu.AddDisabledItem(new GUIContent("Move Down"));
                            }
                            else
                            {
                                menu.AddItem(new GUIContent("Move Down"), false, delegate {
                                    LevelSegment.LevelSegmentPath temp = segment.customPaths[index];
                                    segment.customPaths[index]         = segment.customPaths[index + 1];
                                    segment.customPaths[index + 1]     = temp;
                                    if (selectedPath == index)
                                    {
                                        selectedPath++;
                                    }
                                    Repaint();
                                    SceneView.RepaintAll();
                                });
                            }
                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Delete"), false, delegate { segment.RemoveCustomPath(index); selectedPath = -1; pathEditor = null; Repaint(); SceneView.RepaintAll(); });
                            menu.ShowAsContext();
                        }
                    }
                    if (selectedPath == i && pathEditor != null)
                    {
                        EditorGUILayout.Space();
                        pathEditor.DrawInspector();
                    }
                    GUILayout.EndVertical();
                    lastRect = GUILayoutUtility.GetLastRect();

                    if (input.mouseLeftDown)
                    {
                        if (lastRect.Contains(Event.current.mousePosition))
                        {
                            selectedPath = i;
                            pathEditor   = new LevelSegmentCustomPathEditor(this, segment, segment.customPaths[i]);
                            Repaint();
                            SceneView.RepaintAll();
                        }
                    }
                }
                GUI.backgroundColor = Color.white;
                if (GUILayout.Button("Add Path"))
                {
                    segment.AddCustomPath("Lane " + (segment.customPaths.Length + 1));
                    Repaint();
                    SceneView.RepaintAll();
                }
            }
            else
            {
                renameCustomPath = -1;
                selectedPath     = -1;
                if (pathEditor != null)
                {
                    pathEditor.Close();
                }
                pathEditor = null;
            }
        }
Exemple #2
0
        public void DrawEditor()
        {
            input.Update();
            if (!guiInitialized)
            {
                defaultBoxStyle = new GUIStyle(GUI.skin.box);
                defaultBoxStyle.normal.background = DreamteckEditorGUI.blankImage;
                defaultBoxStyle.margin            = new RectOffset(0, 0, 0, 0);
                defaultButtonStyle = new GUIStyle(GUI.skin.button);
                defaultButtonStyle.normal.background = buttonNormal;
                defaultButtonStyle.normal.textColor  = DreamteckEditorGUI.iconColor;
                defaultButtonStyle.hover.background  = buttonHover;
                defaultButtonStyle.hover.textColor   = DreamteckEditorGUI.highlightContentColor;
                defaultButtonStyle.margin            = new RectOffset(2, 2, 2, 2);
                thumbnailLabel = new GUIStyle(GUI.skin.label);
                thumbnailLabel.normal.textColor = DreamteckEditorGUI.lightColor;
                thumbnailLabel.fontSize         = 10;
                thumbnailLabel.alignment        = TextAnchor.MiddleCenter;
                headerToggle = new GUIStyle(GUI.skin.toggle);
                headerToggle.normal.textColor = Color.white;
                guiInitialized = true;
            }


            if (sequenceAddress.Count > 0)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("<", GUILayout.Width(35)))
                {
                    sequenceAddress.RemoveAt(sequenceAddress.Count - 1);
                }
                GUIContent content = new GUIContent(undoObject.name);
                float      min = 0f, max = 0f;
                GUI.skin.label.CalcMinMaxWidth(content, out min, out max);
                GUILayout.Label(undoObject.name, GUILayout.Width(min));
                for (int i = 0; i < sequenceAddress.Count; i++)
                {
                    content = new GUIContent("/ " + sequenceAddress[i].name);
                    GUI.skin.label.CalcMinMaxWidth(content, out min, out max);
                    GUILayout.Label(content, GUILayout.Width(min));
                }
                EditorGUILayout.EndHorizontal();
            }
            scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(viewRect.width), GUILayout.Height(viewRect.height));
            if (sequenceAddress.Count == 0)
            {
                for (int i = 0; i < sequences.Length; i++)
                {
                    SequenceUI(sequences[i]);
                }

                if (GUILayout.Button("Add Sequence", GUILayout.Width(100), GUILayout.Height(50)))
                {
                    SegmentSequence[] newSequence = new SegmentSequence[sequences.Length + 1];
                    sequences.CopyTo(newSequence, 0);
                    newSequence[newSequence.Length - 1] = new SegmentSequence();
                    sequences = newSequence;
                    if (onApplySequences != null)
                    {
                        onApplySequences(sequences);
                    }
                }
            }
            else
            {
                SequenceUI(sequenceAddress[sequenceAddress.Count - 1]);
            }
            GUILayout.EndScrollView();

            if (changeDefinition != null && !changeDefinition.nested)
            {
                EditorGUI.DrawRect(segmentPanelRect, Color.white);
                GUILayout.BeginArea(segmentPanelRect);
                GameObject last = changeDefinition.prefab;
                last = (GameObject)EditorGUILayout.ObjectField(last, typeof(GameObject), false);
                if (last != changeDefinition.prefab)
                {
                    if (onWillChange != null)
                    {
                        onWillChange();
                    }
                    changeDefinition.prefab = last;
                    changed = true;
                }
                GUILayout.EndArea();
                if (input.mouseLeftDown && !segmentPanelRect.Contains(Event.current.mousePosition))
                {
                    changeDefinition = null;
                }
                else if (input.mouseLeftDown)
                {
                    input.Use();
                }
            }

            if (dragIndex >= 0)
            {
                changed = true;
                if (input.mouseLeftUp)
                {
                    dragIndex    = -1;
                    segmentArray = null;
                }
                else
                {
                    GUI.color = new Color(1f, 1f, 1f, 0.75f);
                    float dragSize = thumbnailSize * 0.75f;
                    DrawDefinition(new Rect(Event.current.mousePosition.x - dragSize * 0.5f + dragOffset.x, Event.current.mousePosition.y - dragSize * 0.5f + dragOffset.y, dragSize, dragSize), editSequence.segments[dragIndex]);
                    GUI.color = Color.white;
                    if (dragOffset.magnitude > 0.05f)
                    {
                        dragOffset = Vector2.Lerp(dragOffset, Vector2.zero, 0.1f);
                        changed    = true;
                    }
                }
            }
        }