示例#1
0
        int FindDialogueNodeIndexByDialogueText(DialogueText dialogueText)
        {
            int size = dialogueNodesProp.arraySize;

            for (int i = 0; i < size; i++)
            {
                SerializedProperty dialogueTextProp = dialogueNodesProp.GetArrayElementAtIndex(i).FindPropertyRelative("m_dialogueText");
                DialogueText       t = (DialogueText)dialogueTextProp.objectReferenceValue;
                if (t == dialogueText)
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#2
0
        void Add(ReorderableList l, DialogueText dialogueText)
        {
            int index = l.serializedProperty.arraySize;

            l.serializedProperty.arraySize++;
            // Highlight new item
            l.index = index;

            SerializedProperty element = l.serializedProperty.GetArrayElementAtIndex(index);

            element.FindPropertyRelative("m_dialogueText").objectReferenceValue = dialogueText;
            element.FindPropertyRelative("m_options").arraySize = 0;
            element.FindPropertyRelative("m_nexts").arraySize   = 0;
            element.FindPropertyRelative("m_finalNext").objectReferenceValue = null;
        }
示例#3
0
        void EmitDialogueTextEnd(DialogueText dialogueText)
        {
            m_OnDialogueTextEnd.Invoke(dialogueText);

            if (OnDialogueTextEnd != null)
            {
                OnDialogueTextEnd.Invoke(this, new DialogueTextEventArgs()
                {
                    dialogueText = dialogueText
                });
            }

            foreach (DialogueHandler dialogueHandler in m_dialogueHandlers)
            {
                dialogueHandler.HandleDialogueTextEnd(dialogueText);
            }
        }
示例#4
0
        float GetDialogueNodeElementHeight(int index)
        {
            float height = 2 + DialogueTextRefFieldHeight;

            // Handle delete intermediate elements by code
            if (index >= dialogueNodeReorderableList.serializedProperty.arraySize)
            {
                return(0);
            }

            SerializedProperty element          = dialogueNodeReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty dialogueTextProp = element.FindPropertyRelative("m_dialogueText");
            DialogueText       dialogueText     = (DialogueText)dialogueTextProp.objectReferenceValue;

            if (dialogueText != null)
            {
                height += 2 + DialogueTextAreaFieldHeight;
            }

            SerializedProperty assignmentsProp = element.FindPropertyRelative("m_assignments");
            VariableAssignmentReorderableList variableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(assignmentsProp, "Change Variables");

            height += variableAssignmentReorderableList.GetHeight();

            height += EditorGUIUtility.singleLineHeight + 2;

            SerializedProperty optionsProp = element.FindPropertyRelative("m_options");

            for (int i = 0; i < optionsProp.arraySize; i++)
            {
                SerializedProperty optionProp            = optionsProp.GetArrayElementAtIndex(i);
                SerializedProperty optionAssignmentsProp = optionProp.FindPropertyRelative("m_assignments");
                VariableAssignmentReorderableList optionVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(optionAssignmentsProp, "Change Variables");
                height += optionVariableAssignmentReorderableList.GetHeight() + 2;
            }
            height += (2 + DialogueTextRefFieldHeight) * optionsProp.arraySize + 2 + ButtonRowHeight;

            SerializedProperty nextsProp = element.FindPropertyRelative("m_nexts");

            height += m_dialogueNodeNextListPropertyDrawer.GetHeight(nextsProp) + 2;

            height += 4;

            return(height);
        }
        public void Setup()
        {
            GameObject gameObject = new GameObject("Dialogue Controller Object");

            m_dialogueController = gameObject.AddComponent <DialogueController>();
            m_dialogueController.OnDialogueBegin += (sender, args) => {
                m_currentDialogue = args.dialogue;
            };
            m_dialogueController.OnDialogueEnd += (sender, args) => {
                m_currentDialogueText = null;
                m_currentDialogue     = null;
            };
            m_dialogueController.OnDialogueTextBegin += (sender, args) => {
                m_currentDialogueText = args.dialogueText.text;
            };
            m_dialogueController.OnDialogueTextEnd += (sender, args) => {
                m_currentDialogueText = null;
            };

            /* Setup */
            Dialogue dialogue = ScriptableObject.CreateInstance <Dialogue>();

            m_dialogue = dialogue;
            BoolVariable boolVariable1 = ScriptableObject.CreateInstance <BoolVariable>();
            DialogueText beginText     = ScriptableObject.CreateInstance <DialogueText>();

            Utils.ExecuteSetter(beginText, "m_text", (textProp) => {
                textProp.stringValue = "Begin Text";
            });
            Utils.ExecuteSetter(dialogue, "m_finalBeginText", (finalBeginTextProp) => {
                finalBeginTextProp.objectReferenceValue = beginText;
            });
            Utils.ExecuteSetter(dialogue, "m_dialogueVariables", (dialogueVariablesProp) => {
                Utils.ExecuteSetterArrayAutoIncrementReset(dialogueVariablesProp, null, (dialogueVariableProp) => {
                    Utils.ExecuteSetter(dialogueVariableProp, "m_variable", (variableProp) => {
                        variableProp.objectReferenceValue = boolVariable1;
                    });
                    Utils.ExecuteSetter(dialogueVariableProp, "m_boolValue", (boolValueProp) => {
                        boolValueProp.boolValue = false;
                    });
                });
            });
            Utils.ExecuteSetter(dialogue, "m_dialogueNodes", (dialogueNodesProp) => {
                DialogueText text1 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text1, "m_text", (textProp) => textProp.stringValue = "Text 1");
                DialogueText text2_1 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text2_1, "m_text", (textProp) => textProp.stringValue = "Text 2.1");
                DialogueText text2_2 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text2_2, "m_text", (textProp) => textProp.stringValue = "Text 2.2");

                Utils.ExecuteSetterArrayAutoIncrementReset(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = beginText;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = text1;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text1;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        Utils.ExecuteSetterArrayAutoIncrementReset(nextsProp, null, (nextProp) => {
                            Utils.ExecuteSetter(nextProp, "m_conditions", (conditionsProp) => {
                                Utils.ExecuteSetterArrayAutoIncrementReset(conditionsProp, null, (conditionProp) => {
                                    Utils.ExecuteSetter(conditionProp, "m_variable", (variableProp) => {
                                        variableProp.objectReferenceValue = boolVariable1;
                                    });
                                    Utils.ExecuteSetter(conditionProp, "m_boolValue", (boolValueProp) => {
                                        boolValueProp.boolValue = true;
                                    });
                                });
                            });
                            Utils.ExecuteSetter(nextProp, "m_next", (nextDialogueTextProp) => {
                                nextDialogueTextProp.objectReferenceValue = text2_2;
                            });
                        });
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = text2_1;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text2_1;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        nextsProp.arraySize = 0;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = null;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text2_2;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        nextsProp.arraySize = 0;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = null;
                    });
                });
            });
            /** End setup **/

            Utils.ExecuteSetter(m_dialogueController, "m_dialogue", (dialogueProp) => {
                dialogueProp.objectReferenceValue = dialogue;
            });

            m_variableAssignmentsController = gameObject.AddComponent <VariableAssignmentsStaticController>();
            Utils.ExecuteSetter(m_variableAssignmentsController, "m_variableAssignments", (variableAssignmentsProp) => {
                Utils.ExecuteSetterArrayAutoIncrementReset(variableAssignmentsProp, null, (variableAssignmentProp) => {
                    Utils.ExecuteSetter(variableAssignmentProp, "m_variable", (variableProp) => {
                        variableProp.objectReferenceValue = boolVariable1;
                    });
                    Utils.ExecuteSetter(variableAssignmentProp, "m_boolValue", (boolValueProp) => {
                        boolValueProp.boolValue = true;
                    });
                });
            });
        }
 public void HandleDialogueText(DialogueText dialogueText)
 {
     EmitHandleDialogueText(dialogueText.text);
 }
示例#7
0
        void DrawDialogueTextLinkageRow(Rect rect, SerializedProperty property, float labelWidth, GUIContent label = null)
        {
            float prevLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = labelWidth;

            DialogueText dialogueText = (DialogueText)property.objectReferenceValue;

            bool isUndefined = m_undefinedDialogueTexts.Contains(dialogueText);

            if (isUndefined)
            {
                Color prevBackgroundColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.yellow;
                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 155, rect.height), property, label);
                GUI.backgroundColor = prevBackgroundColor;
                EditorGUI.BeginDisabledGroup(true);
                GUI.Button(new Rect(rect.xMax - 60 - 90, rect.y, 90, rect.height), "Undefined", EditorStyles.miniButtonLeft);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 65, rect.height), property, label);
            }

            GUIStyle rightButtonStyle = isUndefined ? EditorStyles.miniButtonRight : EditorStyles.miniButton;

            if (dialogueText == null)
            {
                Rect     coverRect  = new Rect(rect.x + labelWidth, rect.y, rect.width - 80 - labelWidth, rect.height);
                GUIStyle coverStyle = new GUIStyle();
                coverStyle.normal.background = new Texture2D(1, 1);
                coverStyle.padding           = EditorStyles.miniButtonLeft.padding;
                coverStyle.alignment         = TextAnchor.MiddleLeft;
                coverStyle.normal.background.SetPixels(new Color[] { Color.red });
                coverStyle.normal.background.Apply();
                coverStyle.normal.textColor = Color.white;
                GUI.Label(coverRect, "End", coverStyle);
                if (GUI.Button(new Rect(rect.xMax - 60, rect.y, 60, rect.height), "New", rightButtonStyle))
                {
                    DialogueText newDialogueText = PromptToCreate <DialogueText>("New Dialogue Text", "Dialogue Text");
                    property.objectReferenceValue = newDialogueText;
                }
            }
            else
            {
                if (GUI.Button(new Rect(rect.xMax - 60, rect.y, 60, DialogueTextRefFieldHeight), "+|->", rightButtonStyle))
                {
                    int dialogueNodeIndex = FindDialogueNodeIndexByDialogueText(dialogueText);
                    if (dialogueNodeIndex > -1)
                    {
                        dialogueNodeReorderableList.index = dialogueNodeIndex;
                    }
                    else
                    {
                        Add(dialogueNodeReorderableList, dialogueText);
                    }
                }
            }

            EditorGUIUtility.labelWidth = prevLabelWidth;
        }
