PointedAtGameObjectInfo.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="PointedAtGameObjectInfo.cs" company="Exit Games GmbH">
  3. // </copyright>
  4. // <summary>
  5. // Display ViewId, OwnerActorNr, IsCeneView and IsMine when clicked using the old UI system
  6. // </summary>
  7. // <author>developer@exitgames.com</author>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using System;
  10. using UnityEngine;
  11. using UnityEngine.UI;
  12. using UnityEngine.EventSystems;
  13. using Photon.Pun;
  14. using Photon.Realtime;
  15. namespace Photon.Pun.UtilityScripts
  16. {
  17. /// <summary>
  18. /// Display ViewId, OwnerActorNr, IsCeneView and IsMine when clicked.
  19. /// </summary>
  20. public class PointedAtGameObjectInfo : MonoBehaviour
  21. {
  22. public static PointedAtGameObjectInfo Instance;
  23. public Text text;
  24. Transform focus;
  25. void Start()
  26. {
  27. if (Instance != null)
  28. {
  29. Debug.LogWarning("PointedAtGameObjectInfo is already featured in the scene, gameobject is destroyed");
  30. Destroy(this.gameObject);
  31. }
  32. Instance = this;
  33. }
  34. public void SetFocus(PhotonView pv)
  35. {
  36. focus = pv != null ? pv.transform : null;
  37. if (pv != null)
  38. {
  39. text.text = string.Format("id {0} own: {1} {2}{3}", pv.ViewID, pv.OwnerActorNr, (pv.IsRoomView) ? "scn" : "", (pv.IsMine) ? " mine" : "");
  40. //GUI.Label (new Rect (Input.mousePosition.x + 5, Screen.height - Input.mousePosition.y - 15, 300, 30), );
  41. }
  42. else
  43. {
  44. text.text = string.Empty;
  45. }
  46. }
  47. public void RemoveFocus(PhotonView pv)
  48. {
  49. if (pv == null)
  50. {
  51. text.text = string.Empty;
  52. return;
  53. }
  54. if (pv.transform == focus)
  55. {
  56. text.text = string.Empty;
  57. return;
  58. }
  59. }
  60. void LateUpdate()
  61. {
  62. if (focus != null)
  63. {
  64. this.transform.position = Camera.main.WorldToScreenPoint(focus.position);
  65. }
  66. }
  67. }
  68. }