UI_ScreenFitPos.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using UnityEngine;
  3. public class UI_ScreenFitPos : 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. Vector3 zero = Vector3.zero;
  16. if (this.m_UIFitType == UI_ScreenFitPos.FitType.HorizontalLeft)
  17. {
  18. zero.x = 0f;
  19. }
  20. else if (this.m_UIFitType == UI_ScreenFitPos.FitType.HorizontalRight)
  21. {
  22. zero.x = (float)Screen.width;
  23. }
  24. else if (this.m_UIFitType == UI_ScreenFitPos.FitType.VerticalBottom)
  25. {
  26. zero.y = 0f;
  27. }
  28. else if (this.m_UIFitType == UI_ScreenFitPos.FitType.VerticalTop)
  29. {
  30. zero.y = (float)Screen.height;
  31. }
  32. Vector3 vector = UI_ScreenFitBase.PointToScreenPos(zero);
  33. if (this.m_UIFitType == UI_ScreenFitPos.FitType.HorizontalLeft || this.m_UIFitType == UI_ScreenFitPos.FitType.HorizontalRight)
  34. {
  35. base.transform.localPosition = new Vector3(vector.x, base.transform.localPosition.y, 0f);
  36. }
  37. else
  38. {
  39. base.transform.localPosition = new Vector3(base.transform.localPosition.x, vector.y, 0f);
  40. }
  41. }
  42. [SerializeField]
  43. private UI_ScreenFitPos.FitType m_UIFitType = UI_ScreenFitPos.FitType.HorizontalLeft;
  44. private enum FitType
  45. {
  46. HorizontalRight,
  47. HorizontalLeft,
  48. VerticalTop,
  49. VerticalBottom
  50. }
  51. }