//设置端口点-有正负极之分 public override void setPosts() { if (floor == 1) //若该元器件直接插在底板上 { Point point = ((GameObject)buttonColliders[0]).GetComponent <Point>(); //获取纽扣上的脚本 if (point.port == 1) //该纽扣碰撞的是电池的正极 { points[1] = ((GameObject)buttonColliders[0]).name; //获取结点名称 points[0] = ((GameObject)buttonColliders[1]).name; } else { points[0] = ((GameObject)buttonColliders[0]).name; //获取结点名称 points[1] = ((GameObject)buttonColliders[1]).name; } } else //若元器件插在其他元器件上 { int index; CircuitElm thisCE = transform.GetComponent <CircuitElm>(); //此元器件 CircuitElm ce = ((GameObject)buttonColliders[0]).transform.parent.GetComponent <CircuitElm>(); //获取元器件 if (thisCE.interfaceList[1].Equals(ce)) //若是电源的正极连接此端口 { ce = ((GameObject)buttonColliders[0]).transform.parent.GetComponent <CircuitElm>(); index = int.Parse(((GameObject)buttonColliders[0]).name); points[1] = ce.getPostFromIndex(index); //point2端口点代表电源的正极 ce = ((GameObject)buttonColliders[1]).transform.parent.GetComponent <CircuitElm>(); index = int.Parse(((GameObject)buttonColliders[1]).name); points[0] = ce.getPostFromIndex(index); //point1端口点代表电源的负极 } else //若是电源的正极连接此端口 { ce = ((GameObject)buttonColliders[0]).transform.parent.GetComponent <CircuitElm>(); index = int.Parse(((GameObject)buttonColliders[0]).name); points[0] = ce.getPostFromIndex(index); //point1端口点代表电源的负极 ce = ((GameObject)buttonColliders[1]).transform.parent.GetComponent <CircuitElm>(); index = int.Parse(((GameObject)buttonColliders[1]).name); points[1] = ce.getPostFromIndex(index); //point2端口点代表电源的正极 } } }
//设置端口点 public override void setPosts() { if (floor == 1) { points[0] = ((GameObject)buttonColliders[0]).name; } else { CircuitElm ce = ((GameObject)buttonColliders[0]).transform.parent.GetComponent <CircuitElm>(); //获取元器件 int index = int.Parse(((GameObject)buttonColliders[0]).name); //被碰撞元器件连接纽扣 points[0] = ce.getPostFromIndex(index); //获取结点名称 } }
//设置端口点 0、1纽扣代表端口1(point2) 2、3纽扣代表端口0(point1) public virtual void setPosts() { buttonCollidersIndex.Clear(); //清空纽扣对应端口的列表 if (floor == 1) //若该元器件直接插在底板上 { if (getPostCount() == 2 || type == CirSim.TYPES.WireElm) //若端口数为两个或者是导线 { if (((GameObject)buttonColliders [0]).GetComponent <Point> ().port == 1) //若碰到的时1纽扣(端口1) { points [0] = ((GameObject)buttonColliders [0]).name; //获取结点名称 points [1] = ((GameObject)buttonColliders [1]).name; } else //碰到的是3纽扣(端口0) { points [1] = ((GameObject)buttonColliders [0]).name; points [0] = ((GameObject)buttonColliders [1]).name; } } else //端口数大于2并且不是导线 { for (int i = 0; i < downHole; i++) { int port = ((GameObject)buttonColliders [i]).GetComponent <Point> ().port; //获取连接端点数 buttonCollidersIndex.Add(port / 2); //记录纽扣对应的端口 points [port / 2] = ((GameObject)buttonColliders [i]).name; //设置端点名称 } } } else if (floor > 1) //若元器件插在其他元器件上 { for (int i = 0; i < downHole; i++) { CircuitElm ce = ((GameObject)buttonColliders [i]).transform.parent.GetComponent <CircuitElm> (); //获取元器件 int port = calNextPort(transform.GetComponent <CircuitElm> (), ce); //获取本元器件的连接纽扣 int index = int.Parse(((GameObject)buttonColliders [i]).name); //被碰撞元器件连接纽扣 buttonCollidersIndex.Add(port / 2); //记录纽扣对应的端口 points [port / 2] = ce.getPostFromIndex(index); //获取结点名称 } } }