using System; using UnityEngine; public class WFScreenAnchor : MonoBehaviour { private void Awake() { NDebug.Assert(this.root != null, "UIRootがnullです"); this.camera_ = this.root.transform.GetComponentInChildren(); } 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 } }