WFScreenAnchor.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using UnityEngine;
  3. public class WFScreenAnchor : MonoBehaviour
  4. {
  5. private void Awake()
  6. {
  7. NDebug.Assert(this.root != null, "UIRootがnullです");
  8. this.camera_ = this.root.transform.GetComponentInChildren<Camera>();
  9. }
  10. private void Update()
  11. {
  12. Vector3 zero = Vector3.zero;
  13. if (this.tracking == WFScreenAnchor.Tracking.Right)
  14. {
  15. zero.x = (float)Screen.width;
  16. }
  17. else if (this.tracking == WFScreenAnchor.Tracking.Left)
  18. {
  19. zero.x = 0f;
  20. }
  21. else if (this.tracking == WFScreenAnchor.Tracking.Top)
  22. {
  23. zero.y = (float)Screen.height;
  24. }
  25. else if (this.tracking == WFScreenAnchor.Tracking.Bottom)
  26. {
  27. zero.y = 0f;
  28. }
  29. Vector3 position = this.camera_.ScreenToWorldPoint(zero);
  30. Vector3 vector = base.transform.parent.InverseTransformPoint(position);
  31. if (this.tracking == WFScreenAnchor.Tracking.Right || this.tracking == WFScreenAnchor.Tracking.Left)
  32. {
  33. base.transform.localPosition = new Vector3(vector.x, base.transform.localPosition.y, 0f);
  34. }
  35. else
  36. {
  37. base.transform.localPosition = new Vector3(base.transform.localPosition.x, vector.y, 0f);
  38. }
  39. }
  40. public WFScreenAnchor.Tracking tracking
  41. {
  42. get
  43. {
  44. return this.Tracking_;
  45. }
  46. }
  47. public UIRoot root;
  48. [SerializeField]
  49. private WFScreenAnchor.Tracking Tracking_;
  50. private Camera camera_;
  51. public enum Tracking
  52. {
  53. Right,
  54. Left,
  55. Top,
  56. Bottom
  57. }
  58. }