├── example.gif ├── ProjectSettings ├── ProjectVersion.txt ├── TagManager.asset ├── TimeManager.asset ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── DynamicsManager.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── UnityAdsSettings.asset ├── Physics2DSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── TextFader.unitypackage ├── Assets ├── TextFader │ ├── Demo │ │ ├── Scenes │ │ │ ├── DemoScene.unity │ │ │ └── DemoScene.unity.meta │ │ └── Scenes.meta │ ├── Demo.meta │ ├── CharFader.cs.meta │ ├── TextFader.cs.meta │ ├── CharLimiter.cs.meta │ ├── CharLimiter.cs │ ├── CharFader.cs │ └── TextFader.cs └── TextFader.meta ├── .gitignore ├── LICENSE └── README.md /example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/example.gif -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.4.2f2 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /TextFader.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/TextFader.unitypackage -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/TextFader/Demo/Scenes/DemoScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miguel12345/TextFader/HEAD/Assets/TextFader/Demo/Scenes/DemoScene.unity -------------------------------------------------------------------------------- /Assets/TextFader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 160aacf6aafe9452497324270ff9cb3a 3 | folderAsset: yes 4 | timeCreated: 1478713186 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/TextFader/Demo/Scenes/DemoScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9196324d5dbe14631bc89407d7ff8654 3 | timeCreated: 1478714277 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/TextFader/Demo.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81ba06637fa0a4409b2333820f57a547 3 | folderAsset: yes 4 | timeCreated: 1478714277 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/TextFader/Demo/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6c6fc4c2f2a82474a8f6c652b0c4a082 3 | folderAsset: yes 4 | timeCreated: 1478714277 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/TextFader/CharFader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b751d15fcc43f4983985f3267c9b0223 3 | timeCreated: 1478713285 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/TextFader/TextFader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 103ce685a7b7c4242b60cc1cac29bd47 3 | timeCreated: 1478713291 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/TextFader/CharLimiter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b47245c6d8b447379fa6aca190795cd 3 | timeCreated: 1478713245 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | 28 | # Builds 29 | *.apk 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Miguel Ferreira 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Assets/TextFader/CharLimiter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityEngine.UI; 4 | using System.Collections.Generic; 5 | 6 | public class CharLimiter : BaseMeshEffect, IMeshModifier { 7 | 8 | [SerializeField] 9 | int m_NumberOfLetters = -1; 10 | 11 | public int NumberOfLetters { 12 | get { 13 | return m_NumberOfLetters; 14 | } 15 | set { 16 | 17 | if( value == m_NumberOfLetters ) 18 | return; 19 | 20 | m_NumberOfLetters = value; 21 | graphic.SetVerticesDirty(); 22 | } 23 | } 24 | 25 | static List tmpVertices = new List(); 26 | static UIVertex[] tmpVerticesQuad = new UIVertex[4]; 27 | 28 | public override void ModifyMesh(VertexHelper toFill) 29 | { 30 | if (!IsActive()) 31 | return; 32 | 33 | if( m_NumberOfLetters == -1 ) 34 | return; 35 | 36 | int vertCount = toFill.currentVertCount; 37 | 38 | for( int i = 0; i < vertCount; i++ ) 39 | { 40 | if( tmpVertices.Count < (i+1) ) 41 | { 42 | tmpVertices.Add( new UIVertex() ); 43 | } 44 | UIVertex vert = tmpVertices[i]; 45 | toFill.PopulateUIVertex( ref vert, i ); 46 | tmpVertices[i] = vert; 47 | } 48 | 49 | int numberOfVertices = m_NumberOfLetters * 4; 50 | toFill.Clear(); 51 | 52 | for( int i = 0; i < numberOfVertices && i < tmpVertices.Count; i++ ) 53 | { 54 | int tempVertsIndex = i & 3; 55 | tmpVerticesQuad[tempVertsIndex] = tmpVertices[i]; 56 | if( tempVertsIndex == 3 ) 57 | { 58 | toFill.AddUIVertexQuad( tmpVerticesQuad ); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TextFader 2 | 3 | Add a beautiful char-by-char fade in animation to your texts by just adding a simple script. 4 | 5 | ![](example.gif) 6 | 7 | 0 runtime performance implications and 0 gc allocs. 8 | 9 | ##Usage 10 | 11 | Add the `TextFader` script to your `Text` element. You can set it to automatically start when enabled, or you can start it yourself by invoking its `PerformAnimation` method. 12 | 13 | ##License 14 | MIT License 15 | 16 | Copyright (c) 2016 Miguel Ferreira 17 | 18 | Permission is hereby granted, free of charge, to any person obtaining a copy 19 | of this software and associated documentation files (the "Software"), to deal 20 | in the Software without restriction, including without limitation the rights 21 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | copies of the Software, and to permit persons to whom the Software is 23 | furnished to do so, subject to the following conditions: 24 | 25 | The above copyright notice and this permission notice shall be included in all 26 | copies or substantial portions of the Software. 27 | 28 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 34 | SOFTWARE. -------------------------------------------------------------------------------- /Assets/TextFader/CharFader.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityEngine.UI; 4 | using System.Collections.Generic; 5 | 6 | public class CharFader : BaseMeshEffect, IMeshModifier { 7 | 8 | static List tmpVertices = new List(); 9 | static UIVertex[] tmpVerticesQuad = new UIVertex[4]; 10 | 11 | int charIndex = -1; 12 | byte alpha; 13 | 14 | public void SetCharAlpha(int charIndex, byte alpha) { 15 | this.charIndex = charIndex; 16 | this.alpha = alpha; 17 | graphic.SetVerticesDirty(); 18 | } 19 | 20 | public override void ModifyMesh(VertexHelper toFill) 21 | { 22 | if (!IsActive()) 23 | return; 24 | 25 | if( charIndex == -1 ) 26 | return; 27 | 28 | int vertCount = toFill.currentVertCount; 29 | 30 | for( int i = 0; i < vertCount; i++ ) 31 | { 32 | if( tmpVertices.Count < (i+1) ) 33 | { 34 | tmpVertices.Add( new UIVertex() ); 35 | } 36 | UIVertex vert = tmpVertices[i]; 37 | toFill.PopulateUIVertex( ref vert, i ); 38 | tmpVertices[i] = vert; 39 | } 40 | 41 | toFill.Clear(); 42 | 43 | for( int i = 0; i < vertCount; i++ ) 44 | { 45 | int tempVertsIndex = i & 3; 46 | tmpVerticesQuad[tempVertsIndex] = tmpVertices[i]; 47 | 48 | 49 | int letterIndex = i / 4; 50 | 51 | if( charIndex == letterIndex ) 52 | { 53 | var color = tmpVerticesQuad[tempVertsIndex].color; 54 | color.a = alpha; 55 | tmpVerticesQuad[tempVertsIndex].color = color; 56 | } 57 | 58 | 59 | if( tempVertsIndex == 3 ) 60 | { 61 | toFill.AddUIVertexQuad( tmpVerticesQuad ); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Assets/TextFader/TextFader.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityEngine.UI; 4 | 5 | [RequireComponent(typeof(Text))] 6 | public class TextFader : MonoBehaviour { 7 | 8 | public bool IgnoreWhiteSpaces = true; 9 | public bool StartOnEnable = true; 10 | public float CharFadeDuration = 0.1f; 11 | 12 | CharLimiter CharLimiter; 13 | CharFader CharFader; 14 | Text text; 15 | 16 | int currentLetterIndex; 17 | float currentCharFadeTime; 18 | 19 | void OnEnable() { 20 | 21 | if( CharLimiter == null ) 22 | CharLimiter = gameObject.AddComponent(); 23 | 24 | if( CharFader == null ) 25 | CharFader = gameObject.AddComponent(); 26 | 27 | CharLimiter.enabled = true; 28 | CharFader.enabled = true; 29 | 30 | text = GetComponent(); 31 | 32 | if( StartOnEnable ) 33 | { 34 | PerformAnimation(); 35 | } 36 | } 37 | 38 | void OnDisable() { 39 | CharLimiter.enabled = false; 40 | CharFader.enabled = false; 41 | } 42 | 43 | public void PerformAnimation() { 44 | currentLetterIndex = 0; 45 | currentCharFadeTime = 0.0f; 46 | } 47 | 48 | void Update() { 49 | 50 | if( IgnoreWhiteSpaces ) 51 | { 52 | var str = text.text; 53 | 54 | if( currentLetterIndex >= str.Length ) 55 | return; 56 | 57 | var currentChar = str[currentLetterIndex]; 58 | if( currentChar == ' ' ) 59 | { 60 | currentLetterIndex++; 61 | Update(); 62 | return; 63 | } 64 | } 65 | 66 | CharLimiter.NumberOfLetters = currentLetterIndex + 1; 67 | 68 | currentCharFadeTime += Time.deltaTime; 69 | float progress = currentCharFadeTime / CharFadeDuration; 70 | 71 | if( progress >= 1.0f ) 72 | { 73 | CharFader.SetCharAlpha( currentLetterIndex, 255 ); 74 | 75 | currentLetterIndex++; 76 | currentCharFadeTime = 0.0f; 77 | 78 | if( currentLetterIndex >= text.text.Length ) 79 | { 80 | enabled = false; 81 | } 82 | } 83 | else 84 | { 85 | byte alpha = (byte)(progress * 255); 86 | CharFader.SetCharAlpha( currentLetterIndex, alpha ); 87 | 88 | } 89 | } 90 | } 91 | --------------------------------------------------------------------------------