예제 #1
0
 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();
 }
예제 #2
0
 private void PickUpKey(GameObject target)
 {
     homeObject  = target;
     homeKey     = target.GetComponent <DetachableKey>();
     dragging    = Object.Instantiate(DetachablePrefab, FindUtilities.TryFind("FirstPersonCharacter").transform);
     draggingKey = dragging.GetComponent <DetachableKey>();
     draggingKey.SetValue(homeKey.GetValue());
     dragging.GetComponent <BoxCollider>().enabled = false;
     draggingKey.Drag();
 }
예제 #3
0
    private void SwapKeys(GameObject target)
    {
        DetachableKey targetKey = target.GetComponent <DetachableKey>();
        char          temp      = targetKey.GetValue();

        targetKey.SetValue(homeKey.GetValue());
        homeKey.SetValue(temp);
        target.transform.parent.GetComponent <Puzzle>().ResetBoardAt(targetKey.GetRow(), targetKey.GetCol(), targetKey);
        homeObject.transform.parent.GetComponent <Puzzle>().ResetBoardAt(homeKey.GetRow(), homeKey.GetCol(), homeKey);
        Object.Destroy(dragging);
        dragging    = null;
        draggingKey = null;
    }
예제 #4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(mouseRay, out hit, 2.0f))
         {
             if (hit.collider.tag == "DetachableKey")
             {
                 DetachableKey dk = hit.collider.GetComponent <DetachableKey>();
                 if (!dk.IsPressed())
                 {
                     PickUpKey(dk.gameObject);
                 }
             }
         }
     }
     else if (Input.GetMouseButtonUp(1))
     {
         mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(mouseRay, out hit, 2.0f))
         {
             if (hit.collider.tag == "DetachableKey")
             {
                 DetachableKey dk = hit.collider.GetComponent <DetachableKey>();
                 if (!dk.IsPressed())
                 {
                     SwapKeys(dk.gameObject);
                 }
                 else
                 {
                     DropKey();
                 }
             }
             else if (hit.collider.tag == "BlankKey")
             {
                 PutDownKey(hit.collider.gameObject);
             }
             else
             {
                 DropKey();
             }
         }
         else
         {
             DropKey();
         }
     }
 }
예제 #5
0
    public static bool AutoPickUp(char c)
    {
        int firstBlank = FindFirstBlank();

        if (firstBlank > -1)
        {
            GameObject    target = TabletPuzzle.GetKeyAt(firstBlank).gameObject;
            DetachableKey dk     = KeyUtilities.ConvertKey <BlankKey, DetachableKey>(
                ref target, ColorUtilities.DETACHABLE, "DetachableKey"
                );
            dk.SetValue(c);
            TabletPuzzle.ResetBoardAt(dk.GetRow(), dk.GetCol(), dk);
            return(true);
        }
        return(false);
    }
예제 #6
0
    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);
    }
예제 #7
0
 public void ConvertPressedDetachablesToVanilla()
 {
     for (int i = 0; i < board.GetLength(0); i++)
     {
         for (int j = 0; j < board.GetLength(1); j++)
         {
             if (board[i, j].tag == "DetachableKey" && board[i, j].pressed)
             {
                 DetachableKey dk        = (DetachableKey)board[i, j];
                 GameObject    keyObject = dk.gameObject;
                 NormalKey     nk        = KeyUtilities.ConvertKey <DetachableKey, NormalKey>(
                     ref keyObject, ColorUtilities.NORMAL, "NormalKey"
                     );
                 ResetBoardAt(nk.GetRow(), nk.GetCol(), nk);
                 if (complete)
                 {
                     nk.Lock();
                 }
             }
         }
     }
 }
예제 #8
0
 private void DropKey()
 {
     Object.Destroy(dragging);
     dragging    = null;
     draggingKey = null;
 }