Created
December 13, 2016 22:12
-
-
Save enue/baaf5bacc503cea494fd6e902569fef3 to your computer and use it in GitHub Desktop.
[Unity]文字が震えるエフェクト
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 UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine.UI; | |
// Unity5.3.4p4 | |
namespace TSKT | |
{ | |
[RequireComponent(typeof(Text))] | |
public class Vibrate : BaseMeshEffect | |
{ | |
const float Interval = 0.067f; | |
float lastModifiedTime = 0f; | |
List<UIVertex> vertices = new List<UIVertex>(); | |
public override void ModifyMesh(VertexHelper vh) | |
{ | |
if (!IsActive()) | |
{ | |
return; | |
} | |
vh.GetUIVertexStream(vertices); | |
ModifyMesh(vertices); | |
vh.Clear(); | |
vh.AddUIVertexTriangleStream(vertices); | |
} | |
void ModifyMesh(List<UIVertex> list) | |
{ | |
for (int i = 0; i < list.Count; i+=6) | |
{ | |
var distance = Random.insideUnitSphere * 4f; | |
for(int j=0; j<6; ++j) | |
{ | |
var vertex = list[i + j]; | |
vertex.position = vertex.position + distance; | |
list[i + j] = vertex; | |
} | |
} | |
} | |
Text text; | |
Text Text | |
{ | |
get | |
{ | |
return text ?? (text = GetComponent<Text>()); | |
} | |
} | |
void Update() | |
{ | |
if (Time.time - lastModifiedTime >= Interval) | |
{ | |
lastModifiedTime = Time.time; | |
Text.SetAllDirty(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment