Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- #region SolidText class
- public class SolidText : StateMachine
- {
- #region Debug
- private void Start ()
- {
- SolidType.CacheFontResources( 10 );
- }
- private void Update ()
- {
- if ( Input.GetKeyDown( KeyCode.U ) )
- SetText( SolidType.Fonts.Test , "awesomer whoop\nverify please\nmoar test\nthen some" , 3 , 1 , 1 , 1.25f , Vector3.zero , SolidType.Alignment.Center , SolidType.BaseLine.Center );
- else if ( Input.GetKeyDown( KeyCode.I ) )
- SetText( SolidType.Fonts.Test , "wonderful stuff\nverify please\nmoar test\nthen some" , 3 , 1 , 1 , 1.25f , Vector3.zero , SolidType.Alignment.Center , SolidType.BaseLine.Center );
- else if ( Input.GetKeyDown( KeyCode.O ) )
- SetText( SolidType.Fonts.Test , "amazing dude\nsuch satisfy\nmoar test\nthen some" , 3 , 1 , 1 , 1.25f , Vector3.zero , SolidType.Alignment.Left , SolidType.BaseLine.Top );
- else if ( Input.GetKeyDown( KeyCode.P ) )
- SetText( SolidType.Fonts.Test , "dude incredible\nworks here\nmoar test\nthen some" , 3 , 1 , 1 , 1.25f , Vector3.zero , SolidType.Alignment.Right , SolidType.BaseLine.Bottom );
- else if ( Input.GetKeyDown( KeyCode.N ) )
- SolidAnimation.VerticalScaleDown( this );
- else if ( Input.GetKeyDown( KeyCode.B ) )
- SolidAnimation.VerticalScaleUp( this );
- else if ( Input.GetKeyDown( KeyCode.M ) )
- SolidUtils.CharacterYScaleZero( SolidUtils.GetCharacters( this ) );
- }
- #endregion Debug
- #region Initialize
- public void Initialize ()
- {
- //
- }
- #endregion Initialize
- #region Set text
- public void SetText ( SolidType.Fonts font , string text , Vector3 scale , float characterSpacing , float wordSpacing , float lineSpacing , Vector3 position , SolidType.Alignment alignment = SolidType.Alignment.Center , SolidType.BaseLine baseLine = SolidType.BaseLine.Bottom )
- {
- if ( text == _text )
- return;
- ClearText();
- string[] textLines = text.Split(new string[] { "\r\n", "\n" } , System.StringSplitOptions.None );
- string containerName = string.Empty;
- for ( int i = 0 ; textLines.Length > i ; i++ )
- containerName += textLines[ i ] + " ";
- MakeContainer( position , containerName );
- _characterSpacing = characterSpacing;
- _wordSpacing = wordSpacing;
- _lineSpacing = lineSpacing;
- _alignment = alignment;
- _baseLine = baseLine;
- _scale = scale;
- _font = font;
- Set( text , textLines , position );
- switch ( baseLine )
- {
- case SolidType.BaseLine.Center:
- container.position += Vector3.up * scale.y * 0.5f;
- break;
- case SolidType.BaseLine.Bottom:
- container.position += Vector3.up * scale.y;
- break;
- }
- }
- private void ClearText ()
- {
- for ( int i = 0 ; _lines.Count > i ; i++ )
- {
- for ( int j = 0 ; _lines[ i ].words.Count > j ; j++ )
- {
- for ( int k = 0 ; _lines[ i ].words[ j ].characters.Count > k ; k++ )
- SolidType.DespawnCharacter( _lines[ i ].words[ j ].characters[ k ] );
- _lines[ i ].words[ j ].characters.Clear();
- }
- _lines[ i ].words.Clear();
- }
- _lines.Clear();
- }
- public void SetText ( SolidType.Fonts font , string text , float scale , float characterSpacing , float wordSpacing , float lineSpacing , Vector3 position , SolidType.Alignment alignment = SolidType.Alignment.Center , SolidType.BaseLine baseLine = SolidType.BaseLine.Bottom )
- {
- SetText( font , text , Vector3.one * scale , characterSpacing , wordSpacing , lineSpacing , position , alignment , baseLine );
- }
- #endregion Set text
- #region Set
- private void Set ( string text , string[] textLines , Vector3 position )
- {
- for ( int i = 0 ; textLines.Length > i ; i++ )
- {
- lines.Add( new SolidLine( textLines[ i ] , position , this ) );
- position += Vector3.down * lineSpacing * scale.y;
- }
- _text = text;
- }
- #endregion Set
- #region Container
- private void MakeContainer ( Vector3 position , string name )
- {
- if ( _container != null )
- Destroy( _container );
- _container = new GameObject( name );
- container.parent = transform;
- container.position = position;
- }
- #endregion Container
- #region Variables
- #region Getters
- public SolidType.Alignment alignment
- {
- get
- {
- return _alignment;
- }
- }
- public SolidType.BaseLine baseLine
- {
- get
- {
- return _baseLine;
- }
- }
- public List<SolidLine> lines
- {
- get
- {
- return _lines;
- }
- }
- public Vector3 position
- {
- get
- {
- return transform.position;
- }
- }
- public Vector3 scale
- {
- get
- {
- return _scale;
- }
- }
- public Quaternion rotation
- {
- get
- {
- return container.localRotation;
- }
- }
- public float characterSpacing
- {
- get
- {
- return _characterSpacing;
- }
- }
- public float wordSpacing
- {
- get
- {
- return _wordSpacing;
- }
- }
- public float lineSpacing
- {
- get
- {
- return _lineSpacing;
- }
- }
- public Transform container
- {
- get
- {
- return _container.transform;
- }
- }
- public SolidType.Fonts font
- {
- get
- {
- return _font;
- }
- }
- #endregion Getters
- #region Private
- private GameObject _container;
- private SolidType.Alignment _alignment;
- private SolidType.BaseLine _baseLine;
- private SolidType.Fonts _font;
- private float _characterSpacing;
- private float _wordSpacing;
- private float _lineSpacing;
- private List< SolidLine > _lines = new List<SolidLine>();
- private string _text;
- private Vector3 _scale;
- #endregion Private
- #endregion Variables
- }
- #endregion SolidText class
- #region SolidLine class
- public class SolidLine
- {
- #region Set text
- public void Set ( string text , Vector3 position )
- {
- MakeContainer( position , text );
- char[] chars = text.ToCharArray();
- int count = 0;
- while ( chars.Length - 1 > count )
- {
- char c = chars[ count ];
- List< char > word = new List<char>();
- while ( chars.Length > count && !char.IsWhiteSpace( c ) )
- {
- c = chars[ count ];
- if ( !char.IsWhiteSpace( c ) )
- word.Add( c );
- count++;
- }
- words.Add( new SolidWord( new string( word.ToArray() ) , position , this ) );
- }
- Layout();
- _text = text;
- }
- #endregion Set text
- #region Layout
- private void Layout ()
- {
- switch ( alignment )
- {
- case SolidType.Alignment.Center:
- CenterAlignedText();
- break;
- case SolidType.Alignment.Left:
- LeftAlignedText();
- break;
- case SolidType.Alignment.Right:
- RightAlignedText();
- break;
- }
- }
- private void CenterAlignedText ()
- {
- int mid = Mathf.FloorToInt( words.Count * 0.5f );
- if ( words.Count % 2 == 0 )
- {
- for ( int i = 0 ; mid > i ; i++ )
- words[ i ].PositionText( position + ( Vector3.left * scale.x * wordSpacing * 0.5f ) , SolidType.Alignment.Right );
- for ( int i = mid ; words.Count > i ; i++ )
- words[ i ].PositionText( position + ( Vector3.right * scale.x * wordSpacing * 0.5f ) , SolidType.Alignment.Left );
- Vector3 start = words[ 0 ].characters[ 0 ].position;
- Vector3 end = words[ words.Count - 1 ].characters[ words[ words.Count - 1 ].characters.Count - 1 ].position;
- Vector3 center = start + ( Vector3.right * Vector3.Distance( start , end ) * 0.5f );
- Vector3 offset = position - center;
- for ( int i = 0 ; words.Count > i ; i++ )
- for ( int j = 0 ; words[ i ].characters.Count > j ; j++ )
- words[ i ].characters[ j ].position += offset;
- }
- else
- {
- words[ mid ].PositionText( position , SolidType.Alignment.Center );
- for ( int i = 0 ; mid > i ; i++ )
- words[ i ].PositionText( words[ mid ].characters[ 0 ].position + ( Vector3.left * scale.x * wordSpacing ) + ( Vector3.left * ( words[ mid ].characters[ 0 ].bounds.extents.x * words[ mid ].characters[ 0 ].scale.x ) ) , SolidType.Alignment.Right );
- for ( int i = mid + 1 ; words.Count > i ; i++ )
- words[ i ].PositionText( words[ mid ].characters[ words[ mid ].characters.Count - 1 ].position + ( Vector3.right * scale.x * wordSpacing ) + ( Vector3.right * ( words[ mid ].characters[ words[ mid ].characters.Count - 1 ].bounds.extents.x * words[ mid ].characters[ words[ mid ].characters.Count - 1 ].scale.x ) ) , SolidType.Alignment.Left );
- }
- }
- private void LeftAlignedText ()
- {
- Vector3 position = this.position;
- for ( int i = 0 ; words.Count > i ; i++ )
- {
- words[ i ].PositionText( position , alignment );
- SolidCharacter lastChar = words[ i ].characters[ words[ i ].characters.Count - 1 ];
- position = lastChar.container.position + ( Vector3.right * lastChar.bounds.extents.x * lastChar.scale.x );
- position += Vector3.right * scale.x * wordSpacing;
- }
- }
- private void RightAlignedText ()
- {
- Vector3 position = this.position;
- for ( int i = 0 ; words.Count > i ; i++ )
- {
- words[ words.Count - i - 1 ].PositionText( position , alignment );
- SolidCharacter firstChar = words[ words.Count - i - 1 ].characters[ 0 ];
- position = firstChar.container.position + ( Vector3.left * firstChar.bounds.extents.x * firstChar.scale.x );
- position += Vector3.left * scale.x * wordSpacing;
- }
- }
- #endregion Layout
- #region Container
- private void MakeContainer ( Vector3 position , string name )
- {
- if ( _container != null )
- Object.Destroy( _container );
- _container = new GameObject( name );
- container.position = position;
- container.parent = parent.container;
- }
- #endregion Container
- #region Variables
- #region Getters
- public SolidText root
- {
- get
- {
- return parent;
- }
- }
- public List<SolidWord> words
- {
- get
- {
- return _words;
- }
- }
- public SolidType.Alignment alignment
- {
- get
- {
- return root.alignment;
- }
- }
- public SolidText parent
- {
- get
- {
- return _parent;
- }
- }
- public Vector3 position
- {
- get
- {
- return container.position;
- }
- }
- public Vector3 scale
- {
- get
- {
- return root.scale;
- }
- }
- public float wordSpacing
- {
- get
- {
- return root.wordSpacing;
- }
- }
- public float lineSpacing
- {
- get
- {
- return root.lineSpacing;
- }
- }
- public float characterSpacing
- {
- get
- {
- return root.characterSpacing;
- }
- }
- public SolidType.BaseLine baseLine
- {
- get
- {
- return root.baseLine;
- }
- }
- public Transform container
- {
- get
- {
- return _container.transform;
- }
- }
- #endregion Getters
- #region Private
- private List< SolidWord > _words = new List< SolidWord >();
- private GameObject _container;
- private SolidText _parent;
- private string _text;
- #endregion Private
- #endregion Variables
- #region Constructor
- public SolidLine ( string text , Vector3 position , SolidText parent )
- {
- _parent = parent;
- Set( text , position );
- }
- #endregion Constructor
- }
- #endregion SolidLine class
- #region SolidWord class
- public class SolidWord
- {
- #region Set text
- private void Set ( string text , bool generate = true )
- {
- if ( _text == text )
- return;
- if ( generate )
- GenerateText( text , parent.baseLine );
- _text = text;
- }
- #endregion Set text
- #region Generate text
- private void GenerateText ( string text , SolidType.BaseLine baseLine )
- {
- if ( text == null || text.Length == 0 )
- return;
- char[] chars = text.ToCharArray();
- for ( int i = 0 ; chars.Length > i ; i++ )
- _characters.Add( SolidType.SpawnCharacter( root.font , chars[ i ] , parent.scale , i , this ) );
- }
- #endregion Generate text
- #region Position text
- public void PositionText ( Vector3 position , SolidType.Alignment alignment )
- {
- switch ( alignment )
- {
- case SolidType.Alignment.Center:
- int mid = Mathf.FloorToInt( characters.Count * 0.5f );
- if ( characters.Count % 2 == 0 )
- {
- characters[ mid - 1 ].position = position + ( Vector3.left * characters[ mid - 1 ].bounds.extents.x * characters[ mid - 1 ].scale.x ) + ( Vector3.left * parent.characterSpacing * 0.5f );
- characters[ mid ].position = position + ( Vector3.right * characters[ mid ].bounds.extents.x * characters[ mid ].scale.x ) + ( Vector3.right * parent.characterSpacing * 0.5f );
- for ( int i = 1 ; mid > i ; i++ )
- characters[ mid - i - 1 ].position = characters[ mid - i - 1 ].next.position + ( Vector3.left * parent.characterSpacing ) + ( Vector3.left * characters[ mid - i - 1 ].next.bounds.extents.x * characters[ mid - i - 1 ].next.scale.x ) + ( Vector3.left * characters[ mid - i - 1 ].bounds.extents.x * characters[ mid - i - 1 ].scale.x );
- for ( int i = mid + 1 ; characters.Count > i ; i++ )
- characters[ i ].position = characters[ i ].previous.position + ( Vector3.right * parent.characterSpacing ) + ( Vector3.right * characters[ i ].previous.bounds.extents.x * characters[ i ].previous.scale.x ) + ( Vector3.right * characters[ i ].bounds.extents.x * characters[ i ].scale.x );
- }
- else
- {
- characters[ mid ].position = position;
- for ( int i = 0 ; mid > i ; i++ )
- characters[ mid - i - 1 ].position = characters[ mid - i - 1 ].next.position + ( Vector3.left * parent.characterSpacing ) + ( Vector3.left * characters[ mid - i - 1 ].next.bounds.extents.x * characters[ mid - i - 1 ].next.scale.x ) + ( Vector3.left * characters[ mid - i - 1 ].bounds.extents.x * characters[ mid - i - 1 ].scale.x );
- for ( int i = mid + 1 ; characters.Count > i ; i++ )
- characters[ i ].position = characters[ i ].previous.position + ( Vector3.right * parent.characterSpacing ) + ( Vector3.right * characters[ i ].previous.bounds.extents.x * characters[ i ].previous.scale.x ) + ( Vector3.right * characters[ i ].bounds.extents.x * characters[ i ].scale.x );
- }
- break;
- case SolidType.Alignment.Left:
- characters[ 0 ].position = position + ( Vector3.right * characters[ 0 ].bounds.extents.x * characters[ 0 ].scale.x );
- for ( int i = 1 ; characters.Count > i ; i++ )
- characters[ i ].position = characters[ i ].previous.position + ( Vector3.right * parent.characterSpacing ) + ( Vector3.right * characters[ i ].previous.bounds.extents.x * characters[ i ].previous.scale.x ) + ( Vector3.right * characters[ i ].bounds.extents.x * characters[ i ].scale.x );
- break;
- case SolidType.Alignment.Right:
- characters[ characters.Count - 1 ].position = position + ( Vector3.left * characters[ characters.Count - 1 ].bounds.extents.x * characters[ characters.Count - 1 ].scale.x );
- for ( int i = 2 ; characters.Count >= i ; i++ )
- characters[ characters.Count - i ].position = characters[ characters.Count - i ].next.position + ( Vector3.left * parent.characterSpacing ) + ( Vector3.left * characters[ characters.Count - i ].next.bounds.extents.x * characters[ characters.Count - i ].next.scale.x ) + ( Vector3.left * characters[ characters.Count - i ].bounds.extents.x * characters[ characters.Count - i ].scale.x );
- break;
- }
- }
- #endregion Position text
- #region Container
- private void MakeContainer ( Vector3 position , string name )
- {
- if ( _container != null )
- Object.Destroy( _container );
- _container = new GameObject( name );
- container.parent = _parent.container;
- container.position = new Vector3( position.x , _parent.container.position.y , position.z );
- }
- #endregion Container
- #region Variables
- #region Getters
- public SolidText root
- {
- get
- {
- return parent.root;
- }
- }
- public SolidType.BaseLine baseLine
- {
- get
- {
- return root.baseLine;
- }
- }
- public Transform container
- {
- get
- {
- return _container.transform;
- }
- }
- public List<SolidCharacter> characters
- {
- get
- {
- return _characters;
- }
- }
- public float lineSpacing
- {
- get
- {
- return root.lineSpacing;
- }
- }
- public SolidLine parent
- {
- get
- {
- return _parent;
- }
- }
- #endregion Getters
- #region Private
- private SolidLine _parent;
- private GameObject _container;
- private List< SolidCharacter > _characters = new List< SolidCharacter >();
- private string _text;
- #endregion Private
- #endregion Variables
- #region Constructor
- public SolidWord ( string text , Vector3 position , SolidLine parent )
- {
- _parent = parent;
- MakeContainer( position , text );
- Set( text );
- }
- #endregion Constructor
- }
- #endregion SolidWord class
- #region SolidCharacter class
- public class SolidCharacter
- {
- #region Variables
- #region Getter/Setters
- public SolidText root
- {
- get
- {
- return parent.root;
- }
- }
- public Vector3 position
- {
- get
- {
- return container.transform.position;
- }
- set
- {
- container.transform.position = value;
- switch ( root.baseLine )
- {
- case SolidType.BaseLine.Top:
- transform.position = container.transform.position + Vector3.up * bounds.extents.y * scale.y;
- break;
- case SolidType.BaseLine.Bottom:
- transform.position = container.transform.position + Vector3.down * bounds.extents.y * scale.y;
- break;
- }
- }
- }
- public Vector3 scale
- {
- get
- {
- return transform.localScale;
- }
- set
- {
- transform.localScale = value;
- }
- }
- #endregion Getter/Setters
- #region Getters
- public int index
- {
- get
- {
- return _index;
- }
- }
- public Mesh mesh
- {
- get
- {
- return _mesh;
- }
- }
- public SolidWord parent
- {
- get
- {
- return _parent;
- }
- }
- public float lineSpacing
- {
- get
- {
- return root.lineSpacing;
- }
- }
- public Transform container
- {
- get
- {
- return transform.parent;
- }
- }
- public SolidCharacter previous
- {
- get
- {
- return index > 0 ? parent.characters[ index - 1 ] : null;
- }
- }
- public SolidCharacter next
- {
- get
- {
- return parent.characters.Count - 1 > index ? parent.characters[ index + 1 ] : null;
- }
- }
- public Bounds bounds
- {
- get
- {
- mesh.RecalculateBounds();
- return mesh.bounds;
- }
- }
- public float width
- {
- get
- {
- return scale.x;
- }
- }
- public float height
- {
- get
- {
- return scale.y;
- }
- }
- public float depth
- {
- get
- {
- return scale.z;
- }
- }
- public GameObject gameObject
- {
- get
- {
- return _gameObject;
- }
- }
- public Transform transform
- {
- get
- {
- return gameObject.transform;
- }
- }
- #endregion Getters
- #region Private
- public char _character;
- public float _kerning;
- public Mesh _mesh;
- public int _index;
- public Quaternion _rotation;
- public GameObject _gameObject;
- public SolidWord _parent;
- #endregion Private
- #endregion Variables
- #region Constructors
- public SolidCharacter ( char character , GameObject gameObject , Vector3 scale , int index , SolidWord parent )
- {
- _index = index;
- _parent = parent;
- _character = character;
- _gameObject = gameObject;
- _mesh = SolidType.CharacterMesh( _parent.root.font , SolidUtils.CharToCharacter( character ) , gameObject );
- transform.SetSiblingIndex( index );
- transform.localScale = scale;
- }
- #endregion Constructors
- }
- #endregion SolidCharacter class
- #region SolidType class
- public static class SolidType
- {
- #region Spawn character
- public static SolidCharacter SpawnCharacter ( Fonts font , char c , Vector3 scale , int index , SolidWord parent )
- {
- Characters charEnum = SolidUtils.CharToCharacter( c );
- if ( _charactersToPool > _characterPool[ font ][ charEnum ].Count )
- FillCharacterPool( font , charEnum );
- Transform container = new GameObject( c.ToString() ).transform;
- GameObject character = _characterPool[ font ][ charEnum ].Dequeue();
- character.SetActive( true );
- container.transform.parent = parent.container;
- character.transform.parent = container;
- character.transform.position = container.position;
- return new SolidCharacter( c , character , scale , index , parent );
- }
- public static void DespawnCharacter ( SolidCharacter character )
- {
- Characters charEnum = ( Characters ) System.Enum.Parse( typeof( Characters ) , character.gameObject.name );
- _characterPool[ character.root.font ][ charEnum ].Enqueue( character.gameObject );
- character.transform.parent = _characterContainers[ character.root.font ][ charEnum ].transform;
- character.transform.localRotation = Quaternion.identity;
- character.transform.position = Vector3.zero;
- character.transform.localScale = Vector3.one;
- character.gameObject.SetActive( false );
- character = null;
- }
- #endregion Spawn character
- #region Character pool
- public static void CacheFontResources ( int charactersToPool )
- {
- if ( !resourcesCached )
- {
- _charactersToPool = charactersToPool;
- string[] fonts = System.IO.Directory.GetDirectories("Assets/Resources/Prefabs/Fonts/" );
- _poolContainer = new GameObject( "SolidType Pool" );
- for ( int i = 0 ; fonts.Length > i ; i++ )
- {
- Fonts font = ( Fonts ) i;
- string path = fonts[ i ].TrimStart( "Assets/Resources/".ToCharArray() );
- GameObject fontContainer = new GameObject( ( font ).ToString());
- _fontContainers.Add( font , fontContainer );
- fontContainer.transform.parent = _poolContainer.transform;
- GameObject[] prefabs = Resources.LoadAll<GameObject>( path );
- _characterPrefabs.Add( font , prefabs );
- _characterPool.Add( font , new Dictionary<Characters , Queue<GameObject>>() );
- _characterContainers.Add( font , new Dictionary<Characters , GameObject>() );
- _characterMeshes.Add( font , new Dictionary<Characters , Dictionary<GameObject , Mesh>>() );
- for ( int j = 0 ; _characterPrefabs[ font ].Length > j ; j++ )
- {
- Characters character = ( Characters ) System.Enum.Parse( typeof( Characters ) , _characterPrefabs[ font ][ j ].name );
- if ( !_characterContainers[ font ].ContainsKey( character ) )
- {
- GameObject characterContainer = new GameObject( character.ToString() );
- _characterContainers[ font ].Add( character , characterContainer );
- characterContainer.transform.parent = fontContainer.transform;
- _characterPool[ font ].Add( character , new Queue<GameObject>() );
- _characterMeshes[ font ].Add( character , new Dictionary<GameObject , Mesh>() );
- for ( int k = 0 ; _charactersToPool > k ; k++ )
- {
- GameObject newCharacter = Object.Instantiate( _characterPrefabs[ font ][ j ] );
- newCharacter.name = _characterPrefabs[ font ][ j ].name;
- newCharacter.transform.parent = characterContainer.transform;
- _characterPool[ font ][ character ].Enqueue( newCharacter );
- _characterMeshes[ font ][ character ].Add( newCharacter , newCharacter.GetComponent<MeshFilter>().mesh );
- newCharacter.SetActive( false );
- }
- }
- }
- }
- _resourcesCached = true;
- }
- }
- public static void FillCharacterPool ( Fonts font , Characters character )
- {
- GameObject characterContainer = _characterContainers[ font ][ character ];
- for ( int i = 0 ; _charactersToPool > i ; i++ )
- {
- GameObject newCharacter = Object.Instantiate( _characterPrefabs[ font ][ ( int ) character ] );
- newCharacter.name = _characterPrefabs[ font ][ ( int ) character ].name;
- newCharacter.transform.parent = characterContainer.transform;
- _characterPool[ font ][ character ].Enqueue( newCharacter );
- _characterMeshes[ font ][ character ].Add( newCharacter , newCharacter.GetComponent<MeshFilter>().mesh );
- newCharacter.SetActive( false );
- }
- }
- public static Mesh CharacterMesh ( Fonts font , Characters character , GameObject gameObject )
- {
- return _characterMeshes[ font ][ character ][ gameObject ];
- }
- #endregion Character pool
- #region Variables
- #region Enums
- public enum Alignment
- {
- Left = 0,
- Center = 1,
- Right = 2
- }
- public enum BaseLine
- {
- Top = 0,
- Center = 1,
- Bottom = 2
- }
- public enum Fonts
- {
- Test
- }
- public enum Characters
- {
- LOW_A,
- LOW_B,
- LOW_C,
- LOW_D,
- LOW_E,
- LOW_F,
- LOW_G,
- LOW_H,
- LOW_I,
- LOW_J,
- LOW_K,
- LOW_L,
- LOW_M,
- LOW_N,
- LOW_O,
- LOW_P,
- LOW_Q,
- LOW_R,
- LOW_S,
- LOW_T,
- LOW_U,
- LOW_V,
- LOW_W,
- LOW_X,
- LOW_Y,
- LOW_Z,
- NUM_0,
- NUM_1,
- NUM_2,
- NUM_3,
- NUM_4,
- NUM_5,
- NUM_6,
- NUM_7,
- NUM_8,
- NUM_9,
- SYM_ASTERISK,
- SYM_COLON,
- SYM_COMMA,
- SYM_DOUBLEQUOTE,
- SYM_EXCLAMATION,
- SYM_HYPHEN,
- SYM_PERIOD,
- SYM_QUESTION,
- SYM_SEMICOLON,
- SYM_SINGLEQUOTE,
- UPP_A,
- UPP_B,
- UPP_C,
- UPP_D,
- UPP_E,
- UPP_F,
- UPP_G,
- UPP_H,
- UPP_I,
- UPP_J,
- UPP_K,
- UPP_L,
- UPP_M,
- UPP_N,
- UPP_O,
- UPP_P,
- UPP_Q,
- UPP_R,
- UPP_S,
- UPP_T,
- UPP_U,
- UPP_V,
- UPP_W,
- UPP_X,
- UPP_Y,
- UPP_Z
- }
- #endregion Enums
- #region Getters
- public static bool resourcesCached
- {
- get
- {
- return _resourcesCached;
- }
- }
- #endregion Getters
- #region Private
- private static Dictionary< Fonts , Dictionary< Characters , Queue< GameObject > > > _characterPool = new Dictionary< Fonts, Dictionary< Characters , Queue< GameObject > > >();
- private static Dictionary< Fonts , Dictionary< Characters , Dictionary< GameObject , Mesh > > > _characterMeshes = new Dictionary<Fonts, Dictionary<Characters, Dictionary<GameObject, Mesh>>>();
- private static Dictionary< Fonts , GameObject[] > _characterPrefabs = new Dictionary< Fonts , GameObject[] >();
- private static Dictionary< Fonts , GameObject > _fontContainers = new Dictionary< Fonts , GameObject >();
- private static Dictionary< Fonts , Dictionary< Characters , GameObject > > _characterContainers = new Dictionary< Fonts , Dictionary< Characters , GameObject > >();
- private static GameObject _poolContainer;
- private static bool _resourcesCached;
- private static int _charactersToPool;
- #endregion Private
- #endregion Variables
- }
- #endregion SolidType class
- #region SolidAnimation class
- public static class SolidAnimation
- {
- public static GoTweenFlow VerticalScale_Enter ()
- {
- GoTweenFlow flow = new GoTweenFlow();
- return flow;
- }
- public static void VerticalScaleUp ( SolidText text )
- {
- List< SolidCharacter > characters = SolidUtils.GetCharacters( text );
- GoTweenFlow flow = new GoTweenFlow();
- float time = 0f;
- float increment = 0.05f;
- float duration = 0.2f;
- for ( int i = 0 ; characters.Count > i ; i++ )
- {
- flow.insert( time , new GoTween( characters[ i ].container , duration , new GoTweenConfig().scale( 1 ).setEaseType( GoEaseType.BackOut ) ) );
- time += increment;
- increment *= 0.975f;
- duration *= 1.05f;
- }
- flow.play();
- }
- public static void VerticalScaleDown ( SolidText text )
- {
- List< SolidCharacter > characters = SolidUtils.GetCharacters( text );
- GoTweenFlow flow = new GoTweenFlow();
- float time = 0f;
- float increment = 0.05f;
- float duration = 0.5f;
- for ( int i = 0 ; characters.Count > i ; i++ )
- {
- flow.insert( time , new GoTween( characters[ i ].container , duration , new GoTweenConfig().scale( new Vector3( characters[ i ].container.localScale.x , 0 , characters[ i ].container.localScale.z ) ).setEaseType( GoEaseType.BackIn ) ) );
- time += increment;
- increment *= 0.975f;
- duration *= 0.975f;
- }
- flow.play();
- }
- }
- #endregion SolidAnimation class
- #region SolidHelper class
- public static class SolidUtils
- {
- public static List<SolidCharacter> GetCharacters ( SolidText text )
- {
- List< SolidCharacter > characters = new List<SolidCharacter>();
- for ( int i = 0 ; text.lines.Count > i ; i++ )
- for ( int j = 0 ; text.lines[ i ].words.Count > j ; j++ )
- characters.AddRange( text.lines[ i ].words[ j ].characters );
- return characters;
- }
- public static void CharacterYScaleZero ( List<SolidCharacter> characters )
- {
- for ( int i = 0 ; characters.Count > i ; i++ )
- characters[ i ].container.localScale = new Vector3( characters[ i ].container.localScale.x , 0 , characters[ i ].container.localScale.z );
- }
- public static SolidType.Characters CharToCharacter ( char character )
- {
- if ( char.IsLetterOrDigit( character ) )
- return ( SolidType.Characters ) System.Enum.Parse( typeof( SolidType.Characters ) , ( char.IsLetter( character ) ? ( char.IsUpper( character ) ? "UPP_" : "LOW_" ) : "NUM_" ) + char.ToUpper( character ) );
- else
- {
- switch ( character )
- {
- case '*':
- return SolidType.Characters.SYM_ASTERISK;
- case ':':
- return SolidType.Characters.SYM_COLON;
- case ',':
- return SolidType.Characters.SYM_COMMA;
- case '"':
- return SolidType.Characters.SYM_DOUBLEQUOTE;
- case '!':
- return SolidType.Characters.SYM_EXCLAMATION;
- case '-':
- return SolidType.Characters.SYM_HYPHEN;
- case '.':
- return SolidType.Characters.SYM_PERIOD;
- case '?':
- return SolidType.Characters.SYM_QUESTION;
- case ';':
- return SolidType.Characters.SYM_SEMICOLON;
- case '\'':
- return SolidType.Characters.SYM_SINGLEQUOTE;
- default:
- return SolidType.Characters.SYM_QUESTION;
- }
- }
- }
- }
- #endregion SolidHelper class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement