Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

115 rindas
2.9 KiB

  1. using System;
  2. using System.Collections;
  3. using SUISS.Core;
  4. using SUISS.Scheduling;
  5. using UnityEngine;
  6. public class CameraTransition : MonoBehaviour
  7. {
  8. protected virtual void Awake()
  9. {
  10. this._cachedCamera = base.GetComponent<Camera>();
  11. this._normalOrthoSize = this._cachedCamera.orthographicSize;
  12. this._normalPosition = base.transform.localPosition;
  13. }
  14. protected virtual void Start()
  15. {
  16. }
  17. protected virtual void OnDestroy()
  18. {
  19. this.StopTransition();
  20. }
  21. public void ZoomInOnInstant(GameObject go)
  22. {
  23. this.StopTransition();
  24. Vector3 a;
  25. if (go == null)
  26. {
  27. a = this._normalPosition;
  28. }
  29. else
  30. {
  31. SpriteRenderer component = go.GetComponent<SpriteRenderer>();
  32. if (component != null)
  33. {
  34. a = component.bounds.center;
  35. }
  36. else
  37. {
  38. a = go.transform.localPosition;
  39. }
  40. }
  41. this.rootContainer.localPosition = -a;
  42. this._cachedCamera.orthographicSize = 0f;
  43. }
  44. public void ZoomInOn(GameObject go, float durationseconds)
  45. {
  46. this.StopTransition();
  47. SpriteRenderer component = go.GetComponent<SpriteRenderer>();
  48. Vector3 towardspos;
  49. if (component != null)
  50. {
  51. towardspos = component.bounds.center;
  52. }
  53. else
  54. {
  55. towardspos = go.transform.localPosition;
  56. }
  57. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._transitionRoutine = this.TransitionRoutine(towardspos, 0f, durationseconds));
  58. }
  59. public void ZoomOutInstant()
  60. {
  61. this.StopTransition();
  62. this.rootContainer.localPosition = -this._normalPosition;
  63. this._cachedCamera.orthographicSize = this._normalOrthoSize;
  64. }
  65. public void ZoomOut(float durationseconds)
  66. {
  67. this.StopTransition();
  68. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._transitionRoutine = this.TransitionRoutine(this._normalPosition, this._normalOrthoSize, durationseconds));
  69. }
  70. public void StopTransition()
  71. {
  72. if (this._transitionRoutine != null && SingletonMonobehaviour<Scheduler>.IsAvailable)
  73. {
  74. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._transitionRoutine);
  75. this._transitionRoutine = null;
  76. }
  77. }
  78. private IEnumerator TransitionRoutine(Vector3 towardspos, float towardszoom, float durationseconds)
  79. {
  80. Vector3 startpos = this.rootContainer.localPosition;
  81. float startzoom = this._cachedCamera.orthographicSize;
  82. for (float i = 0f; i < durationseconds; i += Time.deltaTime)
  83. {
  84. float f = i / durationseconds;
  85. this.rootContainer.localPosition = Vector3.Lerp(startpos, -towardspos, f);
  86. this._cachedCamera.orthographicSize = Mathf.Lerp(startzoom, towardszoom, f);
  87. yield return null;
  88. }
  89. this.rootContainer.localPosition = -towardspos;
  90. this._cachedCamera.orthographicSize = towardszoom;
  91. this._transitionRoutine = null;
  92. yield break;
  93. }
  94. [SerializeField]
  95. private Transform rootContainer;
  96. private Camera _cachedCamera;
  97. private float _normalOrthoSize;
  98. private Vector3 _normalPosition;
  99. private IEnumerator _transitionRoutine;
  100. }