コード例 #1
0
    public void DrawWindow(ref int num, ref Rect rect, ref float h)
    {
        DialogPhrase phrase = parentNode.phrase;

        windowRect = new Rect(rect.x, rect.y + h + 112, rect.width, 100);
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Del", new GUILayoutOption[] { GUILayout.Width(45), GUILayout.Height(100) }))
        {
            EditorGUI.FocusTextInControl("");
            DeleteNode(ref num);
            return;
        }
        GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(45) });
        GUILayout.FlexibleSpace();
        if (num > 0)
        {
            if (GUILayout.Button("Up"))
            {
                EditorGUI.FocusTextInControl("");
                phrase.chooses.Insert(num - 1, choose);
                phrase.chooses.RemoveAt(num + 1);
                parentNode.chooseNodes.Insert(num - 1, this);
                parentNode.chooseNodes.RemoveAt(num + 1);
            }
        }
        if (num < phrase.chooses.Count - 1)
        {
            if (GUILayout.Button("Down"))
            {
                EditorGUI.FocusTextInControl("");
                phrase.chooses.Insert(num + 2, choose);
                phrase.chooses.RemoveAt(num);
                parentNode.chooseNodes.Insert(num + 2, this);
                parentNode.chooseNodes.RemoveAt(num);
            }
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
        SerializedObject soChoose = new SerializedObject(choose);

        GUILayout.BeginVertical();
        EditorGUILayout.PropertyField(soChoose.FindProperty("type"), GUIContent.none, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
        if (choose.type == ChooseType.CONTINUE)
        {
            GUILayout.FlexibleSpace();
        }
        else
        {
            choose.chooseText = EditorGUILayout.TextArea(choose.chooseText, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(35) });
        }
        GUILayout.BeginHorizontal();
        GUILayout.Label(string.Format("Conditions: {0}", choose.conditions.Count));
        GUILayout.Label(string.Format("Effects: {0}", choose.effects.Count));
        choose.isOnce = GUILayout.Toggle(choose.isOnce, "isOnse");
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Next Phrase ->"))
        {
            DialogPhraseNode dialogPhraseNode = DialogEditor.editor.CreatePhrase(new Vector2(parentNode.windowRect.xMax + 40, parentNode.windowRect.yMin + num * (20 + 170)), null);
            dialogPhraseNode.phrase.speekerType = phrase.speekerType;
            dialogPhraseNode.phrase.speeker     = phrase.speeker;
            DialogLinkNode linkNode = CreateLinkNode(null);
            DialogEditor.editor.selectLink = null;
            DialogEditor.editor.linkMod    = false;
            linkNode.SetOutput(dialogPhraseNode);
        }
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.EndVertical();
        rect.height += windowRect.height;
        h           += windowRect.height;
        soChoose.ApplyModifiedProperties();
    }
コード例 #2
0
    private void Control()
    {
        Event e = Event.current;

        mousePos = e.mousePosition;
        int select = -1;

        if (e.button == 0)
        {
            if (e.type == EventType.MouseDown)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].windowRect.Contains(mousePos))
                    {
                        select = nodes[i].id;
                        Selection.activeGameObject = nodes[i].phrase.gameObject;
                        foreach (DialogChooseNode chooseNode in nodes[i].chooseNodes)
                        {
                            if (chooseNode.windowRect.Contains(mousePos))
                            {
                                Selection.activeGameObject = chooseNode.choose.gameObject;
                                break;
                            }
                        }
                        break;
                    }
                }
                if (select == -1)
                {
                    for (int i = 0; i < links.Count; i++)
                    {
                        if (links[i].windowRect.Contains(mousePos))
                        {
                            Selection.activeGameObject = links[i].link.gameObject;
                            select = links[i].id;
                            break;
                        }
                    }
                }
                if (select == -1)
                {
                    Selection.activeGameObject = dialog.gameObject;
                }
            }
            else if (e.type == EventType.MouseUp)
            {
                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].windowRect.Contains(mousePos))
                    {
                        select = nodes[i].id;
                        break;
                    }
                }

                if (linkMod)
                {
                    if (select != -1)
                    {
                        DialogPhraseNode dialogPhraseNode = null;
                        foreach (DialogPhraseNode node in nodes)
                        {
                            if (node.id == select)
                            {
                                dialogPhraseNode = node;
                                break;
                            }
                        }
                        selectLink.SetOutput(dialogPhraseNode);
                        linkMod = false;
                        Selection.activeGameObject = selectLink.link.gameObject;
                        selectLink = null;
                    }
                    else
                    {
                        selectLink.DeleteLink();
                        linkMod    = false;
                        selectLink = null;
                    }
                }
            }
        }
        else if (e.button == 1)
        {
            if (e.type == EventType.MouseDown)
            {
            }
            else if (e.type == EventType.MouseDrag)
            {
                if (moveMod)
                {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        nodes[i].phrase.nodePosition.position += e.delta;
                    }
                }
                else if (e.delta != Vector2.zero)
                {
                    moveMod = true;
                }
            }
            else if (e.type == EventType.MouseUp)
            {
                if (moveMod)
                {
                    moveMod = false;
                }
                else if (!linkMod)
                {
                    for (int i = 0; i < nodes.Count; i++)
                    {
                        if (nodes[i].windowRect.Contains(mousePos))
                        {
                            select = nodes[i].id;
                            break;
                        }
                    }
                    if (select == -1)
                    {
                        for (int i = 0; i < links.Count; i++)
                        {
                            if (links[i].windowRect.Contains(mousePos))
                            {
                                select = links[i].id;
                                break;
                            }
                        }
                    }
                    if (select == -1)
                    {
                        GenericMenu menuWindow = new GenericMenu();
                        menuWindow.AddItem(new GUIContent("Create new phrase"), false, ContextCallback, "createPhrase");
                        menuWindow.AddSeparator("");
                        menuWindow.AddItem(new GUIContent("Save dialog"), false, ContextCallback, "saveDialog");
                        menuWindow.ShowAsContext();
                        e.Use();
                    }
                    else
                    {
                        foreach (DialogPhraseNode node in nodes)
                        {
                            if (node.windowRect.Contains(mousePos))
                            {
                                GenericMenu menuWindow = new GenericMenu();
                                if (node.id == select && node.chooseOpen)
                                {
                                    foreach (DialogChooseNode chooseNode in node.chooseNodes)
                                    {
                                        if (chooseNode.windowRect.Contains(mousePos))
                                        {
                                            menuWindow.AddItem(new GUIContent("Add link"), false, ContextCallback, string.Format("link_{0}_{1}", node.id, chooseNode.id));
                                            menuWindow.AddSeparator("");
                                            break;
                                        }
                                    }
                                }
                                menuWindow.AddItem(new GUIContent("Set started phrase"), false, ContextCallback, "startPhrase");
                                menuWindow.AddSeparator("");
                                menuWindow.AddItem(new GUIContent("Delete phrase"), false, ContextCallback, "deletePhrase");
                                menuWindow.ShowAsContext();
                                e.Use();
                                break;
                            }
                        }
                        foreach (DialogLinkNode link in links)
                        {
                            if (link.windowRect.Contains(mousePos))
                            {
                                GenericMenu menuWindow = new GenericMenu();
                                menuWindow.AddItem(new GUIContent("Delete link"), false, ContextCallback, "deleteLink");
                                menuWindow.ShowAsContext();
                                e.Use();
                                break;
                            }
                        }
                    }
                }
            }
        }
    }