using UnityEngine; using UnityEngine.UI; public class UISpiritLoader : MonoBehaviour { public bool Ratio; public MyImage Image; private Vector2 ImageSizeData; private Vector2 LoaderSizeData; [ContextMenu("SetLoaderSpirit")] public void SetLoaderSpirit() { //Image.SetNativeSize(); Image.GetComponent().localScale = new Vector3(1, 1, 1); LoaderSizeData = GetComponent().sizeDelta; ImageSizeData = Image.GetComponent().sizeDelta; if (Ratio) { if (LoaderSizeData.x > LoaderSizeData.y) { float ys = LoaderSizeData.y / ImageSizeData.y; Image.GetComponent().localScale = new Vector3(ys, ys, ys); } else { float xs = LoaderSizeData.x / ImageSizeData.x; Image.GetComponent().localScale = new Vector3(xs, xs, xs); } Image.GetComponent().localPosition = Vector3.zero; } } }