[英]How can I draw a Line animation to outline various shapes?
我将执行以下操作:(伪代码,未经测试)
对于每个预制件或游戏对象,请存储定义轮廓的边列表。 我不建议使用网格物体的边缘,最好为每个形状指定特定的边缘预定义列表,以避免对象的内部边缘。 列表中的每个条目都由两个Vector3定义,这两个是两个顶点。
List<Vector3[]> outline = new List<Vector3[]>();
现在,您有许多方法可以实际绘制箭头,例如将它们作为单独的游戏对象(可能不是一个好主意),粒子系统,或者只是从父对象更新功能自动绘制。 我建议后者。
现在,您将存储一堆用于定义箭头位置的浮点数
public List<float> arrow_locations = new List<float>();
//adding one arrow
arrow_locations.Add(0.0);
//now in the update function of your parent object, update the arrow locations
private float cycle = 0.0f;
void Update()
{
float segment_size = 360.0f/outline.Count;
for(int i=0; i < arrow_locations.Count; i++)
{
arrow_locations[i] += 0.05f; //speed of spinning
if( arrow_locations[i] >= 360.0f ) arrow_locations[i] = 0;
//now to get the actual location of the arrow
int which_edge = Mathf.Floor((arrow_locations[i]/360.0f)*outline.Count);
//this will give us a number 0..1 telling us where along the edge the arrow is
float weight_within_edge=(arrow_locations[i] - segment_size*which_edge)/segment_size;
//here we lerp between the two vertices of the edge
Vector3 new_loc = outline[which_edge][0]*(1.0-weight_within_edge) + outline[which_edge][1]*(weight_within_edge);
//now that we have the location of the arrow, draw it
//note, you can get more efficient if using instancing for all arrows
//You can also use line drawing, but i wouldn't recommend that.
DrawMesh(arrow_mesh, new_loc, Quaternion.identity);
}
}
请注意,当您拥有箭头的位置时,可以通过将其投影到相机平面上来选择在UI中以2D绘制它们。 箭头旁边的线条本身是静态的,因此您可以很容易地将它们绘制为网格的一部分。 还要注意,我没有提到对象的位置,所有值可能应该在局部空间中定义,然后与对象一起转换。 您可以通过提供aa变换矩阵在DrawMesh函数中变换绘制的内容。
我认为带有参数化径向遮罩的着色器将是实现此目的的最佳方法。 我从来没有自己做过,所以我对它的完成方式只有一个大致的了解,但以下是AFAIK的工作方式:
为了帮助可视化,绘制了一个非常专业的油漆图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.