示例#8
0
        void DrawDialogueNodeElement(Rect rect, int index, bool isActive, bool isFocus)
        {
            if (!isRectInViewport(rect))
            {
                return;
            }
            // Handle delete intermediate elements by code
            if (index >= dialogueNodeReorderableList.serializedProperty.arraySize)
            {
                return;
            }

            float prevLabelWidth = EditorGUIUtility.labelWidth;

            SerializedProperty finalBeginTextProp = serializedObject.FindProperty("m_finalBeginText");
            DialogueText       finalBeginText     = (DialogueText)finalBeginTextProp.objectReferenceValue;
            SerializedProperty dialogueNodeProp   = dialogueNodeReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty dialogueTextProp   = dialogueNodeProp.FindPropertyRelative("m_dialogueText");
            DialogueText       dialogueText       = (DialogueText)dialogueTextProp.objectReferenceValue;

            rect.y += 2;

            Rect dialogueTextRowColumn1Rect = new Rect(rect.x, rect.y, rect.width - 155, DialogueTextRefFieldHeight);
            Rect dialogueTextRowColumn2Rect = new Rect(rect.xMax - 60 - 90, rect.y, 90, DialogueTextRefFieldHeight);
            Rect dialogueTextRowColumn3Rect = new Rect(rect.xMax - 60, rect.y, 60, DialogueTextRefFieldHeight);

            bool isUnused = m_unusedDialogueTexts.Contains(dialogueText);

            if (isUnused)
            {
                Color originalBackgroundColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.yellow;
                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 205, DialogueTextRefFieldHeight), dialogueTextProp, GUIContent.none);
                GUI.backgroundColor = originalBackgroundColor;
                EditorGUI.BeginDisabledGroup(true);
                GUI.Button(new Rect(rect.xMax - 60 - 90 - 50, rect.y, 50, DialogueTextRefFieldHeight), "Unused", EditorStyles.miniButtonLeft);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                EditorGUI.PropertyField(dialogueTextRowColumn1Rect, dialogueTextProp, GUIContent.none);
            }
            if (dialogueText != null)
            {
                bool isBeginText = dialogueText == finalBeginText;
                EditorGUI.BeginDisabledGroup(isBeginText);
                if (GUI.Button(dialogueTextRowColumn2Rect, isBeginText ? "Begin Text" : "As Begin Text", isUnused ? EditorStyles.miniButtonMid : EditorStyles.miniButtonLeft))
                {
                    finalBeginTextProp.objectReferenceValue = dialogueText;
                }
                EditorGUI.EndDisabledGroup();
                if (GUI.Button(dialogueTextRowColumn3Rect, "De|ete", EditorStyles.miniButtonRight))
                {
                    if (EditorUtility.DisplayDialog("Delete Dialogue Node", "Are you sure you want to delete?", "Yes", "No"))
                    {
                        DeleteDialogueNode(index);
                        serializedObject.ApplyModifiedProperties();
                        return;
                    }
                }
            }
            else
            {
                if (GUI.Button(dialogueTextRowColumn2Rect, "New Text", EditorStyles.miniButtonLeft))
                {
                    DialogueText newDialogueText = PromptToCreate <DialogueText>("New Dialogue Text", "Dialogue Text");
                    dialogueTextProp.objectReferenceValue = newDialogueText;
                }
                if (GUI.Button(dialogueTextRowColumn3Rect, "De|ete", EditorStyles.miniButtonRight))
                {
                    if (EditorUtility.DisplayDialog("Delete Dialogue Node", "Are you sure you want to delete?", "Yes", "No"))
                    {
                        DeleteDialogueNode(index);
                        serializedObject.ApplyModifiedProperties();
                        return;
                    }
                }
            }

            rect.y += DialogueTextRefFieldHeight;

            if (dialogueText != null)
            {
                GUIStyle textAreaStyle = new GUIStyle(EditorStyles.textArea);
                textAreaStyle.wordWrap = true;
                dialogueText.text      = EditorGUI.TextArea(new Rect(rect.x, rect.y, rect.width, DialogueTextAreaFieldHeight), dialogueText.text, textAreaStyle);
                EditorUtility.SetDirty(dialogueText);

                rect.y += DialogueTextAreaFieldHeight;
            }

            rect.y += 2;

            SerializedProperty assignmentsProp = dialogueNodeProp.FindPropertyRelative("m_assignments");
            VariableAssignmentReorderableList dialogueNodeVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(assignmentsProp, "Change Variables");
            float dialogueNodeVariableAssignmentReorderableListHeight = dialogueNodeVariableAssignmentReorderableList.GetHeight();
            Rect  dialogueNodeVariableAssignmentReorderableListRect   = new Rect(rect.x, rect.y, rect.width, dialogueNodeVariableAssignmentReorderableListHeight);

            dialogueNodeVariableAssignmentReorderableList.DoList(dialogueNodeVariableAssignmentReorderableListRect);

            rect.y += dialogueNodeVariableAssignmentReorderableListHeight;

            rect.y += 2;

            GUIStyle optionsHeaderStyle = new GUIStyle();

            optionsHeaderStyle.normal.background = new Texture2D(1, 1);
            optionsHeaderStyle.padding           = EditorStyles.miniButtonLeft.padding;
            optionsHeaderStyle.alignment         = TextAnchor.MiddleLeft;
            optionsHeaderStyle.normal.background.SetPixels(new Color[] { new Color(0.3f, 0.3f, 0.3f) });
            optionsHeaderStyle.normal.background.Apply();
            optionsHeaderStyle.normal.textColor = Color.white;
            Rect optionsHeaderRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);

            GUI.Label(optionsHeaderRect, "Options", optionsHeaderStyle);

            rect.y += optionsHeaderRect.height;
            rect.y += 2;

            SerializedProperty nextDialogueOptionsProp = dialogueNodeProp.FindPropertyRelative("m_options");

            for (int i = 0; i < nextDialogueOptionsProp.arraySize; i++)
            {
                SerializedProperty nextDialogueOptionProp = nextDialogueOptionsProp.GetArrayElementAtIndex(i);
                SerializedProperty optionTextProp         = nextDialogueOptionProp.FindPropertyRelative("m_dialogueOptionText");
                DialogueOptionText optionText             = (DialogueOptionText)optionTextProp.objectReferenceValue;

                EditorGUIUtility.labelWidth = 20.0f;
                EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, DialogueTextRefFieldHeight + 2), new Color(0.3f, 0.3f, 0.3f));
                EditorGUI.PropertyField(new Rect(rect.x + 20, rect.y, 100, DialogueTextRefFieldHeight), optionTextProp, new GUIContent("\u2192"));
                if (optionText)
                {
                    optionText.text = EditorGUI.TextField(new Rect(rect.x + 120, rect.y, rect.width - 180, DialogueTextRefFieldHeight), optionText.text);
                    EditorUtility.SetDirty(optionText);
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUI.TextField(new Rect(rect.x + 120, rect.y, rect.width - 280, DialogueTextRefFieldHeight), "");
                    EditorGUI.EndDisabledGroup();
                    if (GUI.Button(new Rect(rect.xMax - 60 - 100, rect.y, 100, DialogueTextRefFieldHeight), "New Option Text", EditorStyles.miniButtonMid))
                    {
                        DialogueOptionText newOptionText = PromptToCreate <DialogueOptionText>("New Dialogue Option Text", "Dialogue Option Text");
                        if (newOptionText != null)
                        {
                            optionTextProp.objectReferenceValue = newOptionText;
                        }
                    }
                }
                if (GUI.Button(new Rect(rect.xMax - 60, rect.y, 60, DialogueTextRefFieldHeight), "De|ete", EditorStyles.miniButtonRight))
                {
                    if (EditorUtility.DisplayDialog("Delete Option", "Are you sure you want to delete?", "Yes", "No"))
                    {
                        DeleteOption(nextDialogueOptionsProp, i);
                        return;
                    }
                }

                rect.y += DialogueTextRefFieldHeight;

                rect.y += 2;

                SerializedProperty optionAssignmentsProp = nextDialogueOptionProp.FindPropertyRelative("m_assignments");
                VariableAssignmentReorderableList optionVariableAssignmentReorderableList = variableAssignmentListPropertyDrawerManager.GetReorderableList(optionAssignmentsProp, "Change variables");
                float optionVariableAssignmentReorderableListHeight = optionVariableAssignmentReorderableList.GetHeight();
                Rect  optionVariableAssignmentReorderableListRect   = new Rect(rect.x + 20, rect.y, rect.width - 20, optionVariableAssignmentReorderableListHeight);
                EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, optionVariableAssignmentReorderableListHeight + 2), new Color(0.3f, 0.3f, 0.3f));
                optionVariableAssignmentReorderableList.DoList(optionVariableAssignmentReorderableListRect);

                rect.y += optionVariableAssignmentReorderableListHeight;

                rect.y += 2;
            }

            EditorGUI.DrawRect(new Rect(rect.x, rect.y - 2, DialogueTextRefFieldHeight + 2, DialogueTextRefFieldHeight + 2), new Color(0.3f, 0.3f, 0.3f));
            EditorGUI.LabelField(new Rect(rect.x + 20, rect.y, 20, ButtonRowHeight), "\u2192");
            if (GUI.Button(new Rect(rect.x + 40, rect.y, rect.width - 40, ButtonRowHeight), "New Option", EditorStyles.miniButton))
            {
                AddOption(nextDialogueOptionsProp);
            }

            rect.y += ButtonRowHeight;

            rect.y += 2;

            SerializedProperty nextsProp     = dialogueNodeProp.FindPropertyRelative("m_nexts");
            SerializedProperty finalNextProp = dialogueNodeProp.FindPropertyRelative("m_finalNext");
            float nextsHeight = m_dialogueNodeNextListPropertyDrawer.GetHeight(nextsProp);
            Rect  nextsRect   = new Rect(rect.x, rect.y, rect.width, nextsHeight);

            m_dialogueNodeNextListPropertyDrawer.DrawDialogueNodeNexts(
                nextsRect,
                nextsProp,
                finalNextProp,
                "Branches");

            rect.y += 2;

            rect.y += 10;

            EditorGUIUtility.labelWidth = prevLabelWidth;
        }
 public virtual void HandleDialogueTextEnd(DialogueText dialogueText)
 {
 }
 public virtual void HandleDialogueTextBegin(DialogueText dialogueText)
 {
 }
        public void TestLinearDialogue()
        {
            /* Setup */
            Dialogue linearDialogue = ScriptableObject.CreateInstance <Dialogue>();

            DialogueText beginText = ScriptableObject.CreateInstance <DialogueText>();

            Utils.ExecuteSetter(beginText, "m_text", (textProp) => {
                textProp.stringValue = "Begin Text";
            });

            Utils.ExecuteSetter(linearDialogue, "m_finalBeginText", (finalBeginTextProp) => {
                finalBeginTextProp.objectReferenceValue = beginText;
            });
            Utils.ExecuteSetter(linearDialogue, "m_dialogueNodes", (dialogueNodesProp) => {
                DialogueText text1 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text1, "m_text", (textProp) => textProp.stringValue = "Text 1");

                DialogueText text2 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text2, "m_text", (textProp) => textProp.stringValue = "Text 2");

                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = beginText;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = text1;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text1;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = text2;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text2;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = null;
                    });
                });
            });
            /** End setup **/

            Utils.ExecuteSetter(m_dialogueController, "m_dialogue", (dialogueProp) => {
                dialogueProp.objectReferenceValue = linearDialogue;
            });

            Assert.AreEqual(m_currentDialogue, null);

            // begin dialogue
            m_dialogueController.StartDialogue();
            Assert.AreEqual(m_currentDialogue, linearDialogue);

            // begin text
            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Begin Text");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 1");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 2");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, null);

            // current dialogue has ended
            Assert.AreEqual(m_currentDialogue, null);
        }
        public void TestBranchedDialogue()
        {
            /* Setup */
            Dialogue     branchedDialogue = ScriptableObject.CreateInstance <Dialogue>();
            BoolVariable boolVariable1    = ScriptableObject.CreateInstance <BoolVariable>();
            DialogueText beginText        = ScriptableObject.CreateInstance <DialogueText>();

            Utils.ExecuteSetter(beginText, "m_text", (textProp) => {
                textProp.stringValue = "Begin Text";
            });
            Utils.ExecuteSetter(branchedDialogue, "m_finalBeginText", (finalBeginTextProp) => {
                finalBeginTextProp.objectReferenceValue = beginText;
            });
            Utils.ExecuteSetter(branchedDialogue, "m_dialogueVariables", (dialogueVariablesProp) => {
                Utils.ExecuteSetterArrayAutoIncrementReset(dialogueVariablesProp, null, (dialogueVariableProp) => {
                    Utils.ExecuteSetter(dialogueVariableProp, "m_variable", (variableProp) => {
                        variableProp.objectReferenceValue = boolVariable1;
                    });
                    Utils.ExecuteSetter(dialogueVariableProp, "m_boolValue", (boolValueProp) => {
                        boolValueProp.boolValue = false;
                    });
                });
            });
            Utils.ExecuteSetter(branchedDialogue, "m_dialogueNodes", (dialogueNodesProp) => {
                DialogueText text1 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text1, "m_text", (textProp) => textProp.stringValue = "Text 1");
                DialogueText text2_1 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text2_1, "m_text", (textProp) => textProp.stringValue = "Text 2.1");
                DialogueText text2_2 = ScriptableObject.CreateInstance <DialogueText>();
                Utils.ExecuteSetter(text2_2, "m_text", (textProp) => textProp.stringValue = "Text 2.2");

                Utils.ExecuteSetterArrayAutoIncrementReset(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = beginText;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = text1;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text1;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        Utils.ExecuteSetterArrayAutoIncrementReset(nextsProp, null, (nextProp) => {
                            Utils.ExecuteSetter(nextProp, "m_conditions", (conditionsProp) => {
                                Utils.ExecuteSetterArrayAutoIncrementReset(conditionsProp, null, (conditionProp) => {
                                    Utils.ExecuteSetter(conditionProp, "m_variable", (variableProp) => {
                                        variableProp.objectReferenceValue = boolVariable1;
                                    });
                                    Utils.ExecuteSetter(conditionProp, "m_boolValue", (boolValueProp) => {
                                        boolValueProp.boolValue = true;
                                    });
                                });
                            });
                            Utils.ExecuteSetter(nextProp, "m_next", (nextDialogueTextProp) => {
                                nextDialogueTextProp.objectReferenceValue = text2_1;
                            });
                        });
                        Utils.ExecuteSetterArrayAutoIncrement(nextsProp, null, (nextProp) => {
                            Utils.ExecuteSetter(nextProp, "m_conditions", (conditionsProp) => {
                                Utils.ExecuteSetterArrayAutoIncrementReset(conditionsProp, null, (conditionProp) => {
                                    Utils.ExecuteSetter(conditionProp, "m_variable", (variableProp) => {
                                        variableProp.objectReferenceValue = boolVariable1;
                                    });
                                    Utils.ExecuteSetter(conditionProp, "m_boolValue", (boolValueProp) => {
                                        boolValueProp.boolValue = false;
                                    });
                                });
                            });
                            Utils.ExecuteSetter(nextProp, "m_next", (nextDialogueTextProp) => {
                                nextDialogueTextProp.objectReferenceValue = text2_2;
                            });
                        });
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = null;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text2_1;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        nextsProp.arraySize = 0;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = null;
                    });
                });
                Utils.ExecuteSetterArrayAutoIncrement(dialogueNodesProp, null, (dialogueNodeProp) => {
                    Utils.ExecuteSetter(dialogueNodeProp, "m_dialogueText", (dialogueTextProp) => {
                        dialogueTextProp.objectReferenceValue = text2_2;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_assignments", (assignmentsProp) => {
                        Utils.ExecuteSetterArrayAutoIncrementReset(assignmentsProp, null, (assignmentProp) => {
                            Utils.ExecuteSetter(assignmentProp, "m_variable", (variableProp) => {
                                variableProp.objectReferenceValue = boolVariable1;
                            });
                            Utils.ExecuteSetter(assignmentProp, "m_boolValue", (boolValueProp) => {
                                boolValueProp.boolValue = true;
                            });
                        });
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_nexts", (nextsProp) => {
                        nextsProp.arraySize = 0;
                    });
                    Utils.ExecuteSetter(dialogueNodeProp, "m_finalNext", (finalNextProp) => {
                        finalNextProp.objectReferenceValue = beginText;
                    });
                });
            });
            /** End setup **/

            Utils.ExecuteSetter(m_dialogueController, "m_dialogue", (dialogueProp) => {
                dialogueProp.objectReferenceValue = branchedDialogue;
            });

            Assert.AreEqual(m_currentDialogue, null);

            // begin dialogue
            m_dialogueController.StartDialogue();
            Assert.AreEqual(m_currentDialogue, branchedDialogue);

            // begin text
            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Begin Text");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 1");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 2.2");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Begin Text");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 1");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, "Text 2.1");

            m_dialogueController.Next();
            Assert.AreEqual(m_currentDialogueText, null);

            // current dialogue has ended
            Assert.AreEqual(m_currentDialogue, null);
        }
