TalkIndicator.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using UnityEngine;
  2. public class TalkIndicator : MonoBehaviour
  3. {
  4. public static TalkIndicator Instance = null;
  5. [SerializeField] private Vector3 offSetDialog;
  6. [SerializeField] private Vector3 offSetNotifi;
  7. [SerializeField] private GameObject dialog;
  8. [SerializeField] private GameObject talkNotifivation;
  9. [SerializeField] private Transform phoneCallPosition;
  10. private Vector3 wordPosDialog = Vector3.zero;
  11. private Vector3 wordPosNotifi = Vector3.zero;
  12. private Vector3 worldScaleNotifi = Vector3.one;
  13. private Transform npcPosition;
  14. private Vector3 lastNpcPosition;
  15. [SerializeField] private float posPhoneOffset;
  16. [SerializeField] private float aspecRatio;
  17. private void Awake()
  18. {
  19. Instance = this;
  20. float w = Screen.width;
  21. float h = Screen.height;
  22. aspecRatio = h / w;
  23. }
  24. private void Start()
  25. {
  26. ConversationManager.instance.onChangeDialog += ChangeDialog;
  27. }
  28. private void ChangeDialog(DataTools.Dialog _dialog)
  29. {
  30. SetPositionObj(_dialog.NpcId);
  31. }
  32. public void SetPositionObj(string _nameNpc)
  33. {
  34. npcPosition = Characters.Instance.GetCurrentNpc(_nameNpc);
  35. }
  36. private void LateUpdate()
  37. {
  38. UpdatePosition();
  39. if (GameGlobal.Instance.GetActualConversationType != DataTools.ConversationType.PhoneCall)
  40. {
  41. if (dialog.gameObject.activeInHierarchy)
  42. {
  43. dialog.transform.position = wordPosDialog;
  44. }
  45. if (talkNotifivation.gameObject.activeInHierarchy)
  46. {
  47. talkNotifivation.transform.position = wordPosNotifi;
  48. }
  49. }
  50. else
  51. {
  52. if (aspecRatio >= 0.7f)
  53. {
  54. dialog.transform.position = phoneCallPosition.position + new Vector3(posPhoneOffset, 0, 0);
  55. }
  56. else
  57. {
  58. dialog.transform.position = phoneCallPosition.position;
  59. }
  60. }
  61. }
  62. private void UpdatePosition()
  63. {
  64. if (npcPosition != null)
  65. {
  66. wordPosDialog.x = npcPosition.position.x + (offSetDialog.x * npcPosition.localScale.x);
  67. wordPosDialog.y = npcPosition.position.y + (offSetDialog.y * npcPosition.localScale.y);
  68. wordPosDialog.z = -5f;
  69. wordPosNotifi.x = npcPosition.position.x + (offSetNotifi.x * npcPosition.localScale.x) - 0.5f * Mathf.Sign(npcPosition.localScale.x);
  70. wordPosNotifi.y = npcPosition.position.y + (offSetNotifi.y * npcPosition.localScale.y);
  71. wordPosNotifi.z = -5f;
  72. worldScaleNotifi = npcPosition.localScale;
  73. }
  74. else
  75. {
  76. wordPosDialog = Navigation.Instance.StartPos;
  77. wordPosDialog.z = -5f;
  78. wordPosNotifi = Navigation.Instance.StartPos;
  79. wordPosNotifi.z = -5f;
  80. worldScaleNotifi = Vector3.one;
  81. }
  82. }
  83. }