Esempio n. 1
0
        /*public void createConnection(ConnectionInstruction inst, FishBox otherBox) {
         *  Debug.Log(inst.ToString());
         *  BoxInfo thisBoxInst = inst.firstBox;
         *  BoxInfo otherBoxInst = inst.secondBox;
         *  string thisCorner = thisBoxInst.corner;
         *  string thisWall = thisBoxInst.wall;
         *  string otherCorner = otherBoxInst.corner;
         *  string otherWall = otherBoxInst.wall;
         *  if (connectedBoxes.ContainsKey(otherBox))
         *  {
         *      foreach (ConnectionInstruction i in connectedBoxes[otherBox])
         *      {
         *          if (inst.sameInstruction(i))
         *          {
         *              Debug.Log("Cannot complete instruction " + inst.ToString() + " because the connection already exists");
         *              return;
         *          }
         *      }
         *      addConnection(inst, otherBox);
         *  }
         *  else if (this == otherBox) {
         *      Debug.Log("Cannot complete instruction "+inst.ToString()+". Cant connect box to itself");
         *  }
         *  else
         *  {
         *
         *      Vector3 otherPos = otherBox.getPosition();
         *      //apply to all connections - write a helper method would you
         *      int direction = 1;
         *      if (otherBoxInst.wall == "bottom") { direction = -1; }
         *      //so we need to do movements relative otherbox
         *      fishTank.transform.position = otherPos + (otherBox.fishTank.transform.up * boxWidthZ*direction);
         *      if (otherCorner == "A" || otherCorner == "B")
         *      {
         *          fishTank.transform.position += (otherBox.fishTank.transform.forward * (boxWidthZ / 2));
         *      }
         *      else
         *      {
         *          fishTank.transform.position += (otherBox.fishTank.transform.forward * (-boxWidthZ / 2));
         *      }
         *
         *      if (otherCorner == "B" || otherCorner == "D")
         *      {
         *          fishTank.transform.position += (otherBox.fishTank.transform.right * (boxWidthX / 2));
         *      }
         *      else
         *      {
         *          fishTank.transform.position += (otherBox.fishTank.transform.right * (-boxWidthX / 2));
         *      }
         *
         *      makeCornersTouch(thisBoxInst, otherBoxInst, otherBox, fishTank.transform.position);
         *
         *      setWallCorner(false, thisWall, thisCorner);
         *      otherBox.setWallCorner(false, otherWall, otherCorner);
         *
         *      connectedBoxes[otherBox] = new List<ConnectionInstruction> {inst};
         *      otherBox.connectedBoxes[this] = new List<ConnectionInstruction> { inst };
         *  }
         * }*/

        private void makeCornersTouch(BoxInfo thisBoxInst, BoxInfo otherBoxInst, FishBox otherBox, Vector3 pivot)
        {
            string     thisCorner  = thisBoxInst.corner;
            string     otherCorner = otherBoxInst.corner;
            Quaternion otherRot    = otherBox.getRotation();

            fishTank.transform.rotation = otherRot;
            String newThisCorner = thisCorner;
            int    rotSign       = 1;

            if (thisBoxInst.wall == otherBoxInst.wall)
            {
                //I would also write method for this, it needs to flip the fish to work right
                fishTank.transform.rotation *= Quaternion.Euler(180 * Vector3.forward);
                if (thisCorner == "A")
                {
                    newThisCorner = "B";
                }
                else if (thisCorner == "B")
                {
                    newThisCorner = "A";
                }
                else if (thisCorner == "C")
                {
                    newThisCorner = "D";
                }
                else if (thisCorner == "D")
                {
                    newThisCorner = "C";
                }
                rotSign = -1;
            }
            Debug.Log(pivot);
            List <String> corners = new List <String>(new String[] { "D", "C", "A", "B" });
            int           offset  = ((2 - corners.IndexOf(newThisCorner) + corners.IndexOf(otherCorner)) * rotSign * 90);

            fishTank.transform.RotateAround(pivot, Vector3.up, offset);
        }