public void initRot() { rotation = Quaternion.identity; PRSInfo info = m_TweenList[1]; // rotation info info.m_Factor = 1; }
public void SetOffset(PRSType type, Vector3 to) { int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { PRSInfo info = (PRSInfo)m_TweenList[index]; info.m_Offset = to; } }
public void setEnableSpeed(PRSType type, bool enable) { int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { PRSInfo info = (PRSInfo)m_TweenList[index]; info.m_IsSpeed = enable; } }
public List <EventDelegate> GetOnFinished(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? info.onFinished : null); }
public AnimationCurve GetAnimationCurve(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? info.m_AnimationCurve : null); }
public float GetDuration(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? (info.m_IsSpeed ? info.m_Speed : info.m_Duration) : 0f); }
public Style GetStyle(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? info.m_Style : Style.Once); }
public bool isSpeed(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? info.m_IsSpeed : false); }
public Vector3 GetOffset(PRSType type) { PRSInfo info = null; int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { info = (PRSInfo)m_TweenList[index]; } return(info != null ? info.m_Offset : Vector3.zero); }
void UpdatePRS(PRSInfo info, float delta) { if (!enabled) { return; } float factor = (info.m_AnimationCurve != null) ? info.m_AnimationCurve.Evaluate(info.m_Factor) : info.m_Factor; Vector3 from = info.m_From, to = info.m_To; if (info.m_IsSpeed) { from = pos; } if (info.m_EnableOffset) { if (info.m_Type == PRSType.Pos) { from = m_InitPos; } else if (info.m_Type == PRSType.Rot) { from = m_InitRot; } else if (info.m_Type == PRSType.Scale) { from = m_initScale; } to = from + info.m_Offset; } if (info.m_Type == PRSType.Pos) { pos = info.m_IsSpeed ? (from + info.m_Speed * delta * info.m_Dir) : (from * (1f - factor) + to * factor); } else if (info.m_Type == PRSType.Scale) { scale = (from * (1f - factor) + to * factor); } else { rotation = Quaternion.Euler(new Vector3( Mathf.Lerp(from.x, to.x, factor), Mathf.Lerp(from.y, to.y, factor), Mathf.Lerp(from.z, to.z, factor))); } }
public void SetTo(PRSType type, Vector3 to) { int index = getIndex(type); if (index > -1 && index < m_TweenList.Length) { PRSInfo info = (PRSInfo)m_TweenList[index]; info.m_To = to; if (type == PRSType.Pos && info.m_IsSpeed) { info.m_Dir = info.m_To - info.m_From; info.m_Dir.Normalize(); } } }
bool isFinish(PRSInfo info) { bool finish = false; if (info.m_IsSpeed) { finish = (info.m_From.x > info.m_To.x && pos.x <= info.m_To.x && info.m_From.y > info.m_To.y && pos.y <= info.m_To.y) || (info.m_From.x > info.m_To.x && pos.x <= info.m_To.x && info.m_From.y <= info.m_To.y && pos.y >= info.m_To.y) || (info.m_From.x <= info.m_To.x && pos.x >= info.m_To.x && info.m_From.y > info.m_To.y && pos.y <= info.m_To.y) || (info.m_From.x <= info.m_To.x && pos.x >= info.m_To.x && info.m_From.y <= info.m_To.y && pos.y >= info.m_To.y); } else { finish = (info.m_Duration == 0f || info.m_Factor > 1f || info.m_Factor < 0f); } return(finish); }
// Update is called once per frame void FixedUpdate() { if (!m_init) { init(); } float delta = Time.deltaTime; //foreach (PRSInfo info in m_TweenList) for (int nIndex = 0; nIndex < m_TweenList.Length; nIndex++) { PRSInfo info = m_TweenList[nIndex]; if (!info.m_Enable) { continue; } UpdateFactor(info, delta); UpdatePRS(info, delta); } }
bool isSetCurrentValue() { //foreach (PRSInfo info in m_TweenList) for (int nIndex = 0; nIndex < m_TweenList.Length; nIndex++) { PRSInfo info = m_TweenList[nIndex]; if (!info.m_Enable) { continue; } if (info.m_EnableOffset == false && (info.m_From == Vector3.zero || info.m_To == Vector3.zero)) { return(true); } else if (info.m_EnableOffset == true && info.m_Offset == Vector3.zero) { return(true); } } return(false); }
void SetEndToCurrentValue() { //foreach (PRSInfo info in m_TweenList) for (int nIndex = 0; nIndex < m_TweenList.Length; nIndex++) { PRSInfo info = m_TweenList[nIndex]; //if (!info.m_Enable) // continue; if (info.m_Type == PRSType.Pos) { info.m_To = pos; } else if (info.m_Type == PRSType.Rot) { info.m_To = rotation.eulerAngles; } else { info.m_To = scale; } } }
public void Play(bool _forward, bool _initFactor = false) { //foreach (PRSInfo info in m_TweenList) for (int nIndex = 0; nIndex < m_TweenList.Length; nIndex++) { PRSInfo info = m_TweenList[nIndex]; if (!info.m_Enable) { continue; } info.m_AmountPerDelta = Mathf.Abs(info.m_AmountPerDelta); if (!_forward) { info.m_Factor = info.m_Factor <= 0f ? 1.0f : info.m_Factor; if (_initFactor) { info.m_Factor = info.m_Factor <= 0f ? 1.0f : 0; } info.m_AmountPerDelta = -info.m_AmountPerDelta; } else { info.m_Factor = info.m_Factor >= 1f ? 0.0f : info.m_Factor; if (_initFactor) { info.m_Factor = info.m_Factor >= 1f ? 0.0f : 1; } } } enabled = true; FixedUpdate(); }
void UpdateFactor(PRSInfo info, float delta) { info.m_Factor += info.m_AmountPerDelta * delta; if (info.m_Style == Style.Loop) { if (info.m_Factor > 1f) { info.m_Factor -= Mathf.Floor(info.m_Factor); } } else if (info.m_Style == Style.PingPong) { if (info.m_Factor > 1f) { info.m_Factor = 1f - (info.m_Factor - Mathf.Floor(info.m_Factor)); info.m_AmountPerDelta = -info.m_AmountPerDelta; } else if (info.m_Factor < 0f) { info.m_Factor = -info.m_Factor; info.m_Factor -= Mathf.Floor(info.m_Factor); info.m_AmountPerDelta = -info.m_AmountPerDelta; } } if ((info.m_Style == Style.Once) && isFinish(info)) { info.m_Factor = Mathf.Clamp01(info.m_Factor); if (!info.m_IsSpeed && (info.m_Factor == 1f && info.m_AmountPerDelta > 0f || info.m_Factor == 0f && info.m_AmountPerDelta < 0f)) { enabled = false; } else if (info.m_IsSpeed) { enabled = false; } if (info.onFinished != null) { m_Temp = info.onFinished; info.onFinished = new List <EventDelegate>(); EventDelegate.Execute(m_Temp); for (int i = 0; i < m_Temp.Count; ++i) { EventDelegate ed = m_Temp[i]; if (ed != null) { EventDelegate.Add(info.onFinished, ed, ed.oneShot); } } m_Temp = null; } } else { info.m_Factor = Mathf.Clamp01(info.m_Factor); } //info.m_Factor = (info.m_AnimationCurve != null) ? info.m_AnimationCurve.Evaluate(info.m_Factor) : info.m_Factor; }