using UnityEngine; namespace Superlazy.UI { public class SLUIPosition : SLUIComponent { public string bind = "Position"; public string rotationBind; public bool billboard = false; public bool world = true; public float cameraDist = 0; private Transform t; private Vector3 position; protected override void Validate() { t = GetComponent(); } protected override void Init() { } protected override void Enable() { SLGame.AddNotify(bindParent.BindPath.CombinePath(bind), OnChange); if (string.IsNullOrEmpty(rotationBind) == false) { SLGame.AddNotify(bindParent.BindPath.CombinePath(rotationBind), OnChange); } } protected override void Disable() { SLGame.RemoveNotify(bindParent.BindPath.CombinePath(bind), OnChange); if (string.IsNullOrEmpty(rotationBind) == false) { SLGame.RemoveNotify(bindParent.BindPath.CombinePath(rotationBind), OnChange); } } private void OnChange() { if (bindParent.Active == false) return; position = SLGame.SessionGet(bindParent.BindPath).Get(bind).ToVector3(); if (world) { t.position = position; } else { t.localPosition = position; } if (string.IsNullOrEmpty(rotationBind) == false) { if (world) { t.rotation = Quaternion.Euler(new Vector3(0, 0, SLGame.SessionGet(bindParent.BindPath).Get(rotationBind))); } else { t.localRotation = Quaternion.Euler(new Vector3(0, 0, SLGame.SessionGet(bindParent.BindPath).Get(rotationBind))); } } } private void Update() // TODO: 여전히 한프레임 밀리지만 먼저꺼가 너무 못생겼다. 시간없으니 다음에 { if (cameraDist > 0.01) { t.position = SLGame.Camera.transform.position + (position - SLGame.Camera.transform.position).normalized * cameraDist; } } private void LateUpdate() { if (billboard) { t.forward = SLGame.Camera.transform.forward; } } } }