Ejemplo n.º 1
0
        public float GetFinalTime(SE_Animation anim, int index)
        {
            float start, eDuration;

            GetElementTimes(anim, index, out start, out eDuration);
            return(start + eDuration);
        }
        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 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);
        }
Ejemplo n.º 4
0
        public virtual int GetRandomSeed(SE_Animation anim, int sequenceIndex)
        {
            float t = anim.mTime - mDelay;

            if (t < 0.0001f)
            {
                t = 0.0001f;
            }
            return(anim.mRandomSeed + (anim.GetCurrentLoop() * anim._Sequences.Length + Mathf.CeilToInt(t / mTotalLoopDuration)) * 20 * sequenceIndex);
        }
Ejemplo n.º 5
0
 public SE_Animation CreateAnimation()
 {
     if (_Preset != null)
     {
         mAnimation = _Preset.CreateAnimation();
     }
     else
     {
         mAnimation = SE_Animation.LoadFromSerializedData(_LocalSerializedData) ?? new SE_Animation();
     }
     return(mAnimation);
 }
        public override void OnInspectorGUI()
        {
                        #if UNITY_5_6_OR_NEWER
            serializedObject.UpdateIfRequiredOrScript();
                        #else
            serializedObject.UpdateIfDirtyOrScript();
                        #endif

            EditorGUIUtility.labelWidth = 50;

            GUI.backgroundColor = Color.Lerp(Color.black, Color.gray, 1);
            GUILayout.BeginVertical(I2_InspectorTools.GUIStyle_Background, GUILayout.Height(1));
            GUI.backgroundColor = Color.white;


            //--[ HEADER ]----------------------
            if (GUILayout.Button("SE Animation", I2_InspectorTools.GUIStyle_Header))
            {
                //Application.OpenURL(SE_InspectorTools.HelpURL_Documentation);
            }

            GUILayout.Space(5);

            //--[ INSPECTOR ]---------------------

            EditorGUI.BeginChangeCheck();

            mInspector.OnGUI_Animation();

            if (EditorGUI.EndChangeCheck() || mDirty)
            {
                mDirty = false;
                var data = SE_Animation.SaveSerializedData(mInspector.mAnimation);
                if (mProp_SerializedData.stringValue != data)
                {
                    mProp_SerializedData.stringValue = data;
                    //Debug.Log(data);
                }
            }

            //--[ FOOTER ]-------------------------
            GUILayout.Space(10);
            GUILayout.FlexibleSpace();

            GUITools.OnGUI_Footer("I2 TextAnimation", I2_InspectorTools.GetVersion(), I2_InspectorTools.HelpURL_forum, I2_InspectorTools.HelpURL_Documentation, I2_InspectorTools.HelpURL_AssetStore);

            EditorGUIUtility.labelWidth = 0;

            GUILayout.EndVertical();

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 7
0
 public static string SaveSerializedData(SE_Animation anim)
 {
     try
     {
         var writer     = new System.IO.StringWriter(System.Globalization.CultureInfo.InvariantCulture);
         var serializer = new System.Xml.Serialization.XmlSerializer(typeof(SE_Animation), mAnimSequenceTypes);
         serializer.Serialize(writer, anim);
         //Debug.Log(writer.ToString());
         return(writer.ToString());
     }
     catch (Exception) { }
     return(null);
 }
        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);
        }
