Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Dialogue : MonoBehaviour
- {
- public Transform NpcTransform;
- bool active;
- public Transform DialogueInterface;
- public float offset;
- bool uiActiveFollow;
- int uistate;
- private Player player;
- public string DialogID;
- public TextAsset textRU;
- public TextAsset textEN;
- float DialTimeout;
- DialogUI dialui;
- public DialogueAnimSync[] SfxTr;
- public Runner runner;
- public bool Deactive;
- public PressE DialogueUItr;
- void Start ()
- {
- dialui = DialogueInterface.GetComponent<DialogUI> ();
- DialTimeout = 2;
- }
- void Update ()
- {
- if (uiActiveFollow)
- {
- DialogueInterface.position = Camera.main.WorldToScreenPoint (transform.position + new Vector3 (0, offset, 0));
- }
- if (DialTimeout < 2)
- {
- DialTimeout += Time.deltaTime;
- }
- }
- public void OnTriggerEnter2D(Collider2D col)
- {
- if (col.transform.CompareTag ("Player") && active == false&&DialTimeout>=2&&Deactive==false)
- {
- player = col.GetComponent<Player> ();
- if (NpcTransform.GetComponent<BackgroundNpcPatrol> ())
- {
- BackgroundNpcPatrol NpcScript = NpcTransform.GetComponent<BackgroundNpcPatrol> ();
- NpcScript.Walk = false;
- NpcScript.anim.SetBool ("Run", false);
- if (NpcScript.transform.position.x < player.transform.position.x)
- {
- NpcScript.transform.localScale = new Vector3 (1, 1, 1);
- } else
- {
- NpcScript.transform.localScale = new Vector3 (-1, 1, 1);
- }
- }
- if (DialogueUItr == null)
- {
- EnableDialogue ();
- }
- else
- {
- DialogueUItr.active = true;
- DialogueUItr.uiActiveFollow = true;
- DialogueUItr.uistate = 1;
- DialogueUItr.target = NpcTransform;
- DialogueUItr.dialogueTr = this;
- }
- }
- }
- public void EnableDialogue()
- {
- active = true;
- dialui.uistate = 1;
- //Say (1);
- uiActiveFollow = true;
- CancelInvoke ("DeactivatePosUiFollow");
- player.DisableControl = true;
- GameObject.FindObjectOfType<MainMenu> ().MenuCursorEnable ();
- if (SfxTr != null)
- {
- //Instantiate (SfxTr[PlayerPrefs.GetInt(DialogID+"Replica")], transform.position, transform.rotation);
- Instantiate (SfxTr[PlayerPrefs.GetInt(DialogID+"Replica")].ReplicaSFX, transform.position, transform.rotation);
- NpcTransform.GetComponent<Animator>().Play(SfxTr[PlayerPrefs.GetInt(DialogID+"Replica")].ReplicaAnim);
- }
- if (PlayerPrefs.GetInt ("SelectionLanguage") == 0)
- {
- dialui.currentTextFile = textEN;
- if (textEN == null)
- {
- dialui.currentTextFile = textRU;
- }
- }
- if (PlayerPrefs.GetInt ("SelectionLanguage") == 1)
- {
- dialui.currentTextFile = textRU;
- }
- dialui.DialogID = DialogID;
- dialui.dialogueNpc = this;
- dialui.LoadText ();
- if (runner != null)
- {
- runner.MovementEventState = 0;
- }
- }
- public void Say(int SayNumber)
- {
- if (SayNumber == 1)
- {
- StartCoroutine ("AnimOnce", "Say");
- }
- }
- public IEnumerator AnimOnce(string anim)
- {
- NpcTransform.GetComponent<Animator>().SetBool (anim, true);
- yield return new WaitForSeconds (0.2f);
- NpcTransform.GetComponent<Animator>().SetBool (anim, false);
- }
- public void OnTriggerExit2D(Collider2D col)
- {
- if (col.transform.CompareTag ("Player") )
- {
- if (active)
- {
- DeactivateDialog ();
- }
- if (DialogueUItr != null)
- {
- DialogueUItr.Deactivate ();
- }
- }
- }
- public void DeactivateDialog()
- {
- active = false;
- dialui.uistate = 2;
- if (NpcTransform.GetComponent<BackgroundNpcPatrol> ())
- {
- BackgroundNpcPatrol NpcScript = NpcTransform.GetComponent<BackgroundNpcPatrol> ();
- NpcScript.Walk = true;
- NpcScript.GetPatrolPoint ();
- }
- Invoke ("DeactivatePosUiFollow", 1);
- player.DisableControl = false;
- GameObject.FindObjectOfType<MainMenu> ().MenuCursorDisable ();
- DialTimeout = 0;
- }
- public void DeactivatePosUiFollow()
- {
- uiActiveFollow = false;
- }
- }
- [System.Serializable]
- public class DialogueAnimSync
- {
- public Transform ReplicaSFX;
- public string ReplicaAnim;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement