public void RegisterPresetDependency(TextAnimation child) { if (mPresetDependants != null && !mPresetDependants.Contains(child) && child != null) { mPresetDependants.Add(child); } }
public void InitTimes(TextAnimation se, bool force = false) { if (mRandomSeed < 0) { mRandomSeed = DRandom.GetSeed(); } int nElements = (se == null) ? 1 : TextAnimation.mCharacters.Size; if (mNumElements == nElements && !force) { return; } mNumElements = nElements; mTotalTime = 0; for (int i = 0, imax = _Sequences.Length; i < imax; ++i) //if (_Sequences[i]._Enabled || force) { _Sequences[i].InitTimes(se, this, i, nElements); float seqDuration = _Sequences[i].mTotalTime; if (mTotalTime < 0 || seqDuration < 0) { mTotalTime = float.MaxValue; } else { mTotalTime = mTotalTime > seqDuration ? mTotalTime : seqDuration; } } mTotalTime += _ExtraTimePerLoop; }
public override void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (anim.mTime < mDelay && !_InitAllElements) { return; } // Iterate through all the valid range for (int iElement = mElementRangeStart; iElement < mElementRangeEnd; ++iElement) { float progress = GetProgress(anim.mTime, anim, iElement); if (!_InitAllElements && progress < 0) { continue; } progress = progress < 0 ? 0 : progress; progress = _EasingCurve.Evaluate(progress); var currentColor = TextAnimation.mOriginalVertices.Buffer[iElement * 4].color; // Find Color for this Character var newColor = _Gradient.Evaluate(progress);//Color32.Lerp(cFrom, cTo, progress); //--[ Blend ]---------------------------- switch (_ColorBlend) { case eColorBlendMode.Replace: break; case eColorBlendMode.Multiply: newColor = newColor * currentColor; break; case eColorBlendMode.Additive: newColor = newColor + currentColor; break; case eColorBlendMode.AlphaBlend: newColor = Color.Lerp(currentColor, newColor, newColor.a); break; } if (_ApplyR) { currentColor.r = (byte)(newColor.r * 255); } if (_ApplyG) { currentColor.g = (byte)(newColor.g * 255); } if (_ApplyB) { currentColor.b = (byte)(newColor.b * 255); } if (_ApplyA) { currentColor.a = (byte)(newColor.a * 255); } // Apply to all Vertices for (int v = iElement * 4; v < iElement * 4 + 4; ++v) { TextAnimation.mOriginalVertices.Buffer[v].color = currentColor; } } }
public void OnEnable() { mTarget = target as TextAnimation; RegisterProperty_Animation(); //EditorApplication.update += UpdateAnims; }
public void UnRegisterPresetDependency(TextAnimation child) { if (mPresetDependants == null) { return; } mPresetDependants.Remove(child); mPresetDependants.RemoveAll(x => x == null); }
public override void OnStop(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (!Application.isPlaying || !_OnFinish_SetAlphaToFinalValue) { return; } var currentAlpha = se.mWidgetColor.a; float t = anim._Backwards ? 0 : 1; var progress = _EasingCurve.Evaluate(t); //--[ From ]---------------------------- float aFrom = _From * 255; if (_AnimBlend_From == eFloatAnimBlendMode.Offset) { aFrom = aFrom + currentAlpha; } if (_AnimBlend_From == eFloatAnimBlendMode.Blend) { aFrom = _From * currentAlpha; } if (HasRandom(_FromRandom)) { aFrom += 255 * _FromRandom * DRandom.GetUnit(0); } //--[ To ]---------------------------- float aTo = 255 * _To; if (_AnimBlend_To == eFloatAnimBlendMode.Offset) { aTo = (currentAlpha + _To); } if (_AnimBlend_To == eFloatAnimBlendMode.Blend) { aTo = (currentAlpha * _To); } if (HasRandom(_ToRandom)) { aTo += 255 * _ToRandom * DRandom.GetUnit(0 * 2 + 90); } // Find Alpha for this Character float falpha = (aFrom + (aTo - aFrom) * progress); byte alpha = (byte)(falpha < 0 ? 0 : falpha > 255 ? 255 : falpha); var color = se.mWidgetColor; color.a = alpha; se.SetWidgetColor(color); }
public void Play(TextAnimation se) { var anim = _Animation; if (anim != null) { anim.Play(se); } }
public static void UnregisterAnimation(TextAnimation se) { if (!Application.isPlaying) { return; } var manager = singleton; manager.mUpdate_Animations.Remove(se); }
public static void RegisterAnimation(TextAnimation se) { if (!Application.isPlaying) { return; } var manager = singleton; if (!manager.mUpdate_Animations.Contains(se)) { manager.mUpdate_Animations.Add(se); } }
public void Apply_Characters(TextAnimation se) { InitTimes(se); if (mNumElements <= 0) { return; } for (int i = 0, imax = _Sequences.Length; i < imax; ++i) { if (_Sequences[i]._Enabled) { _Sequences[i].Apply_Characters(se, this, i); } } }
public SE_Animation_Inspector(SE_Animation anim, TextAnimation se) { mTextAnimation = se; mAnimation = anim; if (mTextAnimation != null && !Application.isPlaying) { mTextAnimation.StopAllAnimations(false); } mAnimation.InitTimes(mTextAnimation, true); if (!Application.isPlaying) { mAnimation.Play(mTextAnimation); } AnimationControls_StopPlaying(true); }
public override void OnStop(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (!Application.isPlaying || !_OnFinish_SetColorToFinalValue) { return; } float t = anim._Backwards ? 0 : 1; var progress = _EasingCurve.Evaluate(t); var currentColor = se.mWidgetColor; // Find Color for this Character var newColor = _Gradient.Evaluate(progress); //--[ Blend ]---------------------------- switch (_ColorBlend) { case eColorBlendMode.Replace: break; case eColorBlendMode.Multiply: newColor = newColor * currentColor; break; case eColorBlendMode.Additive: newColor = newColor + currentColor; break; case eColorBlendMode.AlphaBlend: newColor = Color.Lerp(currentColor, newColor, newColor.a); break; } if (_ApplyR) { currentColor.r = (byte)(newColor.r * 255); } if (_ApplyG) { currentColor.g = (byte)(newColor.g * 255); } if (_ApplyB) { currentColor.b = (byte)(newColor.b * 255); } if (_ApplyA) { currentColor.a = (byte)(newColor.a * 255); } se.SetWidgetColor(currentColor); }
[NonSerialized][XmlIgnore] public int mNumElements; // Num elements in the TextAnimation component (used to know when the InitTime should be executed again if the text changes) #endregion public void Play(TextAnimation se) { if (se != null) { if (!se.mPlayingAnimations.Contains(this)) { se.mPlayingAnimations.Add(this); TextAnimationsManager.RegisterAnimation(se); } se.MarkWidgetAsChanged(); _OnFinished += (anim) => { se._OnAnimation_Finished.Invoke(anim); }; } IsPlaying = true; mTime = mRealTime = 0; mNumElements = -1; mRandomSeed = -1; InitTimes(se, true); }
public void Stop(TextAnimation se, bool executeCallback = true) { if (IsPlaying) { for (int i = 0; i < _Sequences.Length; ++i) { if (_Sequences[i]._Enabled) { _Sequences[i].OnStop(se, this, i); } } IsPlaying = false; if (executeCallback && _OnFinished != null) { _OnFinished(this); } se.mPlayingAnimations.Remove(this); se.MarkWidgetAsChanged(true, true); } _OnFinished = null; }
public override void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (anim.mTime < mDelay && !_InitAllElements) { return; } bool applyRandomFrom = HasRandom(_FromRandom); bool applyRandomTo = HasRandom(_ToRandom); DRandom.mCurrentSeed = GetRandomSeed(anim, sequenceIndex); Vector3 from = _From * se.mCharacterSize; Vector3 to = _To * se.mCharacterSize; Vector3 newValue = MathUtils.v3zero; if (_AnimBlend_From == ePositionAnimBlendMode.Replace) { from.x = MathUtils.LerpUnclamped(se.mAllCharactersMin.x, se.mAllCharactersMax.x, _From.x); from.y = MathUtils.LerpUnclamped(se.mAllCharactersMin.y, se.mAllCharactersMax.y, _From.y); } if (_AnimBlend_To == ePositionAnimBlendMode.Replace) { to.x = MathUtils.LerpUnclamped(se.mAllCharactersMin.x, se.mAllCharactersMax.x, _To.x); to.y = MathUtils.LerpUnclamped(se.mAllCharactersMin.y, se.mAllCharactersMax.y, _To.y); } // Iterate through all the valid range for (int iElement = mElementRangeStart; iElement < mElementRangeEnd; ++iElement) { float progress = GetProgress(anim.mTime, anim, iElement); if (!_InitAllElements && progress < 0) { continue; } progress = progress < 0 ? 0 : progress; float tx = _EasingCurve.Evaluate(progress); float ty = _UseAxisEasingCurves ? _EasingCurveY.Evaluate(progress) : tx; float tz = _UseAxisEasingCurves ? _EasingCurveZ.Evaluate(progress) : tx; var currentValue = TextAnimation.mOriginalVertices.Buffer[iElement * 4].position; var vFrom = (_AnimBlend_From == ePositionAnimBlendMode.Offset) ? (currentValue + from) : from; var vTo = (_AnimBlend_To == ePositionAnimBlendMode.Offset) ? (currentValue + to) : to; if (applyRandomFrom) { vFrom += GetRandom(_FromRandom * se.mCharacterSize, iElement); } if (applyRandomTo) { vTo += GetRandom(_ToRandom * se.mCharacterSize, iElement * 2 + 90); } if (_ApplyX) { newValue.x = vFrom.x + (vTo.x - vFrom.x) * tx; } if (_ApplyY) { newValue.y = vFrom.y + (vTo.y - vFrom.y) * ty; } if (_ApplyZ) { newValue.z = vFrom.z + (vTo.z - vFrom.z) * tz; } // Apply to all Vertices for (int v = iElement * 4; v < iElement * 4 + 4; ++v) { // Apply Lerp(vFrom, vTo, t) + offset_from_currentValue (the offset is applied to avoid changing the character's size) if (_ApplyX) { TextAnimation.mOriginalVertices.Buffer[v].position.x = newValue.x + (TextAnimation.mOriginalVertices.Buffer[v].position.x - currentValue.x); } if (_ApplyY) { TextAnimation.mOriginalVertices.Buffer[v].position.y = newValue.y + (TextAnimation.mOriginalVertices.Buffer[v].position.y - currentValue.y); } if (_ApplyZ) { TextAnimation.mOriginalVertices.Buffer[v].position.z = newValue.z + (TextAnimation.mOriginalVertices.Buffer[v].position.z - currentValue.z); } } } }
// Copy from SE_AnimSequence_Position, except where noted public override void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (anim.mTime < mDelay && !_InitAllElements) { return; } bool applyRandomFrom = HasRandom(_FromRandom); bool applyRandomTo = HasRandom(_ToRandom); DRandom.mCurrentSeed = GetRandomSeed(anim, sequenceIndex); Vector3 from = _From; // * se.mCharacterSize; // REMOVED *se.mCharacterSize Vector3 to = _To; // * se.mCharacterSize; // REMOVED *se.mCharacterSize Vector3 newValue = MathUtils.v3zero; // Iterate through all the valid range for (int iElement = mElementRangeStart; iElement < mElementRangeEnd; ++iElement) { float progress = GetProgress(anim.mTime, anim, iElement); if (!_InitAllElements && progress < 0) { continue; } progress = progress < 0 ? 0 : progress; float tx = _EasingCurve.Evaluate(progress); float ty = _UseAxisEasingCurves ? _EasingCurveY.Evaluate(progress) : tx; float tz = _UseAxisEasingCurves ? _EasingCurveZ.Evaluate(progress) : tx; var currentValue = MathUtils.v3one; // MODIFIED var vFrom = (_AnimBlend_From == ePositionAnimBlendMode.Replace) ? from : (currentValue + from); var vTo = (_AnimBlend_To == ePositionAnimBlendMode.Replace) ? to : (currentValue + to); if (applyRandomFrom) { vFrom += GetRandom(_FromRandom /* se.mCharacterSize*/, iElement); // REMOVED *se.mCharacterSize } if (applyRandomTo) { vTo += GetRandom(_ToRandom /* se.mCharacterSize*/, iElement * 2 + 90); // REMOVED *se.mCharacterSize } if (_ApplyX) { newValue.x = vFrom.x + (vTo.x - vFrom.x) * tx; } else { newValue.x = 0; } if (_ApplyY) { newValue.y = vFrom.y + (vTo.y - vFrom.y) * ty; } else { newValue.y = 0; } if (_ApplyZ) { newValue.z = vFrom.z + (vTo.z - vFrom.z) * tz; } else { newValue.z = 0; } // NEW CODE (in Scale)----------------------------------------------------------------------------------------------------------------------------------------- Vector3 vPivot = MathUtils.v3half; if (_PivotType == ePivotType.Relative_Letter || _PivotType == ePivotType.Relative_Word || _PivotType == ePivotType.Relative_Line) { vPivot.x = MathUtils.LerpUnclamped(TextAnimation.mCharacters.Buffer[iElement].Min.x, TextAnimation.mCharacters.Buffer[iElement].Max.x, _Pivot.x); vPivot.y = MathUtils.LerpUnclamped(TextAnimation.mCharacters.Buffer[iElement].Min.y, TextAnimation.mCharacters.Buffer[iElement].Max.y, _Pivot.y); } else if (_PivotType == ePivotType.Relative_All) { vPivot.x = MathUtils.LerpUnclamped(se.mAllCharactersMin.x, se.mAllCharactersMax.x, _Pivot.x); vPivot.y = MathUtils.LerpUnclamped(se.mAllCharactersMin.y, se.mAllCharactersMax.y, _Pivot.y); } else if (_PivotType == ePivotType.Relative_Rect) { vPivot.x = MathUtils.LerpUnclamped(se.mWidgetRectMin.x, se.mWidgetRectMax.x, _Pivot.x); vPivot.y = MathUtils.LerpUnclamped(se.mWidgetRectMin.y, se.mWidgetRectMax.y, _Pivot.y); } else { vPivot = _Pivot * se.mCharacterSize; } // END NEW CODE Quaternion qRot = Quaternion.Euler(newValue); // NEW CODE (for rotation)-------------------------------------------------------------------------- // Apply to all Vertices for (int v = iElement * 4; v < iElement * 4 + 4; ++v) { TextAnimation.mOriginalVertices.Buffer[v].position = qRot * (TextAnimation.mOriginalVertices.Buffer[v].position - vPivot) + vPivot; } } }
public virtual void UpdateSequence(float dt, TextAnimation se, SE_Animation anim, int sequenceIndex, ref bool makeMaterialDirty, ref bool makeVerticesDirty) { }
public void AnimUpdate(float dt, TextAnimation se, ref bool makeMaterialDirty, ref bool makeVerticesDirty) { if (se == null) { return; } InitTimes(se); if (mNumElements <= 0) { return; } if (mRealTime >= 0) { mRealTime += dt; switch (_Playback) { case SE_Animation.ePlayback.Loop: mTime = Mathf.Repeat(mRealTime, mTotalTime); break; case SE_Animation.ePlayback.PingPong: { mTime = Mathf.Repeat(mRealTime, 2 * mTotalTime); if (mTime > mTotalTime) { mTime = mTotalTime - (mTime - mTotalTime); } break; } default: //case ePlayback.Single: mTime = mRealTime; break; } if (_Backwards) { mTime = mTotalTime - mTime; } float mFinalTime = mTotalTime; if (_Playback != SE_Animation.ePlayback.Single) { mFinalTime = _PlaybackTimes <= 0 ? -1 : (mTotalTime * _PlaybackTimes); } if (mFinalTime > 0 && mRealTime >= (mFinalTime + _ExtraTimeFinal)) { mRealTime = mFinalTime; Stop(se); } } for (int i = 0, imax = _Sequences.Length; i < imax; ++i) { if (_Sequences[i]._Enabled) { _Sequences[i].UpdateSequence(dt, se, this, i, ref makeMaterialDirty, ref makeVerticesDirty); } } }
public virtual void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { }
public virtual void OnStop(TextAnimation se, SE_Animation anim, int sequenceIndex) { }
public override void UpdateSequence(float dt, TextAnimation se, SE_Animation anim, int sequenceIndex, ref bool makeMaterialDirty, ref bool makeVerticesDirty) { base.UpdateSequence(dt, se, anim, sequenceIndex, ref makeMaterialDirty, ref makeVerticesDirty); makeVerticesDirty = true; }
public virtual void InitTimes(TextAnimation se, SE_Animation anim, int sequenceIndex, int nElements) { switch (_StartType) { case eStartType.AfterPrevious: { if (sequenceIndex > 0) { mDelay = anim._Sequences[sequenceIndex - 1].mTotalTime; } break; } case eStartType.AllPrevious: { mDelay = 0; for (int i = 0; i < sequenceIndex; ++i) { mDelay = Mathf.Max(mDelay, anim._Sequences[sequenceIndex].mTotalTime); } break; } case eStartType.WithPrevious: { if (sequenceIndex > 0) { mDelay = anim._Sequences[sequenceIndex - 1].mDelay; } break; } case eStartType.AllUsedElements: { mDelay = 0; for (int i = 0; i < sequenceIndex; ++i) { if (anim._Sequences[sequenceIndex].IsUsingCommonElements(this)) { mDelay = Mathf.Max(mDelay, anim._Sequences[sequenceIndex].mTotalTime); } } break; } default: //case eStartType.OnAnimStart: { mDelay = 0; break; } } mDelay += _StartDelay; //--[ Get Animation Range ]-------------------------------- mElementRangeStart = 0; mElementRangeEnd = nElements; switch (_TargetRangeType) { case eTargetRange.All: mElementRangeStart = 0; mElementRangeEnd = nElements; break; case eTargetRange.First: mElementRangeStart = 0; mElementRangeEnd = _TargetRangeAmount; break; case eTargetRange.Last: mElementRangeStart = nElements - _TargetRangeAmount; mElementRangeEnd = nElements; break; case eTargetRange.Range: mElementRangeStart = _TargetRangeStart; mElementRangeEnd = _TargetRangeStart + _TargetRangeAmount; break; } nElements = mElementRangeEnd - mElementRangeStart; //--[ Find Times ]-------------------------------- if (_DurationType == eDurationType.PerElement) { mElementDuration = _Duration; mLoopDuration = mElementDuration + (mElementDuration * _Separation * (nElements - 1)); } else { mLoopDuration = _Duration; mElementDuration = mLoopDuration / (_Separation * nElements - _Separation + 1); } mElementDelay = mElementDuration * _Separation; mTotalLoopDuration = _Playback == SE_Animation.ePlayback.PingPong ? 2 * mLoopDuration : mLoopDuration; if (_Playback == SE_Animation.ePlayback.Loop || _Playback == SE_Animation.ePlayback.PingPong) { if (_PlaybackTimes > 0) { mTotalTime = mDelay + mLoopDuration * _PlaybackTimes; } else { mTotalTime = float.MaxValue; } } else { mTotalTime = mDelay + mLoopDuration; } }
public override void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { if (anim.mTime < mDelay && !_InitAllElements) { return; } bool applyRandomFrom = HasRandom(_FromRandom); bool applyRandomTo = HasRandom(_ToRandom); DRandom.mCurrentSeed = GetRandomSeed(anim, sequenceIndex); // Iterate through all the valid range for (int iElement = mElementRangeStart; iElement < mElementRangeEnd; ++iElement) { float progress = GetProgress(anim.mTime, anim, iElement); if (!_InitAllElements && progress < 0) { continue; } progress = progress < 0 ? 0 : progress; progress = _EasingCurve.Evaluate(progress); var currentAlpha = TextAnimation.mOriginalVertices.Buffer[iElement * 4].color.a; //--[ From ]---------------------------- float aFrom = _From * 255; if (_AnimBlend_From == eFloatAnimBlendMode.Offset) { aFrom = aFrom + currentAlpha; } if (_AnimBlend_From == eFloatAnimBlendMode.Blend) { aFrom = _From * currentAlpha; } if (applyRandomFrom) { aFrom += 255 * _FromRandom * DRandom.GetUnit(iElement); } //--[ To ]---------------------------- float aTo = 255 * _To; if (_AnimBlend_To == eFloatAnimBlendMode.Offset) { aTo = (currentAlpha + _To); } if (_AnimBlend_To == eFloatAnimBlendMode.Blend) { aTo = (currentAlpha * _To); } if (applyRandomTo) { aTo += 255 * _ToRandom * DRandom.GetUnit(iElement * 2 + 90); } // Find Alpha for this Character float falpha = (aFrom + (aTo - aFrom) * progress); byte alpha = (byte)(falpha < 0?0 : falpha > 255?255: falpha); // Apply to all Vertices for (int v = iElement * 4; v < iElement * 4 + 4; ++v) { TextAnimation.mOriginalVertices.Buffer[v].color.a = alpha; } } }
public override void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex) { base.Apply_Characters(se, anim, sequenceIndex); }