1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using UnityEngine;
- public class WFScreenAnchor : MonoBehaviour
- {
- private void Awake()
- {
- NDebug.Assert(this.root != null, "UIRootがnullです");
- this.camera_ = this.root.transform.GetComponentInChildren<Camera>();
- }
- private void Update()
- {
- Vector3 zero = Vector3.zero;
- if (this.tracking == WFScreenAnchor.Tracking.Right)
- {
- zero.x = (float)Screen.width;
- }
- else if (this.tracking == WFScreenAnchor.Tracking.Left)
- {
- zero.x = 0f;
- }
- else if (this.tracking == WFScreenAnchor.Tracking.Top)
- {
- zero.y = (float)Screen.height;
- }
- else if (this.tracking == WFScreenAnchor.Tracking.Bottom)
- {
- zero.y = 0f;
- }
- Vector3 position = this.camera_.ScreenToWorldPoint(zero);
- Vector3 vector = base.transform.parent.InverseTransformPoint(position);
- if (this.tracking == WFScreenAnchor.Tracking.Right || this.tracking == WFScreenAnchor.Tracking.Left)
- {
- base.transform.localPosition = new Vector3(vector.x, base.transform.localPosition.y, 0f);
- }
- else
- {
- base.transform.localPosition = new Vector3(base.transform.localPosition.x, vector.y, 0f);
- }
- }
- public WFScreenAnchor.Tracking tracking
- {
- get
- {
- return this.Tracking_;
- }
- }
- public UIRoot root;
- [SerializeField]
- private WFScreenAnchor.Tracking Tracking_;
- private Camera camera_;
- public enum Tracking
- {
- Right,
- Left,
- Top,
- Bottom
- }
- }
|