public void Connect(ComponentBase cmp) { Debug.Log ("Connecting..."); int i = CurrentIndex(); if (i == -1) return; connections[i].IsAvailable = false; cmp.GetComponent<Rigidbody>().isKinematic = true; cmp.transform.position = connections[i].pointPos; cmp.transform.LookAt(2*cmp.transform.position - connections[i].Obj.position); cmp.transform.parent = connections[i].Obj.transform; foreach(Connection c in cmp.connections) connections.Add (c); }
public void Disconnect(ComponentBase cmp, bool checkConn = true) { if (checkConn) { Transform prnt = cmp.transform.parent; while (prnt != null && prnt != transform) { prnt = prnt.parent; } if (prnt == null) { return; } } var children = cmp.transform.GetComponentsInChildren <ComponentBase> (); if (children != null && children.Length > 0) { for (int i = 0; i < children.Length; ++i) { if (cmp != children[i] && children[i] != null) { Disconnect(children[i], false); } } } foreach (Connection c in cmp.connections) { connections.Remove(c); } cmp.GetComponent <Rigidbody>().isKinematic = false; cmp.transform.parent = null; var con = connections.Where((c) => c.pointPos == cmp.transform.position); if (con != null && con.Count() > 0) { con.First().IsAvailable = true; } }
public void Connect(ComponentBase cmp) { Debug.Log("Connecting..."); int i = CurrentIndex(); if (i == -1) { return; } connections[i].IsAvailable = false; cmp.GetComponent <Rigidbody>().isKinematic = true; cmp.transform.position = connections[i].pointPos; cmp.transform.LookAt(2 * cmp.transform.position - connections[i].Obj.position); cmp.transform.parent = connections[i].Obj.transform; foreach (Connection c in cmp.connections) { connections.Add(c); } }
public void Disconnect(ComponentBase cmp, bool checkConn = true) { if (checkConn) { Transform prnt = cmp.transform.parent; while (prnt != null && prnt != transform) prnt = prnt.parent; if (prnt == null) return; } var children = cmp.transform.GetComponentsInChildren<ComponentBase> (); if(children != null && children.Length > 0) for (int i = 0; i < children.Length; ++i) if(cmp != children[i] && children[i] != null) Disconnect (children[i],false); foreach (Connection c in cmp.connections) { connections.Remove (c); } cmp.GetComponent<Rigidbody>().isKinematic = false; cmp.transform.parent = null; var con = connections.Where ((c) => c.pointPos == cmp.transform.position); if (con != null && con.Count() > 0) con.First ().IsAvailable = true; }