using System; using UnityEngine; public class UI_ImageFitPos : UI_ScreenFitBase { protected override void Start() { base.Start(); } protected override void Update() { base.Update(); } protected override void FitAction() { if (!this.FitImage) { return; } Vector3 zero = Vector3.zero; switch (this.m_UIFitType) { case UI_ImageFitPos.FitType.HorizontalRight: zero.x = (float)(this.FitImage.width / 2); if (this.m_UseFillAmount) { zero.x -= (float)this.FitImage.width * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount)); } break; case UI_ImageFitPos.FitType.HorizontalLeft: zero.x = (float)(-(float)this.FitImage.width / 2); if (this.m_UseFillAmount) { zero.x += (float)this.FitImage.width * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount)); } break; case UI_ImageFitPos.FitType.VerticalTop: zero.y = (float)(this.FitImage.height / 2); if (this.m_UseFillAmount) { zero.y -= (float)this.FitImage.height * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount)); } break; case UI_ImageFitPos.FitType.VerticalBottom: zero.y = (float)(-(float)this.FitImage.height / 2); if (this.m_UseFillAmount) { zero.y += (float)this.FitImage.height * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount)); } break; } if (this.m_UIFitType == UI_ImageFitPos.FitType.HorizontalLeft || this.m_UIFitType == UI_ImageFitPos.FitType.HorizontalRight) { base.transform.localPosition = new Vector3(this.FitImage.transform.localPosition.x + zero.x, base.transform.localPosition.y, 0f); } else { base.transform.localPosition = new Vector3(base.transform.localPosition.x, this.FitImage.transform.localPosition.y + zero.y, 0f); } } [SerializeField] private UI_ImageFitPos.FitType m_UIFitType = UI_ImageFitPos.FitType.HorizontalLeft; [SerializeField] private bool m_UseFillAmount; [SerializeField] private bool m_FillReverse; public UIBasicSprite FitImage; private enum FitType { HorizontalRight, HorizontalLeft, VerticalTop, VerticalBottom } }