/* * This method is used to create a container which is used to house the connected * puzzle pieces... */ public void createContainer(Vector2 eventPosition, GameObject piece_a, GameObject piece_b) { //Debug.Log ("Create Container Called"); GameObject temp = new GameObject(); temp.transform.SetParent(this.transform); RectTransform rect = temp.AddComponent <RectTransform> (); //rect.localPosition = eventPosition; // add the JigsawConnections GO to the new object created... JigsawConnections connect = temp.AddComponent <JigsawConnections> (); connect = connect.addPiece(piece_a); connect = connect.addPiece(piece_b); temp.AddComponent <DragAndDropGroup> (); connect.setPositions(piece_a.GetComponent <JigsawPieceData> ()); if (connect.getConnectedPieces().Count == foundPieces.Count) { onJigsawCompleted.Invoke(); } }
// Used to add a new Jigsaw piece to the collection public JigsawConnections addPiece(GameObject add) { JigsawConnections ret = this; connectedPieces.Add(add); JigsawConnections[] allConnected = GameObject.FindObjectsOfType <JigsawConnections> (); foreach (JigsawConnections jc in allConnected) { if (jc == this) { continue; } if (jc.getConnectedPieces().Contains(add)) { if (this.connectedPieces.Count >= jc.getConnectedPieces().Count) { connectedPieces.UnionWith(jc.getConnectedPieces()); } else { jc.getConnectedPieces().UnionWith(this.connectedPieces); ret = jc; // remove object after delay so that a value is still returned... Destroy(this.gameObject, .1f); markedForDeath = true; } } } add.GetComponent <JigsawPieceData> ().setConnected(true); foreach (GameObject go in connectedPieces) { Destroy(go.GetComponent <DragAndDrop> ()); } return(ret); }