示例#13
0
        public static (List <DialogueText> undefinedDialogueTexts, List <DialogueText> unusedDialoguedTexts) GetUnreferencedDialogueTextAndUnusedNodes(Dialogue dialogue)
        {
            List <DialogueText> dialogueTextsFromNode           = new List <DialogueText>();
            List <DialogueText> dialogueTextsFromBeginText      = new List <DialogueText>();
            List <DialogueText> dialogueTextsFromNextText       = new List <DialogueText>();
            List <DialogueText> dialogueTextsFromOptionNextText = new List <DialogueText>();

            List <DialogueNodeNext> beginTexts = dialogue.beginTexts;

            foreach (DialogueNodeNext beginTextNext in beginTexts)
            {
                if (beginTextNext.next != null)
                {
                    dialogueTextsFromBeginText.Add(beginTextNext.next);
                }
            }

            DialogueText finalBeginText = dialogue.finalBeginText;

            if (finalBeginText != null)
            {
                dialogueTextsFromBeginText.Add(finalBeginText);
            }

            List <DialogueNode> dialogueNodes = dialogue.dialogueNodes;

            foreach (DialogueNode dialogueNode in dialogueNodes)
            {
                if (dialogueNode.dialogueText != null)
                {
                    dialogueTextsFromNode.Add(dialogueNode.dialogueText);
                }

                foreach (DialogueNodeNext dialogueNodeNext in dialogueNode.nexts)
                {
                    if (dialogueNodeNext.next != null)
                    {
                        dialogueTextsFromNextText.Add(dialogueNodeNext.next);
                    }
                }

                if (dialogueNode.finalNext != null)
                {
                    dialogueTextsFromNextText.Add(dialogueNode.finalNext);
                }
            }

            IEnumerable <DialogueText> declaredDialogueTexts = dialogueTextsFromBeginText
                                                               .Concat(dialogueTextsFromNextText)
                                                               .Concat(dialogueTextsFromOptionNextText);

            List <DialogueText> undefinedDialogueTexts = declaredDialogueTexts.Except(dialogueTextsFromNode).ToList();

            IEnumerable <DialogueNode> unusedDialoguedNodes = dialogueNodes
                                                              .Where((DialogueNode d) => declaredDialogueTexts.Where((DialogueText t) => t == d.dialogueText).Count() == 0);

            List <DialogueText> unusedDialoguedTexts = new List <DialogueText>();

            foreach (DialogueNode dialogueNode in unusedDialoguedNodes)
            {
                if (dialogueNode.dialogueText != null)
                {
                    unusedDialoguedTexts.Add(dialogueNode.dialogueText);
                }
            }

            return(undefinedDialogueTexts, unusedDialoguedTexts);
        }