UI_ImageFitPos.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using UnityEngine;
  3. public class UI_ImageFitPos : UI_ScreenFitBase
  4. {
  5. protected override void Start()
  6. {
  7. base.Start();
  8. }
  9. protected override void Update()
  10. {
  11. base.Update();
  12. }
  13. protected override void FitAction()
  14. {
  15. if (!this.FitImage)
  16. {
  17. return;
  18. }
  19. Vector3 zero = Vector3.zero;
  20. switch (this.m_UIFitType)
  21. {
  22. case UI_ImageFitPos.FitType.HorizontalRight:
  23. zero.x = (float)(this.FitImage.width / 2);
  24. if (this.m_UseFillAmount)
  25. {
  26. zero.x -= (float)this.FitImage.width * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount));
  27. }
  28. break;
  29. case UI_ImageFitPos.FitType.HorizontalLeft:
  30. zero.x = (float)(-(float)this.FitImage.width / 2);
  31. if (this.m_UseFillAmount)
  32. {
  33. zero.x += (float)this.FitImage.width * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount));
  34. }
  35. break;
  36. case UI_ImageFitPos.FitType.VerticalTop:
  37. zero.y = (float)(this.FitImage.height / 2);
  38. if (this.m_UseFillAmount)
  39. {
  40. zero.y -= (float)this.FitImage.height * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount));
  41. }
  42. break;
  43. case UI_ImageFitPos.FitType.VerticalBottom:
  44. zero.y = (float)(-(float)this.FitImage.height / 2);
  45. if (this.m_UseFillAmount)
  46. {
  47. zero.y += (float)this.FitImage.height * ((!this.m_FillReverse) ? this.FitImage.fillAmount : (1f - this.FitImage.fillAmount));
  48. }
  49. break;
  50. }
  51. if (this.m_UIFitType == UI_ImageFitPos.FitType.HorizontalLeft || this.m_UIFitType == UI_ImageFitPos.FitType.HorizontalRight)
  52. {
  53. base.transform.localPosition = new Vector3(this.FitImage.transform.localPosition.x + zero.x, base.transform.localPosition.y, 0f);
  54. }
  55. else
  56. {
  57. base.transform.localPosition = new Vector3(base.transform.localPosition.x, this.FitImage.transform.localPosition.y + zero.y, 0f);
  58. }
  59. }
  60. [SerializeField]
  61. private UI_ImageFitPos.FitType m_UIFitType = UI_ImageFitPos.FitType.HorizontalLeft;
  62. [SerializeField]
  63. private bool m_UseFillAmount;
  64. [SerializeField]
  65. private bool m_FillReverse;
  66. public UIBasicSprite FitImage;
  67. private enum FitType
  68. {
  69. HorizontalRight,
  70. HorizontalLeft,
  71. VerticalTop,
  72. VerticalBottom
  73. }
  74. }