Inheritance: UnityEngine.MonoBehaviour
    private void OnTriggerEnter(Collider other)
    {
        OurNPC npc = other.gameObject.GetComponentInChildren <OurNPC>();

        //print("Collided with " + other.gameObject.name);
        if (npc != null && npc != lastInteractedNPC)
        {
            if (!hasAddedListener)
            {
                // find the dialogue component and register that we want to know when dialogue ends and allow the player to move
                FindObjectOfType <Yarn.Unity.DialogueUI>().onDialogueEnd.AddListener(() => { DialogueEnded(); });
                hasAddedListener = true;
            }
            if (npc.CanPlay())
            {
                // then try talking with it!
                Yarn.Unity.DialogueRunner runner = FindObjectOfType <Yarn.Unity.DialogueRunner>();
                if (!runner.isDialogueRunning)
                {
                    // don't start the dialogue if it's already talking, we'll have to account for that in our script by checking if we've said things already
                    runner.StartDialogue(npc.talkToNode);
                }
                playerMovement.isAllowedToMove = !runner.isDialogueRunning || canMoveWhileTalking; // only stop the player from moving if dialogue actually starts
                lastInteractedNPC = npc;
                npc.Played();
            }
        }
    }
Example #2
0
 void Start()
 {
     if (scriptToLoad != null)
     {
         Yarn.Unity.DialogueRunner dialogueRunner = FindObjectOfType <Yarn.Unity.DialogueRunner>();
         dialogueRunner.Add(scriptToLoad);
     }
 }
Example #3
0
        /// Start the dialogue
        void Start()
        {
            // Ensure that we have our Implementation object
            if (dialogueUI == null)
            {
                Debug.LogError("Implementation was not set! Can't run the dialogue!");
                return;
            }

            // And that we have our variable storage object
            if (variableStorage == null)
            {
                Debug.LogError("Variable storage was not set! Can't run the dialogue!");
                return;
            }

            // Ensure that the variable storage has the right stuff in it
            variableStorage.ResetToDefaults();

            // Load all scripts
            if (sourceText != null)
            {
                foreach (var source in sourceText)
                {
                    // load and compile the text
                    dialogue.LoadString(source.text, source.name);
                }
            }

            if (startAutomatically)
            {
                StartDialogue();
            }

            if (stringGroups != null)
            {
                // Load the string table for this language, if appropriate
                var stringsGroup = new List <LocalisedStringGroup>(stringGroups).Find(
                    entry => entry.language == (shouldOverrideLanguage ? overrideLanguage : Application.systemLanguage)
                    );

                if (stringsGroup != null)
                {
                    foreach (var table in stringsGroup.stringFiles)
                    {
                        this.AddStringTable(table.text);
                    }
                }
            }

            if (Instance != null)
            {
                Debug.LogError("Instance of dialogue runner already exists, this shouldn't happen");
            }
            Instance = this;
        }
Example #4
0
    void Start()
    {
        dialogueRunner = gameObject.GetComponent <Yarn.Unity.DialogueRunner>();

        // Register a function on startup called "visited" that lets Yarn scripts query to see if a node has been run before.
        dialogueRunner.AddFunction("visited", 1, delegate(Yarn.Value[] parameters)
        {
            var nodeName = parameters[0];
            return(visitedNodes.Contains(nodeName.AsString));
        });
    }
Example #5
0
    void Start()
    {
        EnterFreeState();

        inputManager = GetComponent <GAME_input_manager> ();
        //inventoryManager = GetComponent<GAME_inventory_manager> ();
        menuManager            = GetComponent <GAME_menu_manager> ();
        dialogRunner           = GetComponent <Yarn.Unity.DialogueRunner> ();
        variableStorageManager = GetComponent <ExampleVariableStorage> ();
        yarnUIManager          = GetComponent <YARN_ui_manager> ();
    }
Example #6
0
 void TalkToNPC()
 {
     if (playerTalkRadius >= Vector3.Distance(player.transform.position, hit.transform.position)) //if the npc is close enough
     {
         dialogueRunner = hit.collider.transform.GetChild(1).gameObject;                          //grab their dialogueRunner
         dialogueRunner.GetComponent <Yarn.Unity.DialogueRunner>().StartDialogue();               //start dialogue
         currentDialogue = dialogueRunner.GetComponent <Yarn.Unity.DialogueRunner>();             //keep track of current dialogue to know when dialogue is over
     }
     else
     {
         print("not close enough");
     }
 }
Example #7
0
    // Start is called before the first frame update
    void Start()
    {
        m_uiManager    = UIManager.Instance;
        m_eventManager = EventManager.Instance;
        m_eventManager.AddDialogueCompletedListener(OnDialogueCompletion);

        m_dialogueRunner = DialogueManager.DialogueRunner;
        m_playerControls = GetComponent <PlayerController>().PlayerControls;
        m_playerInput    = GetComponent <PlayerInput>();
        m_playerMovement = GetComponent <PlayerMovement>();

        m_playerControls.Player.Interact.performed += TriggerDialogue;
        m_playerControls.UI.Disable();
    }
Example #8
0
    //this function is intended to help create a new database when a new chapter is added.
    //run it once then save the object it generates as a prefab to create a new database from all loaded nodes.
    private void PopulateNewDatabase()
    {
        Yarn.Unity.DialogueRunner runner = GameObject.Find("DialogueOverlord").GetComponent <Yarn.Unity.DialogueRunner>();
        GameObject   tempGO;
        NodeDatabase tempDB;

        tempGO      = new GameObject();
        tempGO.name = "New NodeDatabase";
        tempDB      = tempGO.AddComponent <NodeDatabase>();
        foreach (string name in runner.dialogue.allNodes)
        {
            Debug.Log(name);
            tempDB.Nodes.Add(new NodeData(name));
        }
    }
Example #9
0
    // Use this for initialization
    void Awake()
    {
        dialogueObject       = GameObject.Find("Dialogue");
        dialogueRunnerScript = dialogueObject.GetComponent <Yarn.Unity.DialogueRunner>();
        ludumDialogueUI      = (LudumDialogueUI)dialogueRunnerScript.dialogueUI;

        inventoryScript = GameObject.Find("Inventory UI").GetComponent <LudumInventory>();
        inventoryScript.OnScoreUpdate += EvaluateScore;

        dispenserInventory = GameObject.Find("DispenserInventory").GetComponent <LudumInventory>();

        timerSlider = GameObject.Find("TimerSlider").GetComponent <Slider>();
        timerSlider.gameObject.SetActive(false);
        timerSlider.maxValue = maxTime;
        //StartCoroutine(StartDialogue());
    }
Example #10
0
 private void Awake()
 {
     #region Enforces Singleton Pattern.
     //Check if instance already exists
     if (instance == null)
     {
         //if not, set instance to this
         instance = this;
     }
     //If instance already exists and it's not this:
     else if (instance != this)
     {
         //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a MyNetworkManager.
         Destroy(gameObject);
     }
     #endregion
 }
Example #11
0
    public void SetUp()
    {
        //Arrange

        // Create the dialogue runner
        var dialogueHost = new GameObject();

        dialogueRunner = dialogueHost.AddComponent <Yarn.Unity.DialogueRunner>();

        // Create the variable storage
        //variableStorage = dialogueHost.AddComponent<ExampleVariableStorage>();

        // Load the test script
        var text = AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/Yarn Spinner/Examples/Demo Assets/Space.json");

        dialogueRunner.AddScript(text);

        dialogueUI = dialogueHost.AddComponent <TestDialogueUIBehaviour>();
        dialogueRunner.dialogueUI = dialogueUI;
    }
Example #12
0
        /// Start the dialogue
        void Start()
        {
            _instance = this;
            // Ensure that we have our Implementation object
            if (dialogueUI == null)
            {
                Debug.LogError("Implementation was not set! Can't run the dialogue!");
                return;
            }

            // And that we have our variable storage object
            if (variableStorage == null)
            {
                Debug.LogError("Variable storage was not set! Can't run the dialogue!");
                return;
            }

            // Ensure that the variable storage has the right stuff in it
            variableStorage.ResetToDefaults();

            // Combine all scripts together and load them
            if (yarnScripts != null && yarnScripts.Length > 0)
            {
                var compiledPrograms = new List <Program>();

                foreach (var program in yarnScripts)
                {
                    compiledPrograms.Add(program.GetProgram());
                }

                var combinedProgram = Program.Combine(compiledPrograms.ToArray());

                dialogue.SetProgram(combinedProgram);
            }


            if (startAutomatically)
            {
                StartDialogue();
            }
        }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        hand_obj.transform.localPosition = pos;
        hand_obj.transform.localRotation = rot;

        FireRay();

        if (currentDialogue != null) // If you are currently talking, you will be unable to teleport or engage in another conversation.
        {
            if (CheckTag("Button"))
            {
                if (activeButton == null)
                {
                    ActivateButton();
                }
                else
                {
                    DeactivateButton();
                    ActivateButton();
                }
            }
            else
            {
                if (activeButton != null) //if not pointing at a button, turn off any active buttons
                {
                    DeactivateButton();
                }
            }

            if (triggerReleased && pressed)
            {
                triggerReleased = false;
                if (CheckTag("Button")) //if its a button, click it
                {
                    ClickButton();
                }

                /*
                 * else if (CheckTag("Teleporter")) //if its a tp then go there and end the conversation
                 * {
                 *  //activeCanvas.SetActive(false);
                 *  isTalking = false;
                 *  Teleport();
                 * }
                 */
            }
            if (currentDialogue.isDialogueRunning == false) // Set currentDialogue to null if dialogue is over so player can teleport and talk again.
            {
                currentDialogue = null;
            }
        }
        else
        {
            if (triggerReleased && pressed) //fire once per trigger pull
            {
                triggerReleased = false;    //toggle to perform on trigger press functionality (the fire once part)
                if (CheckTag("NPC"))
                {
                    TalkToNPC();
                }
                else if (CheckTag("Teleporter"))
                {
                    Teleport();
                }
                else if (CheckTag("DialogueTrigger"))
                {
                    if (playerTalkRadius >= Vector3.Distance(player.transform.position, hit.transform.position))
                    { //if the item is close enough
                        hit.transform.gameObject.GetComponent <DialogueTrigger>().TriggerDialogue();
                        currentDialogue = hit.transform.gameObject.GetComponent <DialogueTrigger>().runnerToTrigger;
                    }
                }
                else if (CheckTag("Secret"))
                {
                    hit.transform.gameObject.GetComponent <DialogueTrigger>().TriggerDialogue();
                    currentDialogue = hit.transform.gameObject.GetComponent <DialogueTrigger>().runnerToTrigger;
                }
            }
        }
        if (CheckTag("DialogueTrigger") || CheckTag("Secret"))
        {
            if (activeObject == null)
            {
                ActivateObject();
            }
            else
            {
                DeactivateObject();
                ActivateObject();
            }
        }
        else
        {
            if (activeObject != null) //if not pointing at a button, turn off any active buttons
            {
                DeactivateObject();
            }
        }

        if (CheckTag("NPC"))
        {
            if (activeNPC == null)
            {
                ActivateNPC();
            }
            else
            {
                DeactivateNPC();
                ActivateNPC();
            }
        }
        else
        {
            if (activeNPC != null) //if not pointing at a button, turn off any active buttons
            {
                DeactivateNPC();
            }
        }

        if (CheckTag("Teleporter"))
        {
            activeTeleporter = hit.transform.gameObject;
            activeTeleporter.GetComponent <Teleporter>().selected = true;
        }
        else
        {
            if (activeTeleporter != null)
            {
                activeTeleporter.GetComponent <Teleporter>().selected = false;
                activeTeleporter = null;
            }
        }


        if (!pressed)
        {
            triggerReleased = true; // if the player released the trigger, update the variable (fire once functionality)
        }
    }
    public void SetUp()
    {
        //Arrange

        // Create the dialogue runner
        var dialogueHost = new GameObject();
        dialogueRunner = dialogueHost.AddComponent<Yarn.Unity.DialogueRunner>();

        // Create the variable storage
        //variableStorage = dialogueHost.AddComponent<ExampleVariableStorage>();

        // Load the test script
        var text = AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/Yarn Spinner/Examples/Demo Assets/Space.json");
        dialogueRunner.AddScript(text);

        dialogueUI = dialogueHost.AddComponent<TestDialogueUIBehaviour>();
        dialogueRunner.dialogueUI = dialogueUI;
    }
Example #15
0
 void Awake()
 {
     S = this;
 }
Example #16
0
 // Use this for initialization
 void Start()
 {
     myCollider = GetComponent <BoxCollider2D>();
     dr         = GameObject.Find("YarnSpinnerHolder").GetComponent <Yarn.Unity.DialogueRunner>();
 }