RobotInc_线路合法性检测
线路需按照类型12345顺序排列,且必须有0开始,5结束,返回true
public void StartCheckLine() //按照一定顺序,检测线路前后链接是否正确,目前停用
{
print("start to check the line!");
if (startId != -1) {
ProdLinePart startPart = curLinePartList.Find(item => item.itemId == startId); //找到线路core部位作为起始位置
print("find start part, and it's id is " + startPart.itemId+", and it's type is " + startPart.type+", and it's outid is " + startPart.outId);
if (CheckProdLine(startPart, 1))
{
//secceedPanel.SetActive(true);
print("succeed!");
}
else
{
failToBuildPanel.SetActive(true);
}
}
else
{
print("no core built");
}
}
bool CheckProdLine(ProdLinePart curEndPart, int curLineType)
{
print("------start to check-----" + curEndPart.itemId + " , " + curLineType);
if(curEndPart.type == 5 ) //如果到了结束part,检测
{
if(curLineType > 1)
{
print("it's over!");
return true;
}
}
else //当前part非结束part
{
if (curEndPart.outId != -1)
{
print("current part out id is not -1");
ProdLinePart nextPart = curLinePartList.Find(item => item.itemId == curEndPart.outId);
print("find next part in list is " + nextPart.itemId);
if (curEndPart.type == 0)
{
print("current item is a transfer");
if (nextPart.type == 0)
{
print("next part is also a transfer");
return CheckProdLine(nextPart, curLineType);
}
else
{
print("next part is not a transfer");
if (curLineType < nextPart.type) //机器必须按照顺序的做法
{
print(" current type is " + curLineType + " , and next type is " + nextPart.type);
curLineType = nextPart.type;
return CheckProdLine(nextPart, curLineType);
}
}
}
else // current part type != 0
{
if (nextPart.type == 0)
{
return CheckProdLine(nextPart, curLineType);
}
}
}
}
return false;
}