Ejemplo n.º 10
0
        public void GetElementTimes(SE_Animation anim, int index, out float startTime, out float elementDuration)
        {
            startTime       = index * mElementDelay;
            elementDuration = mElementDuration;
            float loopTime = mTotalTime - mDelay;

            int randomSeedBase = anim.mRandomSeed + 10 * anim.GetCurrentLoop() - DRandom.mCurrentSeed;

            if (_DurationRandom_Slower > 0 || _DurationRandom_Faster > 0)
            {
                float durRangeSlower = _DurationRandom_Slower * loopTime;
                float durRangeFaster = _DurationRandom_Faster * elementDuration;

                float minDuration = elementDuration - durRangeFaster; if (minDuration < 0.001f)
                {
                    minDuration = 0.001f;
                }
                float maxDuration = elementDuration + durRangeSlower; if (maxDuration > loopTime - startTime)
                {
                    maxDuration = loopTime - startTime;
                }
                elementDuration = DRandom.Get(index + randomSeedBase, minDuration, maxDuration);
            }

            if (_RandomStart > 0)
            {
                float randRange = _RandomStart * loopTime;
                float minStart  = startTime - randRange; if (minStart < 0)
                {
                    minStart = 0;
                }
                float maxStart = startTime + randRange; if (maxStart > loopTime - elementDuration)
                {
                    maxStart = loopTime - elementDuration;
                }
                startTime = DRandom.Get(index + randomSeedBase, minStart, maxStart);
            }

            if (_Backwards)
            {
                startTime = mTotalTime - (startTime + mDelay) - elementDuration;
            }
        }
        public void OnGUI_AnimationSlot()
        {
            var prop_Slot          = mSerialized_AnimationSlots.GetArrayElementAtIndex(mAnimationsReorderableList.index);
            var prop_SlotPreset    = prop_Slot.FindPropertyRelative("_Preset");
            var prop_SlotLocalData = prop_Slot.FindPropertyRelative("_LocalSerializedData");

            if (mEditor_SelectedAnim == null || iCurrentAnimationSlot != mAnimationsReorderableList.index)
            {
                iCurrentAnimationSlot = mAnimationsReorderableList.index;

                if (prop_SlotPreset.objectReferenceValue != null)
                {
                    mSerializedObject_SelectedAnim = new SerializedObject(prop_SlotPreset.objectReferenceValue);
                }
                else
                {
                    mSerializedObject_SelectedAnim = null;
                }

                DestroyAnimationInspector();

                mEditor_SelectedAnim = new SE_Animation_Inspector(mTarget._AnimationSlots[iCurrentAnimationSlot]._Animation /*CreateAnimation()*/, mTarget);
            }

            if (prop_SlotPreset.objectReferenceValue != null && mSerializedObject_SelectedAnim != null)
            {
                                #if UNITY_5_6_OR_NEWER
                mSerializedObject_SelectedAnim.UpdateIfRequiredOrScript();
                                #else
                mSerializedObject_SelectedAnim.UpdateIfDirtyOrScript();
                                #endif
            }

            GUILayout.Space(10);


            //GUITools.DrawHeader("Animation", true);
            var boxArea = new GUIStyle("Box");
            boxArea.overflow = new RectOffset(2, 2, 0, 0);
            bool deselectAnimation = false;
            GUILayout.BeginHorizontal(boxArea);
            GUILayout.Toggle(true, "Animation", EditorStyles.foldout);
            GUILayout.FlexibleSpace();
            deselectAnimation = GUILayout.Button("X", EditorStyles.miniButton);
            GUILayout.EndHorizontal();

            GUILayout.Space(-4);


            GUI.backgroundColor = GUITools.DarkGray;
            GUILayout.BeginVertical(/*EditorStyles.textArea, */ GUILayout.Height(1));
            GUI.backgroundColor = Color.white;

            EditorGUI.BeginChangeCheck();
            mEditor_SelectedAnim.OnGUI_Animation();

            if (EditorGUI.EndChangeCheck() || SE_AnimationPreset_Inspector.mDirty)
            {
                SE_AnimationPreset_Inspector.mDirty = false;

                var data = SE_Animation.SaveSerializedData(mEditor_SelectedAnim.mAnimation);
                if (prop_SlotLocalData.stringValue != data)
                {
                    prop_SlotLocalData.stringValue = data;
                    //Debug.Log(data);
                }

                if (prop_SlotPreset.objectReferenceValue != null)
                {
                    var prop_PresetData = mSerializedObject_SelectedAnim.FindProperty("mSerializedData");
                    if (prop_PresetData.stringValue != data)
                    {
                        prop_PresetData.stringValue = data;
                        mSerializedObject_SelectedAnim.ApplyModifiedProperties();
                        //mTarget._AnimationSlots[iCurrentAnimationSlot].CreateAnimation();
                    }
                }
            }
            if (mEditor_SelectedAnim.mAnimation.IsPlaying)
            {
                mMakeMaterialDirty = mMakeVerticesDirty = true;
            }


            GUITools.CloseHeader();

            if (deselectAnimation)
            {
                DeselectAnimation();
            }
        }
 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;
 }
Ejemplo n.º 13
0
        public float GetProgress(float time, SE_Animation anim, int characterID)
        {
            //--[ Verify that the animation is playing ]--------------------------------
            if (time < mDelay)
            {
                return(-1);
            }
            if (time > mTotalTime)
            {
                time = mTotalTime;
            }

            //--[ Only accept elements in the Characters Range ]--------------------------------

            int elementId = characterID;
            int nElements = TextAnimation.mCharacters.Size;

            if (mElementRangeEnd <= mElementRangeStart || elementId < mElementRangeStart || elementId >= mElementRangeEnd)
            {
                return(-1);
            }

            //--[ only accept those elements in the Custom array ]--------------------------------

            if (_TargetRangeType == eTargetRange.Custom && _TargetRangeCustom != null)
            {
                bool found = false;
                for (int i = 0, imax = _TargetRangeCustom.Length; i < imax; ++i)
                {
                    if (_TargetRangeCustom[i] == characterID)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(-1);
                }
            }

            if (time >= mTotalTime)
            {
                return(1);
            }

            time -= mDelay;

            nElements  = mElementRangeEnd - mElementRangeStart;
            elementId -= mElementRangeStart;


            //--[ Apply Playback ]--------------------------------

            switch (_Playback)
            {
            case SE_Animation.ePlayback.Loop:
                time           = Mathf.Repeat(time, mLoopDuration);
                mElementDelay -= 0.5f * mElementDelay / (float)nElements;
                break;

            case SE_Animation.ePlayback.PingPong:
            {
                time           = Mathf.Repeat(time, 2 * mLoopDuration);
                mElementDelay -= 0.5f * mElementDelay / (float)nElements;
                if (time > mLoopDuration)
                {
                    time  = mLoopDuration - (time - mLoopDuration);
                    time -= 0.25f * mElementDelay;
                }
                break;
            }

            default:     //case ePlayback.Single:
                break;
            }


            //--[ Find element progress and apply Easing ]--------------------------------
            float startTime, elementDuration;

            GetElementTimes(anim, elementId, out startTime, out elementDuration);


            float t = (time - startTime) / elementDuration;

            t = t > 1 ? 1 : t;
            return(t);
        }
Ejemplo n.º 14
0
 public virtual void Apply_Characters(TextAnimation se, SE_Animation anim, int sequenceIndex)
 {
 }
Ejemplo n.º 15
0
 public virtual void UpdateSequence(float dt, TextAnimation se, SE_Animation anim, int sequenceIndex, ref bool makeMaterialDirty, ref bool makeVerticesDirty)
 {
 }
Ejemplo n.º 16
0
        // 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;
                }
            }
        }
Ejemplo n.º 17
0
 public virtual void OnStop(TextAnimation se, SE_Animation anim, int sequenceIndex)
 {
 }
Ejemplo n.º 18
0
        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;
            }
        }
Ejemplo n.º 19
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 20
0
 public SE_Animation CreateAnimation()
 {
     return(SE_Animation.LoadFromSerializedData(mSerializedData) ?? new SE_Animation());
 }
        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);
 }