|
- using System;
- using System.Collections;
- using SUISS.Core;
- using SUISS.Scheduling;
- using UnityEngine;
-
- public class CameraTransition : MonoBehaviour
- {
- protected virtual void Awake()
- {
- this._cachedCamera = base.GetComponent<Camera>();
- this._normalOrthoSize = this._cachedCamera.orthographicSize;
- this._normalPosition = base.transform.localPosition;
- }
-
- protected virtual void Start()
- {
- }
-
- protected virtual void OnDestroy()
- {
- this.StopTransition();
- }
-
- public void ZoomInOnInstant(GameObject go)
- {
- this.StopTransition();
- Vector3 a;
- if (go == null)
- {
- a = this._normalPosition;
- }
- else
- {
- SpriteRenderer component = go.GetComponent<SpriteRenderer>();
- if (component != null)
- {
- a = component.bounds.center;
- }
- else
- {
- a = go.transform.localPosition;
- }
- }
- this.rootContainer.localPosition = -a;
- this._cachedCamera.orthographicSize = 0f;
- }
-
- public void ZoomInOn(GameObject go, float durationseconds)
- {
- this.StopTransition();
- SpriteRenderer component = go.GetComponent<SpriteRenderer>();
- Vector3 towardspos;
- if (component != null)
- {
- towardspos = component.bounds.center;
- }
- else
- {
- towardspos = go.transform.localPosition;
- }
- SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._transitionRoutine = this.TransitionRoutine(towardspos, 0f, durationseconds));
- }
-
- public void ZoomOutInstant()
- {
- this.StopTransition();
- this.rootContainer.localPosition = -this._normalPosition;
- this._cachedCamera.orthographicSize = this._normalOrthoSize;
- }
-
- public void ZoomOut(float durationseconds)
- {
- this.StopTransition();
- SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._transitionRoutine = this.TransitionRoutine(this._normalPosition, this._normalOrthoSize, durationseconds));
- }
-
- public void StopTransition()
- {
- if (this._transitionRoutine != null && SingletonMonobehaviour<Scheduler>.IsAvailable)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._transitionRoutine);
- this._transitionRoutine = null;
- }
- }
-
- private IEnumerator TransitionRoutine(Vector3 towardspos, float towardszoom, float durationseconds)
- {
- Vector3 startpos = this.rootContainer.localPosition;
- float startzoom = this._cachedCamera.orthographicSize;
- for (float i = 0f; i < durationseconds; i += Time.deltaTime)
- {
- float f = i / durationseconds;
- this.rootContainer.localPosition = Vector3.Lerp(startpos, -towardspos, f);
- this._cachedCamera.orthographicSize = Mathf.Lerp(startzoom, towardszoom, f);
- yield return null;
- }
- this.rootContainer.localPosition = -towardspos;
- this._cachedCamera.orthographicSize = towardszoom;
- this._transitionRoutine = null;
- yield break;
- }
-
- [SerializeField]
- private Transform rootContainer;
-
- private Camera _cachedCamera;
-
- private float _normalOrthoSize;
-
- private Vector3 _normalPosition;
-
- private IEnumerator _transitionRoutine;
- }
|