12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using UnityEngine;
- public class TalkIndicator : MonoBehaviour
- {
- public static TalkIndicator Instance = null;
- [SerializeField] private Vector3 offSetDialog;
- [SerializeField] private Vector3 offSetNotifi;
- [SerializeField] private GameObject dialog;
- [SerializeField] private GameObject talkNotifivation;
- [SerializeField] private Transform phoneCallPosition;
- private Vector3 wordPosDialog = Vector3.zero;
- private Vector3 wordPosNotifi = Vector3.zero;
- private Vector3 worldScaleNotifi = Vector3.one;
- private Transform npcPosition;
- private Vector3 lastNpcPosition;
- [SerializeField] private float posPhoneOffset;
- [SerializeField] private float aspecRatio;
- private void Awake()
- {
- Instance = this;
- float w = Screen.width;
- float h = Screen.height;
- aspecRatio = h / w;
- }
- private void Start()
- {
- ConversationManager.instance.onChangeDialog += ChangeDialog;
- }
- private void ChangeDialog(DataTools.Dialog _dialog)
- {
- SetPositionObj(_dialog.NpcId);
- }
- public void SetPositionObj(string _nameNpc)
- {
- npcPosition = Characters.Instance.GetCurrentNpc(_nameNpc);
- }
- private void LateUpdate()
- {
- UpdatePosition();
- if (GameGlobal.Instance.GetActualConversationType != DataTools.ConversationType.PhoneCall)
- {
- if (dialog.gameObject.activeInHierarchy)
- {
- dialog.transform.position = wordPosDialog;
- }
- if (talkNotifivation.gameObject.activeInHierarchy)
- {
- talkNotifivation.transform.position = wordPosNotifi;
- }
- }
- else
- {
- if (aspecRatio >= 0.7f)
- {
- dialog.transform.position = phoneCallPosition.position + new Vector3(posPhoneOffset, 0, 0);
- }
- else
- {
- dialog.transform.position = phoneCallPosition.position;
- }
- }
- }
- private void UpdatePosition()
- {
- if (npcPosition != null)
- {
- wordPosDialog.x = npcPosition.position.x + (offSetDialog.x * npcPosition.localScale.x);
- wordPosDialog.y = npcPosition.position.y + (offSetDialog.y * npcPosition.localScale.y);
- wordPosDialog.z = -5f;
- wordPosNotifi.x = npcPosition.position.x + (offSetNotifi.x * npcPosition.localScale.x) - 0.5f * Mathf.Sign(npcPosition.localScale.x);
- wordPosNotifi.y = npcPosition.position.y + (offSetNotifi.y * npcPosition.localScale.y);
- wordPosNotifi.z = -5f;
- worldScaleNotifi = npcPosition.localScale;
- }
- else
- {
- wordPosDialog = Navigation.Instance.StartPos;
- wordPosDialog.z = -5f;
- wordPosNotifi = Navigation.Instance.StartPos;
- wordPosNotifi.z = -5f;
- worldScaleNotifi = Vector3.one;
- }
- }
- }
|