NibiruSystemUITeleport.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEngine;
  2. namespace Nxr.Internal
  3. {
  4. [RequireComponent(typeof(Collider))]
  5. public class NibiruSystemUITeleport : MonoBehaviour, INxrGazeResponder
  6. {
  7. public void OnGazeEnter()
  8. {
  9. Debug.Log("NibiruSystemUITeleport.OnGazeEnter");
  10. }
  11. public void OnGazeExit()
  12. {
  13. Debug.Log("NibiruSystemUITeleport.OnGazeExit");
  14. if (nxrNotificationScript == null)
  15. {
  16. nxrNotificationScript = gameObject.GetComponent<NxrNotificationScript>();
  17. }
  18. nxrNotificationScript.SendCmdToJava(NxrNotificationScript.CMD_ID.HOVER, "-1,-1");
  19. }
  20. public void OnGazeTrigger()
  21. {
  22. Debug.Log("NibiruSystemUITeleport.OnGazeTrigger");
  23. if (nxrNotificationScript == null)
  24. {
  25. nxrNotificationScript = gameObject.GetComponent<NxrNotificationScript>();
  26. }
  27. // CLICK
  28. nxrNotificationScript.SendCmdToJava(NxrNotificationScript.CMD_ID.CLICK, UVRadio[0] * nxrNotificationScript.PreTextureWidth + "," +
  29. (1 - UVRadio[1]) * nxrNotificationScript.PreTextureHeight);
  30. }
  31. NxrNotificationScript nxrNotificationScript;
  32. public void OnUpdateIntersectionPosition(Vector3 position)
  33. {
  34. // update intersection
  35. //Debug.Log("OnUpdateIntersectionPosition------->" + position.ToString() + "," +
  36. //transform.InverseTransformVector(position).ToString());
  37. float xRadio = (position.x - leftX) / (rightX - leftX);
  38. float yRadio = (position.y - bottomeY) / (topY - bottomeY);
  39. UVRadio[0] = Mathf.Clamp(xRadio, 0, 1);
  40. UVRadio[1] = Mathf.Clamp(yRadio, 0, 1);
  41. // Debug.Log("UV is " + UVRadio[0] + "," + UVRadio[1]);
  42. if (nxrNotificationScript == null)
  43. {
  44. nxrNotificationScript = gameObject.GetComponent<NxrNotificationScript>();
  45. }
  46. // HOVER View Top Left is 0,0
  47. //nxrNotificationScript.SendCmdToJava(NxrNotificationScript.CMD_ID.HOVER, UVRadio[0] * nxrNotificationScript.PreTextureWidth + "," +
  48. // (1-UVRadio[1]) * nxrNotificationScript.PreTextureHeight);
  49. //Debug.Log("On Hover : " + UVRadio[0] * nxrNotificationScript.PreTextureWidth + "," +
  50. //(1 - UVRadio[1]) * nxrNotificationScript.PreTextureHeight);
  51. }
  52. public float leftX, rightX, topY, bottomeY;
  53. [Tooltip("bottome left is (0,0), top right is (1,1)")]
  54. public Vector2 UVRadio;
  55. // Use this for initialization
  56. void Start()
  57. {
  58. // Debug.Log("" + transform.localPosition.ToString() + "," + transform.localScale.ToString());
  59. leftX = transform.localPosition.x - transform.localScale.x / 2;
  60. rightX = transform.localPosition.x + transform.localScale.x / 2;
  61. topY = transform.localPosition.y + transform.localScale.y / 2;
  62. bottomeY = transform.localPosition.y - transform.localScale.y / 2;
  63. }
  64. }
  65. }