所以我做了这个形状,我通过这个脚本应用于精灵:
void insert(int val){
if(this.elem < val){
if(this.right != null){
this.right.insert(val);
}
else{
nodes++;
this.right = new Node(val);
}
}
else if(this.elem > val){
if(this.left != null){
this.left.insert(val);
}
else{
nodes++;
this.left = new Node(val);
}
}
else {
return;
}
}
正如您在屏幕截图中看到的那样,开始和结束都没有按预期连接。我怎样才能解决这个问题?我在整个互联网上找到了这段代码,但都给出了这个结果。有人可以解决这个问题或提供一个样条解决方案吗?我认为去Shader解决方案(使用着色器的0经验)有点过分。
答案 0 :(得分:0)
这个解决方案可能有点复杂。但它会起作用。
这个想法是
1)将第一段绘制为小分段区域
2)从秒到最后-1段作为大段。
3)将最后一段绘制为小的分段区域。
它在起始段和结束段之间形成无缝边缘。 总分段的数量并不算太多。
total segment = segment + 2 * subsegment
这是示例代码。
using UnityEngine;
using System.Collections;
public class CircleShapeGenerator : MonoBehaviour {
public int segments = 100;
public int edgeSegments = 10;
public float radius = 1f;
int vertCount;
float increAngle, increAngleEdge;
public Color c1 = new Color( 1, 1, 1, 1f );
public Color c2 = new Color( 1, 1, 1, 1f );
LineRenderer line;
void Start ()
{
vertCount = segments + 2*edgeSegments - 2 + 1;
increAngle = 360f / segments;
increAngleEdge = increAngle/edgeSegments;
line = gameObject.AddComponent<LineRenderer>();
line.material = new Material(Shader.Find("Particles/Additive"));
line.SetWidth(0.05F, 0.05F);
line.SetVertexCount (vertCount);
line.useWorldSpace = false;
}
void Update()
{
line.SetColors(c1, c2);
//draw first segment
float angle = 0;
for (int i = 0; i < edgeSegments; i++)
{
float x = Mathf.Sin (Mathf.Deg2Rad * angle) * radius;
float y = Mathf.Cos (Mathf.Deg2Rad * angle) * radius;
line.SetPosition( i, new Vector3(x, y, 0) );
angle += increAngleEdge;
}
//draw from seconds to last-1 segment
angle -= increAngleEdge;
for (int i = 0; i < segments-2; i++)
{
angle += increAngle;
float x = Mathf.Sin (Mathf.Deg2Rad * angle) * radius;
float y = Mathf.Cos (Mathf.Deg2Rad * angle) * radius;
line.SetPosition( edgeSegments + i, new Vector3(x, y, 0) );
}
//draw last segment
for (int i = 0; i < edgeSegments+1; i++)
{
angle += increAngleEdge;
float x = Mathf.Sin (Mathf.Deg2Rad * angle) * radius;
float y = Mathf.Cos (Mathf.Deg2Rad * angle) * radius;
line.SetPosition( edgeSegments + segments - 2 + i, new Vector3(x, y, 0) );
}
}
}