123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using UnityEngine;
- using System.Collections;
- public enum ZoomPhase
- {
- Stay,
- Forward,
- Bacward,
- }
- public class Zoom2D : MoveRoot
- {
- #region 变量
- public float Stay;
- public float Timer;
- public float Duration;
- public float TempTime;
- public float OnewayTime;
- public float SizeDelta;
- public float SizeOrigin;
- public float SizeDestination;
- public Vector3 PosDelta;
- public Vector3 PosOrigin;
- public Vector3 PosDestination;
- public Camera Camera;
- public Transform Target;
- public ZoomPhase Phase;
- public CurveFunctionF SizeFunc;
- public CurveFunctionV VecFunc;
- #endregion
- public Zoom2D(Camera camera)
- {
- Camera = camera;
- }
- public override bool DoForward()
- {
- Timer += Time.deltaTime;
- if (Timer < TempTime)
- {
- if (Phase == ZoomPhase.Forward)
- {
- Camera.orthographicSize = SizeFunc(Timer, OnewayTime, SizeOrigin, SizeDelta);
- Camera.transform.position = VecFunc(Timer, OnewayTime, PosOrigin, PosDelta);
- }
- else if (Phase == ZoomPhase.Bacward)
- {
- Camera.orthographicSize = SizeFunc(Timer, OnewayTime, SizeDestination, -SizeDelta);
- Camera.transform.position = VecFunc(Timer, OnewayTime, PosDestination, -PosDelta);
- }
- return false;
- }
- else
- {
- if (Phase == ZoomPhase.Forward)
- {
- Phase = ZoomPhase.Stay;
- Timer = 0;
- TempTime = Stay;
- Camera.orthographicSize = SizeDestination;
- Camera.transform.position = PosDestination;
- return false;
- }
- else if (Phase == ZoomPhase.Stay)
- {
- Phase = ZoomPhase.Bacward;
- Timer = 0;
- TempTime = OnewayTime;
- return false;
- }
- else if (Phase == ZoomPhase.Bacward)
- {
- Timer = 0;
- Camera.orthographicSize = SizeOrigin;
- Camera.transform.position = PosOrigin;
- OnForwardFinish.SafeInvoke();
- return true;
- }
- throw new Exception();
- }
- }
- public override bool DoBackward()
- {
- throw new Exception();
- }
- public void StartZoom(float sizeOrigin, float sizeDestination, float duration, float stay, Transform target, Curve curve)
- {
- OnForwardStart.SafeInvoke();
- Stay = stay;
- Duration = duration;
- OnewayTime = (duration - stay)/2;
- SizeDelta = sizeDestination - sizeOrigin;
- SizeOrigin = sizeOrigin;
- SizeDestination = sizeDestination;
- PosDelta = target.position - Camera.transform.position;
- PosOrigin = Camera.transform.position;
- PosDestination = target.position;
- PosDelta.z = 0;
- PosDestination.z = Camera.transform.position.z;
- Target = target;
- TempTime = OnewayTime;
- Phase = ZoomPhase.Forward;
- VecFunc = ManaAnim.CurveFuncDicV[curve];
- SizeFunc = ManaAnim.CurveFuncDicF[curve];
- ManaAnim.MoveForList.Remove(this);
- ManaAnim.MoveForList.Add(this);
- }
- }
|