Skip to content

Instantly share code, notes, and snippets.

@PiMaker
Last active February 21, 2022 17:58
Show Gist options
  • Save PiMaker/3decf2ac27955b76ffbc56b4f467229a to your computer and use it in GitHub Desktop.
Save PiMaker/3decf2ac27955b76ffbc56b4f467229a to your computer and use it in GitHub Desktop.
// Available under the terms of the CC0 license
// No copyright intended, this file is in the public domain
// Originally written by: _pi_
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
using System.Collections.Generic;
namespace Pi
{
public class SpeechAnimatorHelper : MonoBehaviour
{
public GameObject Target;
public AnimatorController FX;
public AvatarMask Mask;
public AnimationClip IdleAnim;
public string PointerName, DataName, ResetName, SBName;
public void CreateAnims() {
Debug.Log("Creating SpeechBubble animations");
var newAnimList = new List<AnimationClip>();
for (int i = 0; i < 256; i++) {
var clip = new AnimationClip();
var curve = new AnimationCurve(new[] {
new Keyframe(0.0f, 0),
new Keyframe(255.0f, 1)
});
AnimationUtility.SetKeyLeftTangentMode(curve, 0, AnimationUtility.TangentMode.Linear);
AnimationUtility.SetKeyLeftTangentMode(curve, 1, AnimationUtility.TangentMode.Linear);
AnimationUtility.SetKeyRightTangentMode(curve, 0, AnimationUtility.TangentMode.Linear);
AnimationUtility.SetKeyRightTangentMode(curve, 1, AnimationUtility.TangentMode.Linear);
clip.SetCurve(Target.name, typeof(MeshRenderer), $"material._Data{i}", curve);
newAnimList.Add(clip);
AssetDatabase.CreateAsset(clip, $"Assets\\SpeechBubble\\Anims\\data{i}.anim");
}
var resetClip = new AnimationClip();
resetClip.frameRate = 90;
for (int i = 0; i < 256; i++) {
var curve = new AnimationCurve(new[] {
new Keyframe(0.0f, 0),
new Keyframe(1.0f, 0)
});
resetClip.SetCurve(Target.name, typeof(MeshRenderer), $"material._Data{i}", curve);
}
AssetDatabase.CreateAsset(resetClip, $"Assets\\SpeechBubble\\Anims\\RESET.anim");
if (FX != null) {
var layername = $"SpeechBubble_Data";
for (int i = 0; i < FX.layers.Length; i++) {
var tlayer = FX.layers[i];
if (tlayer.name.StartsWith(layername)) {
FX.RemoveLayer(i);
i--;
}
}
for (int i = 0; i < FX.parameters.Length; i++) {
var tparm = FX.parameters[i];
if (tparm.name.StartsWith(layername)) {
FX.RemoveParameter(i);
i--;
}
}
{
var layer = new AnimatorControllerLayer() {
defaultWeight = 1.0f,
name = $"{layername}"
};
layer.stateMachine = new AnimatorStateMachine();
layer.stateMachine.hideFlags = HideFlags.HideInHierarchy;
layer.stateMachine.name = layer.name;
var offState = new AnimatorState() {
motion = (Motion) IdleAnim,
name = "Idle",
writeDefaultValues = false
};
layer.stateMachine.defaultState = offState;
layer.avatarMask = Mask;
AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(FX));
AssetDatabase.AddObjectToAsset(offState, AssetDatabase.GetAssetPath(layer.stateMachine));
for (int i = 0; i < 256; i++) {
var parm = new AnimatorControllerParameter() {
name = $"{layername}{i}",
type = AnimatorControllerParameterType.Float,
defaultBool = false
};
FX.AddParameter(parm);
var onState = new AnimatorState() {
motion = (Motion) newAnimList[i],
name = "Updating " + i,
writeDefaultValues = false,
timeParameter = DataName,
timeParameterActive = true
};
var transOn = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = onState,
duration = 0,
hasFixedDuration = true,
name = "turn_on_" + i,
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.Equals,
parameter = PointerName,
threshold = i,
}
}
};
var transOff = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = offState,
duration = 0,
hasFixedDuration = true,
name = "turn_off_" + i,
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.NotEqual,
parameter = PointerName,
threshold = i,
}
}
};
onState.AddTransition(transOff);
offState.AddTransition(transOn);
layer.stateMachine.AddState(onState, new Vector3(240, 200 + 100 * i));
AssetDatabase.AddObjectToAsset(onState, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transOn, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transOff, AssetDatabase.GetAssetPath(layer.stateMachine));
}
layer.stateMachine.AddState(offState, new Vector3(0, 200));
var disState = new AnimatorState() {
motion = (Motion) IdleAnim,
name = "Disabled",
writeDefaultValues = false
};
var transEn = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = offState,
duration = 0.01f,
hasFixedDuration = true,
name = "enable",
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.If,
parameter = SBName,
threshold = 1.0f
}
}
};
var transDis = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = disState,
duration = 0.01f,
hasFixedDuration = true,
name = "disable",
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.IfNot,
parameter = SBName
}
}
};
offState.AddTransition(transDis);
disState.AddTransition(transEn);
layer.stateMachine.AddState(disState, new Vector3(-240, 200));
AssetDatabase.AddObjectToAsset(disState, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transDis, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transEn, AssetDatabase.GetAssetPath(layer.stateMachine));
FX.AddLayer(layer);
}
// RESET ANIM
{
var layer = new AnimatorControllerLayer() {
defaultWeight = 1.0f,
name = $"{layername}_RESET"
};
var offState = new AnimatorState() {
motion = (Motion) IdleAnim,
name = "Idle",
writeDefaultValues = false
};
var onState = new AnimatorState() {
motion = (Motion) resetClip,
name = "Reset",
writeDefaultValues = false
};
var transOn = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = onState,
duration = 0.01f,
hasFixedDuration = true,
name = "turn_on",
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.If,
parameter = ResetName,
threshold = 1.0f
}
}
};
var transOff = new AnimatorStateTransition() {
hasExitTime = false,
canTransitionToSelf = false,
destinationState = offState,
duration = 0.01f,
hasFixedDuration = true,
name = "turn_off",
conditions = new[] {
new AnimatorCondition() {
mode = AnimatorConditionMode.IfNot,
parameter = ResetName
}
}
};
onState.AddTransition(transOff);
offState.AddTransition(transOn);
layer.stateMachine = new AnimatorStateMachine();
layer.stateMachine.hideFlags = HideFlags.HideInHierarchy;
layer.stateMachine.name = layer.name;
layer.stateMachine.AddState(onState, new Vector3(240, 60));
layer.stateMachine.AddState(offState, new Vector3(240, 140));
layer.stateMachine.defaultState = onState;
layer.avatarMask = Mask;
AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(FX));
AssetDatabase.AddObjectToAsset(onState, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(offState, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transOn, AssetDatabase.GetAssetPath(layer.stateMachine));
AssetDatabase.AddObjectToAsset(transOff, AssetDatabase.GetAssetPath(layer.stateMachine));
FX.AddLayer(layer);
}
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
//FixYourAnimators.FixAllAnimators();
Debug.Log("SpeechBubble animations created!");
}
}
[CustomEditor(typeof(SpeechAnimatorHelper))]
public class SpeechAnimatorHelperEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUILayout.Button("Create Animations"))
{
((SpeechAnimatorHelper)target).CreateAnims();
}
}
}
}
#endif
Shader "_pi_/SpeechDisplayShader"
{
Properties
{
// Available under the terms of the CC0 license
// No copyright intended, this file is in the public domain
// Originally written by: _pi_
_MainTex ("Speech Bubble Texture", 2D) = "black"
// _CRT ("Data CRT", 2D) = "black"
_TextRegion ("Text Region", Vector) = (0, 0, 1, 1)
_Font ("Font Atlas", 2D) = "white" {}
_Atlas_Width ("Atlas width (chars)", Int) = 64
_Atlas_Height ("Atlas height (chars)", Int) = 8
_CharBorder ("Character Border", Range(0, 1)) = 0.1
_Data0 ("Data 0", Float) = 0
_Data1 ("Data 1", Float) = 0
_Data2 ("Data 2", Float) = 0
_Data3 ("Data 3", Float) = 0
_Data4 ("Data 4", Float) = 0
_Data5 ("Data 5", Float) = 0
_Data6 ("Data 6", Float) = 0
_Data7 ("Data 7", Float) = 0
_Data8 ("Data 8", Float) = 0
_Data9 ("Data 9", Float) = 0
_Data10 ("Data 10", Float) = 0
_Data11 ("Data 11", Float) = 0
_Data12 ("Data 12", Float) = 0
_Data13 ("Data 13", Float) = 0
_Data14 ("Data 14", Float) = 0
_Data15 ("Data 15", Float) = 0
_Data16 ("Data 16", Float) = 0
_Data17 ("Data 17", Float) = 0
_Data18 ("Data 18", Float) = 0
_Data19 ("Data 19", Float) = 0
_Data20 ("Data 20", Float) = 0
_Data21 ("Data 21", Float) = 0
_Data22 ("Data 22", Float) = 0
_Data23 ("Data 23", Float) = 0
_Data24 ("Data 24", Float) = 0
_Data25 ("Data 25", Float) = 0
_Data26 ("Data 26", Float) = 0
_Data27 ("Data 27", Float) = 0
_Data28 ("Data 28", Float) = 0
_Data29 ("Data 29", Float) = 0
_Data30 ("Data 30", Float) = 0
_Data31 ("Data 31", Float) = 0
_Data32 ("Data 32", Float) = 0
_Data33 ("Data 33", Float) = 0
_Data34 ("Data 34", Float) = 0
_Data35 ("Data 35", Float) = 0
_Data36 ("Data 36", Float) = 0
_Data37 ("Data 37", Float) = 0
_Data38 ("Data 38", Float) = 0
_Data39 ("Data 39", Float) = 0
_Data40 ("Data 40", Float) = 0
_Data41 ("Data 41", Float) = 0
_Data42 ("Data 42", Float) = 0
_Data43 ("Data 43", Float) = 0
_Data44 ("Data 44", Float) = 0
_Data45 ("Data 45", Float) = 0
_Data46 ("Data 46", Float) = 0
_Data47 ("Data 47", Float) = 0
_Data48 ("Data 48", Float) = 0
_Data49 ("Data 49", Float) = 0
_Data50 ("Data 50", Float) = 0
_Data51 ("Data 51", Float) = 0
_Data52 ("Data 52", Float) = 0
_Data53 ("Data 53", Float) = 0
_Data54 ("Data 54", Float) = 0
_Data55 ("Data 55", Float) = 0
_Data56 ("Data 56", Float) = 0
_Data57 ("Data 57", Float) = 0
_Data58 ("Data 58", Float) = 0
_Data59 ("Data 59", Float) = 0
_Data60 ("Data 60", Float) = 0
_Data61 ("Data 61", Float) = 0
_Data62 ("Data 62", Float) = 0
_Data63 ("Data 63", Float) = 0
_Data64 ("Data 64", Float) = 0
_Data65 ("Data 65", Float) = 0
_Data66 ("Data 66", Float) = 0
_Data67 ("Data 67", Float) = 0
_Data68 ("Data 68", Float) = 0
_Data69 ("Data 69", Float) = 0
_Data70 ("Data 70", Float) = 0
_Data71 ("Data 71", Float) = 0
_Data72 ("Data 72", Float) = 0
_Data73 ("Data 73", Float) = 0
_Data74 ("Data 74", Float) = 0
_Data75 ("Data 75", Float) = 0
_Data76 ("Data 76", Float) = 0
_Data77 ("Data 77", Float) = 0
_Data78 ("Data 78", Float) = 0
_Data79 ("Data 79", Float) = 0
_Data80 ("Data 80", Float) = 0
_Data81 ("Data 81", Float) = 0
_Data82 ("Data 82", Float) = 0
_Data83 ("Data 83", Float) = 0
_Data84 ("Data 84", Float) = 0
_Data85 ("Data 85", Float) = 0
_Data86 ("Data 86", Float) = 0
_Data87 ("Data 87", Float) = 0
_Data88 ("Data 88", Float) = 0
_Data89 ("Data 89", Float) = 0
_Data90 ("Data 90", Float) = 0
_Data91 ("Data 91", Float) = 0
_Data92 ("Data 92", Float) = 0
_Data93 ("Data 93", Float) = 0
_Data94 ("Data 94", Float) = 0
_Data95 ("Data 95", Float) = 0
_Data96 ("Data 96", Float) = 0
_Data97 ("Data 97", Float) = 0
_Data98 ("Data 98", Float) = 0
_Data99 ("Data 99", Float) = 0
_Data100 ("Data 100", Float) = 0
_Data101 ("Data 101", Float) = 0
_Data102 ("Data 102", Float) = 0
_Data103 ("Data 103", Float) = 0
_Data104 ("Data 104", Float) = 0
_Data105 ("Data 105", Float) = 0
_Data106 ("Data 106", Float) = 0
_Data107 ("Data 107", Float) = 0
_Data108 ("Data 108", Float) = 0
_Data109 ("Data 109", Float) = 0
_Data110 ("Data 110", Float) = 0
_Data111 ("Data 111", Float) = 0
_Data112 ("Data 112", Float) = 0
_Data113 ("Data 113", Float) = 0
_Data114 ("Data 114", Float) = 0
_Data115 ("Data 115", Float) = 0
_Data116 ("Data 116", Float) = 0
_Data117 ("Data 117", Float) = 0
_Data118 ("Data 118", Float) = 0
_Data119 ("Data 119", Float) = 0
_Data120 ("Data 120", Float) = 0
_Data121 ("Data 121", Float) = 0
_Data122 ("Data 122", Float) = 0
_Data123 ("Data 123", Float) = 0
_Data124 ("Data 124", Float) = 0
_Data125 ("Data 125", Float) = 0
_Data126 ("Data 126", Float) = 0
_Data127 ("Data 127", Float) = 0
_Data128 ("Data 128", Float) = 0
_Data129 ("Data 129", Float) = 0
_Data130 ("Data 130", Float) = 0
_Data131 ("Data 131", Float) = 0
_Data132 ("Data 132", Float) = 0
_Data133 ("Data 133", Float) = 0
_Data134 ("Data 134", Float) = 0
_Data135 ("Data 135", Float) = 0
_Data136 ("Data 136", Float) = 0
_Data137 ("Data 137", Float) = 0
_Data138 ("Data 138", Float) = 0
_Data139 ("Data 139", Float) = 0
_Data140 ("Data 140", Float) = 0
_Data141 ("Data 141", Float) = 0
_Data142 ("Data 142", Float) = 0
_Data143 ("Data 143", Float) = 0
_Data144 ("Data 144", Float) = 0
_Data145 ("Data 145", Float) = 0
_Data146 ("Data 146", Float) = 0
_Data147 ("Data 147", Float) = 0
_Data148 ("Data 148", Float) = 0
_Data149 ("Data 149", Float) = 0
_Data150 ("Data 150", Float) = 0
_Data151 ("Data 151", Float) = 0
_Data152 ("Data 152", Float) = 0
_Data153 ("Data 153", Float) = 0
_Data154 ("Data 154", Float) = 0
_Data155 ("Data 155", Float) = 0
_Data156 ("Data 156", Float) = 0
_Data157 ("Data 157", Float) = 0
_Data158 ("Data 158", Float) = 0
_Data159 ("Data 159", Float) = 0
_Data160 ("Data 160", Float) = 0
_Data161 ("Data 161", Float) = 0
_Data162 ("Data 162", Float) = 0
_Data163 ("Data 163", Float) = 0
_Data164 ("Data 164", Float) = 0
_Data165 ("Data 165", Float) = 0
_Data166 ("Data 166", Float) = 0
_Data167 ("Data 167", Float) = 0
_Data168 ("Data 168", Float) = 0
_Data169 ("Data 169", Float) = 0
_Data170 ("Data 170", Float) = 0
_Data171 ("Data 171", Float) = 0
_Data172 ("Data 172", Float) = 0
_Data173 ("Data 173", Float) = 0
_Data174 ("Data 174", Float) = 0
_Data175 ("Data 175", Float) = 0
_Data176 ("Data 176", Float) = 0
_Data177 ("Data 177", Float) = 0
_Data178 ("Data 178", Float) = 0
_Data179 ("Data 179", Float) = 0
_Data180 ("Data 180", Float) = 0
_Data181 ("Data 181", Float) = 0
_Data182 ("Data 182", Float) = 0
_Data183 ("Data 183", Float) = 0
_Data184 ("Data 184", Float) = 0
_Data185 ("Data 185", Float) = 0
_Data186 ("Data 186", Float) = 0
_Data187 ("Data 187", Float) = 0
_Data188 ("Data 188", Float) = 0
_Data189 ("Data 189", Float) = 0
_Data190 ("Data 190", Float) = 0
_Data191 ("Data 191", Float) = 0
_Data192 ("Data 192", Float) = 0
_Data193 ("Data 193", Float) = 0
_Data194 ("Data 194", Float) = 0
_Data195 ("Data 195", Float) = 0
_Data196 ("Data 196", Float) = 0
_Data197 ("Data 197", Float) = 0
_Data198 ("Data 198", Float) = 0
_Data199 ("Data 199", Float) = 0
_Data200 ("Data 200", Float) = 0
_Data201 ("Data 201", Float) = 0
_Data202 ("Data 202", Float) = 0
_Data203 ("Data 203", Float) = 0
_Data204 ("Data 204", Float) = 0
_Data205 ("Data 205", Float) = 0
_Data206 ("Data 206", Float) = 0
_Data207 ("Data 207", Float) = 0
_Data208 ("Data 208", Float) = 0
_Data209 ("Data 209", Float) = 0
_Data210 ("Data 210", Float) = 0
_Data211 ("Data 211", Float) = 0
_Data212 ("Data 212", Float) = 0
_Data213 ("Data 213", Float) = 0
_Data214 ("Data 214", Float) = 0
_Data215 ("Data 215", Float) = 0
_Data216 ("Data 216", Float) = 0
_Data217 ("Data 217", Float) = 0
_Data218 ("Data 218", Float) = 0
_Data219 ("Data 219", Float) = 0
_Data220 ("Data 220", Float) = 0
_Data221 ("Data 221", Float) = 0
_Data222 ("Data 222", Float) = 0
_Data223 ("Data 223", Float) = 0
_Data224 ("Data 224", Float) = 0
_Data225 ("Data 225", Float) = 0
_Data226 ("Data 226", Float) = 0
_Data227 ("Data 227", Float) = 0
_Data228 ("Data 228", Float) = 0
_Data229 ("Data 229", Float) = 0
_Data230 ("Data 230", Float) = 0
_Data231 ("Data 231", Float) = 0
_Data232 ("Data 232", Float) = 0
_Data233 ("Data 233", Float) = 0
_Data234 ("Data 234", Float) = 0
_Data235 ("Data 235", Float) = 0
_Data236 ("Data 236", Float) = 0
_Data237 ("Data 237", Float) = 0
_Data238 ("Data 238", Float) = 0
_Data239 ("Data 239", Float) = 0
_Data240 ("Data 240", Float) = 0
_Data241 ("Data 241", Float) = 0
_Data242 ("Data 242", Float) = 0
_Data243 ("Data 243", Float) = 0
_Data244 ("Data 244", Float) = 0
_Data245 ("Data 245", Float) = 0
_Data246 ("Data 246", Float) = 0
_Data247 ("Data 247", Float) = 0
_Data248 ("Data 248", Float) = 0
_Data249 ("Data 249", Float) = 0
_Data250 ("Data 250", Float) = 0
_Data251 ("Data 251", Float) = 0
_Data252 ("Data 252", Float) = 0
_Data253 ("Data 253", Float) = 0
_Data254 ("Data 254", Float) = 0
_Data255 ("Data 255", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent+10" "VRCFallback"="Hidden" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
/* Texture2D<uint4> _CRT; */
float4 _TextRegion;
float _Data0;
float _Data1;
float _Data2;
float _Data3;
float _Data4;
float _Data5;
float _Data6;
float _Data7;
float _Data8;
float _Data9;
float _Data10;
float _Data11;
float _Data12;
float _Data13;
float _Data14;
float _Data15;
float _Data16;
float _Data17;
float _Data18;
float _Data19;
float _Data20;
float _Data21;
float _Data22;
float _Data23;
float _Data24;
float _Data25;
float _Data26;
float _Data27;
float _Data28;
float _Data29;
float _Data30;
float _Data31;
float _Data32;
float _Data33;
float _Data34;
float _Data35;
float _Data36;
float _Data37;
float _Data38;
float _Data39;
float _Data40;
float _Data41;
float _Data42;
float _Data43;
float _Data44;
float _Data45;
float _Data46;
float _Data47;
float _Data48;
float _Data49;
float _Data50;
float _Data51;
float _Data52;
float _Data53;
float _Data54;
float _Data55;
float _Data56;
float _Data57;
float _Data58;
float _Data59;
float _Data60;
float _Data61;
float _Data62;
float _Data63;
float _Data64;
float _Data65;
float _Data66;
float _Data67;
float _Data68;
float _Data69;
float _Data70;
float _Data71;
float _Data72;
float _Data73;
float _Data74;
float _Data75;
float _Data76;
float _Data77;
float _Data78;
float _Data79;
float _Data80;
float _Data81;
float _Data82;
float _Data83;
float _Data84;
float _Data85;
float _Data86;
float _Data87;
float _Data88;
float _Data89;
float _Data90;
float _Data91;
float _Data92;
float _Data93;
float _Data94;
float _Data95;
float _Data96;
float _Data97;
float _Data98;
float _Data99;
float _Data100;
float _Data101;
float _Data102;
float _Data103;
float _Data104;
float _Data105;
float _Data106;
float _Data107;
float _Data108;
float _Data109;
float _Data110;
float _Data111;
float _Data112;
float _Data113;
float _Data114;
float _Data115;
float _Data116;
float _Data117;
float _Data118;
float _Data119;
float _Data120;
float _Data121;
float _Data122;
float _Data123;
float _Data124;
float _Data125;
float _Data126;
float _Data127;
float _Data128;
float _Data129;
float _Data130;
float _Data131;
float _Data132;
float _Data133;
float _Data134;
float _Data135;
float _Data136;
float _Data137;
float _Data138;
float _Data139;
float _Data140;
float _Data141;
float _Data142;
float _Data143;
float _Data144;
float _Data145;
float _Data146;
float _Data147;
float _Data148;
float _Data149;
float _Data150;
float _Data151;
float _Data152;
float _Data153;
float _Data154;
float _Data155;
float _Data156;
float _Data157;
float _Data158;
float _Data159;
float _Data160;
float _Data161;
float _Data162;
float _Data163;
float _Data164;
float _Data165;
float _Data166;
float _Data167;
float _Data168;
float _Data169;
float _Data170;
float _Data171;
float _Data172;
float _Data173;
float _Data174;
float _Data175;
float _Data176;
float _Data177;
float _Data178;
float _Data179;
float _Data180;
float _Data181;
float _Data182;
float _Data183;
float _Data184;
float _Data185;
float _Data186;
float _Data187;
float _Data188;
float _Data189;
float _Data190;
float _Data191;
float _Data192;
float _Data193;
float _Data194;
float _Data195;
float _Data196;
float _Data197;
float _Data198;
float _Data199;
float _Data200;
float _Data201;
float _Data202;
float _Data203;
float _Data204;
float _Data205;
float _Data206;
float _Data207;
float _Data208;
float _Data209;
float _Data210;
float _Data211;
float _Data212;
float _Data213;
float _Data214;
float _Data215;
float _Data216;
float _Data217;
float _Data218;
float _Data219;
float _Data220;
float _Data221;
float _Data222;
float _Data223;
float _Data224;
float _Data225;
float _Data226;
float _Data227;
float _Data228;
float _Data229;
float _Data230;
float _Data231;
float _Data232;
float _Data233;
float _Data234;
float _Data235;
float _Data236;
float _Data237;
float _Data238;
float _Data239;
float _Data240;
float _Data241;
float _Data242;
float _Data243;
float _Data244;
float _Data245;
float _Data246;
float _Data247;
float _Data248;
float _Data249;
float _Data250;
float _Data251;
float _Data252;
float _Data253;
float _Data254;
float _Data255;
float getDataRaw(uint idx) {
[forcecase]
switch (idx) {
case 0: return _Data0;
case 1: return _Data1;
case 2: return _Data2;
case 3: return _Data3;
case 4: return _Data4;
case 5: return _Data5;
case 6: return _Data6;
case 7: return _Data7;
case 8: return _Data8;
case 9: return _Data9;
case 10: return _Data10;
case 11: return _Data11;
case 12: return _Data12;
case 13: return _Data13;
case 14: return _Data14;
case 15: return _Data15;
case 16: return _Data16;
case 17: return _Data17;
case 18: return _Data18;
case 19: return _Data19;
case 20: return _Data20;
case 21: return _Data21;
case 22: return _Data22;
case 23: return _Data23;
case 24: return _Data24;
case 25: return _Data25;
case 26: return _Data26;
case 27: return _Data27;
case 28: return _Data28;
case 29: return _Data29;
case 30: return _Data30;
case 31: return _Data31;
case 32: return _Data32;
case 33: return _Data33;
case 34: return _Data34;
case 35: return _Data35;
case 36: return _Data36;
case 37: return _Data37;
case 38: return _Data38;
case 39: return _Data39;
case 40: return _Data40;
case 41: return _Data41;
case 42: return _Data42;
case 43: return _Data43;
case 44: return _Data44;
case 45: return _Data45;
case 46: return _Data46;
case 47: return _Data47;
case 48: return _Data48;
case 49: return _Data49;
case 50: return _Data50;
case 51: return _Data51;
case 52: return _Data52;
case 53: return _Data53;
case 54: return _Data54;
case 55: return _Data55;
case 56: return _Data56;
case 57: return _Data57;
case 58: return _Data58;
case 59: return _Data59;
case 60: return _Data60;
case 61: return _Data61;
case 62: return _Data62;
case 63: return _Data63;
case 64: return _Data64;
case 65: return _Data65;
case 66: return _Data66;
case 67: return _Data67;
case 68: return _Data68;
case 69: return _Data69;
case 70: return _Data70;
case 71: return _Data71;
case 72: return _Data72;
case 73: return _Data73;
case 74: return _Data74;
case 75: return _Data75;
case 76: return _Data76;
case 77: return _Data77;
case 78: return _Data78;
case 79: return _Data79;
case 80: return _Data80;
case 81: return _Data81;
case 82: return _Data82;
case 83: return _Data83;
case 84: return _Data84;
case 85: return _Data85;
case 86: return _Data86;
case 87: return _Data87;
case 88: return _Data88;
case 89: return _Data89;
case 90: return _Data90;
case 91: return _Data91;
case 92: return _Data92;
case 93: return _Data93;
case 94: return _Data94;
case 95: return _Data95;
case 96: return _Data96;
case 97: return _Data97;
case 98: return _Data98;
case 99: return _Data99;
case 100: return _Data100;
case 101: return _Data101;
case 102: return _Data102;
case 103: return _Data103;
case 104: return _Data104;
case 105: return _Data105;
case 106: return _Data106;
case 107: return _Data107;
case 108: return _Data108;
case 109: return _Data109;
case 110: return _Data110;
case 111: return _Data111;
case 112: return _Data112;
case 113: return _Data113;
case 114: return _Data114;
case 115: return _Data115;
case 116: return _Data116;
case 117: return _Data117;
case 118: return _Data118;
case 119: return _Data119;
case 120: return _Data120;
case 121: return _Data121;
case 122: return _Data122;
case 123: return _Data123;
case 124: return _Data124;
case 125: return _Data125;
case 126: return _Data126;
case 127: return _Data127;
case 128: return _Data128;
case 129: return _Data129;
case 130: return _Data130;
case 131: return _Data131;
case 132: return _Data132;
case 133: return _Data133;
case 134: return _Data134;
case 135: return _Data135;
case 136: return _Data136;
case 137: return _Data137;
case 138: return _Data138;
case 139: return _Data139;
case 140: return _Data140;
case 141: return _Data141;
case 142: return _Data142;
case 143: return _Data143;
case 144: return _Data144;
case 145: return _Data145;
case 146: return _Data146;
case 147: return _Data147;
case 148: return _Data148;
case 149: return _Data149;
case 150: return _Data150;
case 151: return _Data151;
case 152: return _Data152;
case 153: return _Data153;
case 154: return _Data154;
case 155: return _Data155;
case 156: return _Data156;
case 157: return _Data157;
case 158: return _Data158;
case 159: return _Data159;
case 160: return _Data160;
case 161: return _Data161;
case 162: return _Data162;
case 163: return _Data163;
case 164: return _Data164;
case 165: return _Data165;
case 166: return _Data166;
case 167: return _Data167;
case 168: return _Data168;
case 169: return _Data169;
case 170: return _Data170;
case 171: return _Data171;
case 172: return _Data172;
case 173: return _Data173;
case 174: return _Data174;
case 175: return _Data175;
case 176: return _Data176;
case 177: return _Data177;
case 178: return _Data178;
case 179: return _Data179;
case 180: return _Data180;
case 181: return _Data181;
case 182: return _Data182;
case 183: return _Data183;
case 184: return _Data184;
case 185: return _Data185;
case 186: return _Data186;
case 187: return _Data187;
case 188: return _Data188;
case 189: return _Data189;
case 190: return _Data190;
case 191: return _Data191;
case 192: return _Data192;
case 193: return _Data193;
case 194: return _Data194;
case 195: return _Data195;
case 196: return _Data196;
case 197: return _Data197;
case 198: return _Data198;
case 199: return _Data199;
case 200: return _Data200;
case 201: return _Data201;
case 202: return _Data202;
case 203: return _Data203;
case 204: return _Data204;
case 205: return _Data205;
case 206: return _Data206;
case 207: return _Data207;
case 208: return _Data208;
case 209: return _Data209;
case 210: return _Data210;
case 211: return _Data211;
case 212: return _Data212;
case 213: return _Data213;
case 214: return _Data214;
case 215: return _Data215;
case 216: return _Data216;
case 217: return _Data217;
case 218: return _Data218;
case 219: return _Data219;
case 220: return _Data220;
case 221: return _Data221;
case 222: return _Data222;
case 223: return _Data223;
case 224: return _Data224;
case 225: return _Data225;
case 226: return _Data226;
case 227: return _Data227;
case 228: return _Data228;
case 229: return _Data229;
case 230: return _Data230;
case 231: return _Data231;
case 232: return _Data232;
case 233: return _Data233;
case 234: return _Data234;
case 235: return _Data235;
case 236: return _Data236;
case 237: return _Data237;
case 238: return _Data238;
case 239: return _Data239;
case 240: return _Data240;
case 241: return _Data241;
case 242: return _Data242;
case 243: return _Data243;
case 244: return _Data244;
case 245: return _Data245;
case 246: return _Data246;
case 247: return _Data247;
case 248: return _Data248;
case 249: return _Data249;
case 250: return _Data250;
case 251: return _Data251;
case 252: return _Data252;
case 253: return _Data253;
case 254: return _Data254;
case 255: return _Data255;
}
return 0;
}
uint getData(uint idx) {
return getDataRaw(idx) * 127.0f;
}
sampler2D _Font;
uint _Atlas_Width, _Atlas_Height;
float _CharBorder;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
static bool isInMirror = UNITY_MATRIX_P._31 != 0 || UNITY_MATRIX_P._32 != 0;
half4 frag (v2f i) : SV_Target
{
float2 uv = i.uv;
half4 col = tex2D(_MainTex, uv);
if (uv.x >= _TextRegion.x && uv.x < _TextRegion.z &&
uv.y >= _TextRegion.y && uv.y < _TextRegion.w)
{
uv -= _TextRegion.xy;
uv /= (_TextRegion.zw - _TextRegion.xy);
if (isInMirror) {
uv.x = 1 - uv.x;
}
uint width = getData(1);
uint height = getData(2);
if (width == 0 || height == 0) {
discard;
}
float2 luv = uv * float2(width, height);
uint char_idx = ((uint)luv.x) + ((height - 1) - (uint)luv.y) * width;
//uint char = 48 + char_idx;
uint char = getData(16 + char_idx);
float2 atlas_offset = float2(char % _Atlas_Width, (char / _Atlas_Width) + 1) *
float2(1.0/_Atlas_Width, 1.0/_Atlas_Height);
atlas_offset.y = 1 - atlas_offset.y;
float2 true_uv = atlas_offset + ((frac(luv)*0.95 + 0.025) * float2(1.0/_Atlas_Width, 1.0/_Atlas_Height));
float4 font_mask = tex2D(_Font, true_uv);
col = lerp(0, 1, font_mask.r);
}
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment