本项目演示如何创建自己的顶点动画着色器。场景不使用任何纹理或动画资源,所有内容都使用Shader Graph进行着色和动画处理。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

117 行
2.1 KiB

using UnityEngine;
namespace Polybrush
{
/**
* RGBA / XYZW / 0123
*/
public enum z_ComponentIndex
{
R = 0,
X = 0,
G = 1,
Y = 1,
B = 2,
Z = 2,
A = 3,
W = 3
};
public enum z_ComponentIndexType
{
Vector = 0,
Color = 1,
Index = 2
};
public static class z_ComponentIndexUtility
{
public static float GetValueAtIndex(this Vector3 value, z_ComponentIndex index)
{
switch(index)
{
case z_ComponentIndex.X:
return value.x;
case z_ComponentIndex.Y:
return value.y;
case z_ComponentIndex.Z:
return value.z;
default:
return 0f;
}
}
public static float GetValueAtIndex(this Vector4 value, z_ComponentIndex index)
{
switch(index)
{
case z_ComponentIndex.X:
return value.x;
case z_ComponentIndex.Y:
return value.y;
case z_ComponentIndex.Z:
return value.z;
case z_ComponentIndex.W:
return value.w;
default:
return 0f;
}
}
public static float GetValueAtIndex(this Color value, z_ComponentIndex index)
{
switch(index)
{
case z_ComponentIndex.R:
return value.r;
case z_ComponentIndex.G:
return value.g;
case z_ComponentIndex.B:
return value.b;
case z_ComponentIndex.A:
return value.a;
default:
return 0f;
}
}
public static uint ToFlag(this z_ComponentIndex e)
{
int i = ((int)e) + 1;
return (uint)(i < 3 ? i : i == 3 ? 4 : 8);
}
public static string GetString(this z_ComponentIndex component, z_ComponentIndexType type = z_ComponentIndexType.Vector)
{
int ind = ((int)component);
if(type == z_ComponentIndexType.Vector)
return ind == 0 ? "X" : (ind == 1 ? "Y" : (ind == 2 ? "Z" : "W"));
else if(type == z_ComponentIndexType.Color)
return ind == 0 ? "R" : (ind == 1 ? "G" : (ind == 2 ? "B" : "A"));
else
return ind.ToString();
}
public static readonly GUIContent[] ComponentIndexPopupDescriptions = new GUIContent[]
{
new GUIContent("X (R)"),
new GUIContent("Y (G)"),
new GUIContent("Z (B)"),
new GUIContent("W (A)")
};
public static readonly int[] ComponentIndexPopupValues = new int[]
{
0,
1,
2,
3
};
}
}