UIManager.cs 1.71 KB
using System.Collections;
using System.Collections.Generic;
using VIDE_Data;
using UnityEngine.UI;
using UnityEngine;

public class UIManager : MonoBehaviour
{
    public GameObject container_NPC;
    public GameObject container_PLAYER;
    public Text text_NPC;
    public Text text_PLAYER;
    GameObject controller_R;

    // Start is called before the first frame update
    void Start()
    {
      
        container_NPC.SetActive(false);
        container_PLAYER.SetActive(false);
        controller_R = GameObject.Find("Controller (right)");

    }

    // Update is called once per frame
    void Update()
    {
        if (controller_R.GetComponent<ActionTest>().GetTeleportDown())
        {
            if (!VD.isActive)
            {
                Begin();
            }
            else
            {
                VD.Next();
            }
        }
        
    }

    void Begin()
    {
        VD.OnNodeChange += UpdateUI;
        VD.OnEnd += End;
        VD.BeginDialogue(GetComponent<VIDE_Assign>());
    }

    void UpdateUI(VD.NodeData data)
    {
        container_NPC.SetActive(false);
        container_PLAYER.SetActive(false);
        if (data.isPlayer)
        {
            container_PLAYER.SetActive(true);
            text_PLAYER.text = data.comments[data.commentIndex];
        }
        else
        {
            container_NPC.SetActive(true);
            text_NPC.text = data.comments[data.commentIndex];
        }
    }


    void End(VD.NodeData data)
    {
    container_NPC.SetActive(false);
    container_PLAYER.SetActive(false);
    VD.OnNodeChange -= UpdateUI;
        VD.OnEnd -= End;
        VD.EndDialogue();
    }
    void OnDisable()
    {
        if (container_NPC != null)
            End(null);
    }
}