C# 行渲染器显示不正确
我左右为难,弄不清楚问题出在哪里。我有一个网格的细胞。。。我将鼠标拖过它们,并使用线渲染器在它们之间创建连接。问题是线条渲染器看起来不正常,我将在下面附加一个图像以查看问题所在。多谢各位C# 行渲染器显示不正确,c#,unity3d,renderer,C#,Unity3d,Renderer,我左右为难,弄不清楚问题出在哪里。我有一个网格的细胞。。。我将鼠标拖过它们,并使用线渲染器在它们之间创建连接。问题是线条渲染器看起来不正常,我将在下面附加一个图像以查看问题所在。多谢各位 public Grid grid; public float connectionDistanceLimit = 3.185f; //0.91*3.5 public float snapDistance = 0.2f; public LineRenderer connectionRenderer; priva
public Grid grid;
public float connectionDistanceLimit = 3.185f; //0.91*3.5
public float snapDistance = 0.2f;
public LineRenderer connectionRenderer;
private List<Vector3> connectionPositions;
public List<GridCell> cellsOnScreen = new List<GridCell>();
public List<GridCell> connectedCells;
private GridCell lastConnectedCell;
private GridCell currentSelectedCell;
private bool conectionStarted = false;
IEnumerator Start()
{
yield return new WaitForEndOfFrame();
cellsOnScreen = grid.GetGridElements();
foreach (GridCell cell in cellsOnScreen)
cell.CellPointEvent += Cell_CellPointEvent;
}
private void Cell_CellPointEvent(bool enter, GridCell cell)
{
currentSelectedCell = cell;
if (conectionStarted)
return;
connectionPositions = new List<Vector3>();
connectedCells = new List<GridCell>();
connectedCells.Add(cell);
Vector3 positionToAdd = cell.transform.position;
positionToAdd.z = 0f;
connectionPositions.Add(positionToAdd);
cell.SetColor();
conectionStarted = true;
}
void Update()
{
if (Input.GetMouseButton(0))
{
if (connectionPositions != null)
{
if (lastConnectedCell != null)
{
if (lastConnectedCell != currentSelectedCell)
return;
}
List<Vector3> tempPositions = new List<Vector3>(connectionPositions);
Vector3 mPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 lastConnection = tempPositions[tempPositions.Count - 1];
mPosition.z = 0f;
lastConnection.z = 0f;
if (Vector3.Distance(lastConnection, mPosition) > connectionDistanceLimit)
{
Ray r = new Ray(lastConnection, (mPosition - lastConnection));
mPosition = r.GetPoint(connectionDistanceLimit);
}
if (Vector3.Distance(lastConnection, mPosition) < connectionDistanceLimit)
foreach (GridCell cell in cellsOnScreen)
{
if (!connectedCells.Contains(cell))
{
GridCell lastCell = connectedCells[connectedCells.Count - 1];
if ((cell.transform.position.y > lastCell.transform.position.y && cell.transform.position.x != lastCell.transform.position.x) ||
cell.transform.position.y < lastCell.transform.position.y && cell.transform.position.x != lastCell.transform.position.x)
{
}
else
{
if (Vector3.Distance(mPosition, cell.transform.position) <= snapDistance)
{
connectedCells.Add(cell);
connectionPositions.Add(cell.transform.position);
cell.isConnected = true;
cell.SetColor();
break;
}
}
}
}
lastConnection.z = 0f;
mPosition.z = 0f;
tempPositions.Add(mPosition);
connectionRenderer.positionCount = tempPositions.Count;
connectionRenderer.SetPositions(tempPositions.ToArray());
}
}
if (Input.GetMouseButtonUp(0))
{
lastConnectedCell = connectedCells[connectedCells.Count - 1];
}
}
公共电网;
公共浮动连接距离限值=3.185f//0.91*3.5
公共浮动捕捉距离=0.2f;
公共线条渲染器连接渲染器;
私有列表连接位置;
公共列表单元格屏幕=新列表();
公共列表连接的单元格;
私有网格单元lastConnectedCell;
私有网格单元currentSelectedCell;
私有布尔连接开始=false;
IEnumerator Start()
{
返回新的WaitForEndOfFrame();
cellsOnScreen=grid.GetGridElements();
foreach(cellsOnScreen中的GridCell单元)
cell.CellPointEvent+=cell_CellPointEvent;
}
私有无效单元格\u CellPointEvent(布尔输入,GridCell单元格)
{
currentSelectedCell=单元格;
如果(连接已启动)
返回;
connectionPositions=新列表();
connectedCells=新列表();
连接的单元格。添加(单元格);
Vector3 positionToAdd=cell.transform.position;
添加位置z=0f;
连接位置。添加(位置添加);
cell.SetColor();
consectionstarted=true;
}
无效更新()
{
if(输入。GetMouseButton(0))
{
if(connectionPositions!=null)
{
if(lastConnectedCell!=null)
{
如果(lastConnectedCell!=currentSelectedCell)
返回;
}
List tempPositions=新列表(connectionPositions);
Vector3位置=Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 lastConnection=tempPositions[tempPositions.Count-1];
位置z=0f;
lastConnection.z=0f;
if(矢量3.距离(上次连接、位置)>连接距离限制)
{
射线r=新射线(lastConnection,(mPosition-lastConnection));
mPosition=r.GetPoint(连接距离限制);
}
if(矢量3.距离(上次连接、位置)<连接距离限制)
foreach(cellsOnScreen中的GridCell单元)
{
如果(!connectedCells.Contains(单元格))
{
GridCell lastCell=connectedCells[connectedCells.Count-1];
if((cell.transform.position.y>lastCell.transform.position.y&&cell.transform.position.x!=lastCell.transform.position.x)||
cell.transform.position.y 如果(Vector3.Distance(mPosition,cell.transform.position)在一个地方有多个点的位置,或者宽度曲线的设置错误,则可能会发生这种奇怪的行为。
LineRenderer并不是为了这个目的。实际上,很难统一绘制普通的“2D”线条。实际上,您必须使用Linefy或Fast Line Renderer之类的东西。LineRenderer实际上只用于开发,实际上只用于制作“色带”在3D中,角点
和端盖顶点
需要为非零。这两个值无论如何都没有帮助,它们只是为了圆角不一定,因为在连接2个点后,我将删除它们并创建与其中精灵的连接。基本上,我将使线渲染器最多有4个点。