Created
December 13, 2013 10:59
-
-
Save hww/7942741 to your computer and use it in GitHub Desktop.
Futile class FLabel which may have vertical animation per single character (looks like wave)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
/* | |
* | |
* By: hww | |
* | |
* Use: | |
* | |
* WaveEffect effect = new WaveEffect(); | |
* FLabelWave label = new FLabelWave("fontName", "Text", effect); | |
* AddChild (label); | |
* | |
* // now at the Update function do | |
* label.waveEffectTime = Time.time; | |
* | |
* // also possible to control the 'effect' object to ajust effect | |
* | |
*/ | |
public class FLabelWave : FLabel | |
{ | |
float waveEffectTime_ = 0; | |
WaveEffect waveEffect; // check my other Gist WaveEffect.cs | |
public FLabelWave(string fontName, string text, WaveEffect effect):this(fontName, text, new FTextParams(), effect) | |
{ | |
} | |
public FLabelWave(string fontName, string text, FTextParams textParams, WaveEffect effect):base(fontName, text, textParams) | |
{ | |
waveEffect = effect; | |
} | |
public float waveEffectTime { | |
get { return waveEffectTime_; } | |
set { | |
if (waveEffectTime_!=value) { | |
waveEffectTime_ = value; | |
_isAlphaDirty=true; | |
} | |
} | |
} | |
override public void PopulateRenderLayer() | |
{ | |
if(_isOnStage && _firstFacetIndex != -1) | |
{ | |
_isMeshDirty = false; | |
Vector3[] vertices = _renderLayer.vertices; | |
Vector2[] uvs = _renderLayer.uvs; | |
Color[] colors = _renderLayer.colors; | |
int vertexIndex0 = _firstFacetIndex*4; | |
int vertexIndex1 = vertexIndex0 + 1; | |
int vertexIndex2 = vertexIndex0 + 2; | |
int vertexIndex3 = vertexIndex0 + 3; | |
int charIdx=0; | |
int lineCount = _letterQuadLines.Length; | |
for(int i = 0; i<lineCount; i++) | |
{ | |
FLetterQuad[] quads = _letterQuadLines[i].quads; | |
int quadCount = quads.Length; | |
for(int q = 0; q<quadCount; q++) | |
{ | |
FLetterQuad quad = quads[q]; | |
FCharInfo charInfo = quad.charInfo; | |
Vector2 offset = new Vector2(0, waveEffect.Update(waveEffectTime_, q)); | |
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex0], quad.topLeft + offset,0); | |
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex1], quad.topRight + offset,0); | |
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex2], quad.bottomRight + offset,0); | |
_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex3], quad.bottomLeft + offset,0); | |
uvs[vertexIndex0] = charInfo.uvTopLeft; | |
uvs[vertexIndex1] = charInfo.uvTopRight; | |
uvs[vertexIndex2] = charInfo.uvBottomRight; | |
uvs[vertexIndex3] = charInfo.uvBottomLeft; | |
colors[vertexIndex0] = _alphaColor; | |
colors[vertexIndex1] = _alphaColor; | |
colors[vertexIndex2] = _alphaColor; | |
colors[vertexIndex3] = _alphaColor; | |
vertexIndex0 += 4; | |
vertexIndex1 += 4; | |
vertexIndex2 += 4; | |
vertexIndex3 += 4; | |
charIdx++; | |
} | |
} | |
_renderLayer.HandleVertsChange(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment