public virtual void CollectUnusedDetachables() { for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { if (board[i, j].gameObject.tag == "DetachableKey" && !board[i, j].IsPressed()) { int firstBlank = PlayerInventory.FindFirstBlank(); if (firstBlank > -1) { GameObject original = board[i, j].gameObject; GameObject clone = Object.Instantiate(this.detachableKey, this.transform); DetachableKey cloneKey = clone.GetComponent <DetachableKey>(); clone.transform.localPosition = original.transform.localPosition; cloneKey.SetValue(board[i, j].GetValue()); BlankKey blankOriginal = KeyUtilities.ConvertKey <DetachableKey, BlankKey>( ref original, ColorUtilities.BLANK, "BlankKey" ); ResetBoardAt(blankOriginal.GetRow(), blankOriginal.GetCol(), blankOriginal); Key k = PlayerInventory.GetPuzzle().GetKeyAt(firstBlank); cloneKey.AutoPickUp(k.transform.position); return; } } } } LockPuzzle(); }
private void PutDownKey(GameObject target) { BlankKey bk = KeyUtilities.ConvertKey <DetachableKey, BlankKey>( ref homeObject, ColorUtilities.BLANK, "BlankKey" ); bk.gameObject.transform.parent.gameObject.GetComponent <Puzzle>().ResetBoardAt(bk.GetRow(), bk.GetCol(), bk); BlankKey targetKey = target.GetComponent <BlankKey>(); char val = draggingKey.GetValue(); Object.Destroy(dragging); dragging = null; draggingKey = null; DetachableKey placed = KeyUtilities.ConvertKey <BlankKey, DetachableKey>( ref target, ColorUtilities.DETACHABLE, "DetachableKey" ); placed.SetValue(val); placed.gameObject.transform.parent.GetComponent <Puzzle>().ResetBoardAt(placed.GetRow(), placed.GetCol(), placed); }