private void Populate() { objectPool = new List <Element>(); linePool = new List <LineScript>(); foreach (ElementData ed in GameHandler.dataHandler.GetElementData(currentExpression)) { GameObject go = Instantiate(GameHandler.objectHandler.elements[(int)ed.type], panels); go.transform.localPosition = new Vector3(ed.positionX, ed.positionY, 0.0f); Element e = go.GetComponentInChildren <Element>(); e.SetData(objectPool.Count, this); ReLabel(e); objectPool.Add(e); } int currentElement = 0; foreach (ElementData ed in GameHandler.dataHandler.GetElementData(currentExpression)) { for (int i = 0; i < ed.inputs.Length; i++) { if (ed.inputs[i] != null) { // Add line // TODO - Make special line for bools GameObject go = Instantiate(GameHandler.objectHandler.line, lines); LineScript ls = go.GetComponent <LineScript>(); ls.SetConnect1(objectPool[currentElement].GetHandels()[i]); ls.SetConnect2(objectPool[GameHandler.dataHandler.GetElementInputDestinationIndex(currentExpression, currentElement, i)].GetHandleOut()); ls.SetPlaced(false); } } currentElement++; } }
public void Drop() { LineScript ls = element.GetCallBack().currentDrawingLine; ls.connect2 = this; // Check if the connection is in cross bool cross = false; if (handleType == HandleType.In || handleType == HandleType.BoolIn) { if (element.GetHandleOut() != null) { foreach (Handle h in element.GetHandleOut().otherHandle) { if (h.element == ls.connect1.element) { cross = true; break; } } } } else { foreach (Handle parentH in element.GetHandels()) { foreach (Handle h in parentH.otherHandle) { if (h.element == ls.connect1.element) { cross = true; break; } } } } if (ls.connect1.element == ls.connect2.element || ls.connect1.handleType == ls.connect2.handleType || (otherHandle.Count > 0 && (handleType == HandleType.In || handleType == HandleType.BoolIn)) || cross ) { ls.connect2 = null; } else if (((ls.connect1.handleType == HandleType.BoolIn || ls.connect1.handleType == HandleType.BoolOut) && (ls.connect2.handleType == HandleType.In || ls.connect2.handleType == HandleType.Out)) || ((ls.connect2.handleType == HandleType.BoolIn || ls.connect2.handleType == HandleType.BoolOut) && (ls.connect1.handleType == HandleType.In || ls.connect1.handleType == HandleType.Out)) ) { // Connect bool to values ls.connect2 = null; } else { ls.SetPlaced(true); } }