using UnityEngine; using UnityEngine.UI; namespace Superlazy.UI { public class SLUIScaleBind : SLUIComponent { public float bindwidth; public float bindHeight; public string bind = ""; private LayoutElement layoutElement; private RectTransform rect; protected override void Validate() { layoutElement = GetComponent(); rect = GetComponent(); } protected override void Init() { } protected override void Enable() { if (bind != string.Empty) { SLGame.AddNotify(bindParent.BindPath.CombinePath(bind), OnChange); } else // 값에 직접바인딩인가? { SLGame.AddNotify(bindParent.BindPath, OnChange); } } protected override void Disable() { if (bind != string.Empty) { SLGame.RemoveNotify(bindParent.BindPath.CombinePath(bind), OnChange); } else // 값에 직접바인딩인가? { SLGame.RemoveNotify(bindParent.BindPath, OnChange); } } private void OnChange() { if (bindParent.Active == false) return; double bindValue; if (bind != string.Empty) { bindValue = SLGame.SessionGet(bindParent.BindPath.CombinePath(bind)); } else { bindValue = SLGame.SessionGet(bindParent.BindPath); } if (layoutElement) { if (bindwidth != 0.0f) layoutElement.preferredWidth = bindwidth * (float)bindValue; if (bindHeight != 0.0f) layoutElement.preferredHeight = bindHeight * (float)bindValue; } else { var size = rect.sizeDelta; if (bindwidth != 0.0f) size.x = bindwidth * (float)bindValue; if (bindHeight != 0.0f) size.y = bindHeight * (float)bindValue; rect.sizeDelta = size; } } } }