Example #1
0
    public override void OnInspectorGUI()
    {
        // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
        serializedObject.Update();
        DrawDefaultInspector();

        if (GUILayout.Button("Find Dialogue Instructions"))
        {
            var parent = DPTrigger.GetComponentInParent <Npc>();
            if (parent != null)
            {
                DPTrigger.dialogueInstructions.Clear();
                string npcName       = parent.name;
                var    functionNames = parent.GetType().GetMethods().Where(m => m.Name.ToLower().Contains($"{npcName.ToLower()}_"));
                foreach (var func in functionNames)
                {
                    string      instructionName = func.Name.Substring(func.Name.IndexOf("Stage"));
                    UnityAction action          = Delegate.CreateDelegate(typeof(UnityAction), parent, func) as UnityAction;
                    UnityEvent  uEvent          = new UnityEvent();
                    UnityEventTools.AddPersistentListener(uEvent, action);
                    DialogueInstruction instruction = new DialogueInstruction()
                    {
                        name   = instructionName,
                        action = uEvent
                    };
                    DPTrigger.dialogueInstructions.Add(instruction);
                }
            }
            serializedObject.ApplyModifiedProperties();
        }

        //// Show the custom GUI controls.
        //EditorGUILayout.IntSlider(damageProp, 0, 100, new GUIContent("Damage"));

        //// Only show the damage progress bar if all the objects have the same damage value:
        //if (!damageProp.hasMultipleDifferentValues)
        //    ProgressBar(damageProp.intValue / 100.0f, "Damage");

        //EditorGUILayout.IntSlider(armorProp, 0, 100, new GUIContent("Armor"));

        //// Only show the armor progress bar if all the objects have the same armor value:
        //if (!armorProp.hasMultipleDifferentValues)
        //    ProgressBar(armorProp.intValue / 100.0f, "Armor");

        //EditorGUILayout.PropertyField(gunProp, new GUIContent("Gun Object"));

        //// Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
        //serializedObject.ApplyModifiedProperties();
    }
Example #2
0
 public void QueueDialogueInstruction(DialogueInstruction instruction)
 {
     dialogue_instruction_queue.Enqueue(instruction);
 }
Example #3
0
 public InstructionLine(DialogueInstruction instruction)
 {
     this.instruction = instruction;
 }
Example #4
0
    public static InstructionLine GenerateInstructionline(DialogueInstruction instruction)
    {
        InstructionLine line = new InstructionLine(instruction);

        return(line);
    }
Example #5
0
    public static List <ScriptLine> CreateDialogueComponents(string text, List <DialogueInstruction> AvailableInstructions = null)
    {
        if (!initialized)
        {
            throw new Exception("InitializeGenerators not yet called");
        }

        List <string> rawLines = new List <string>(text.Split('\n'));

        rawLines = rawLines.Select(x => x.Trim()).ToList();
        rawLines = rawLines.Where(x => x != "").ToList();

        List <ScriptLine> processedLines = new List <ScriptLine>();

        string currentSpeaker     = "";
        int    speakingLineNumber = 0;
        Dictionary <string, ScriptLine> labeledLines = new Dictionary <string, ScriptLine>();

        for (int i = 0; i < rawLines.Count; i++)
        {
            ScriptLine processedLine = null;

            string line = rawLines[i];

            // Dealing with commented out lines
            if (line.StartsWith("//"))
            {
                continue;
            }

            // Checking if the line is valid based on what the game says
            // This is mainly used to filter out statements which should appear/not appear based on the game
            List <string> conditions = GetConditions(line);
            if (!IsLineValid(conditions))
            {
                continue;
            }
            line = RemoveConditions(line);

            // processing current speaker
            string speaker = GetSpeaker(line);
            if (speaker != "")
            {
                currentSpeaker = speaker;
            }
            else if (currentSpeaker == "")
            {
                Debug.LogWarning("Speaker not specified");
            }
            line = RemoveSpeaker(line);

            // processing jump statements
            string jump = GetJump(line);
            line = RemoveJump(line);

            // processing labels
            string label = GetLabel(line);
            line = RemoveLabel(line);

            switch (GetLineType(line))
            {
            case LineType.SpeakingLine:
                processedLine = GenerateSpeakingLine(currentSpeaker, GetSpokenLine(line), speakingLineNumber);
                break;

            case LineType.Expression:
                CharacterExpression desiredExpression = GetExpression(line);
                processedLine = GenerateExperssionLine(currentSpeaker, desiredExpression);
                break;

            case LineType.Choice:
                List <ChoiceLineContent> choices = GetChoices(line, currentSpeaker, speakingLineNumber);
                processedLine = GenerateChoiceLine(currentSpeaker, choices);
                break;

            case LineType.Instruction:
                if (AvailableInstructions != null)
                {
                    line = GetInstructionName(line);
                    DialogueInstruction instruction = AvailableInstructions.Find(x => x.name == line);
                    if (instruction != null)
                    {
                        processedLine = GenerateInstructionLine(instruction);
                    }
                    else
                    {
                        throw new Exception(string.Format("Instruction with name '{0}' not found", line));
                    }
                }
                else
                {
                    throw new Exception("No instructions provided");
                }
                break;

            case LineType.Stall:
                float time = GetStallTime(line);
                processedLine = GenerateStallLine(time);
                break;
            }

            //Redundant hacky coding
            processedLine.speaker = currentSpeaker;

            // adding label to our repository of labels
            if (!string.IsNullOrEmpty(jump))
            {
                processedLine.jumpLabel = jump;
            }

            // adding label to our repository of labels
            if (!string.IsNullOrEmpty(label))
            {
                labeledLines.Add(label, processedLine);
                processedLine.lineLabel  = label;
                processedLine.lineNumber = speakingLineNumber;
            }

            processedLines.Add(processedLine);
            speakingLineNumber++;
        }

        // final scrub through of processed lines to set up proper routing to tags
        for (int i = 0; i < processedLines.Count; i++)
        {
            ScriptLine processedLine = processedLines[i];

            switch (processedLine.GetLineType())
            {
            case LineType.SpeakingLine:
            case LineType.Expression:
                if (!string.IsNullOrEmpty(processedLine.jumpLabel))
                {
                    try
                    {
                        processedLine.nextLine = labeledLines[processedLine.jumpLabel];
                    }
                    catch (Exception e)
                    {
                        Debug.Log(processedLine.jumpLabel);
                        throw e;
                    }
                }
                break;

            case LineType.Choice:
                ((ChoiceLine)processedLine).InitJumps(labeledLines);
                break;
            }
        }
        return(processedLines);
    }