示例#1
0
        private void addConnection(ConnectionInstruction inst, FishBox otherBox)
        {
            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[otherBox][0].secondBox.wall != otherWall ||
                connectedBoxes[otherBox][0].firstBox.wall != thisWall)
            {
                Debug.Log("Cannot complete instruction " + inst.ToString() +
                          ". A box cannot be connected to two different walls on the same box");
                return;
            }
            if (connectedBoxes[otherBox].Count >= 2)
            {
                connectedBoxes[otherBox].Add(inst);
                otherBox.connectedBoxes[this].Add(inst);
                return;
            }
            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.rotation = otherBox.fishTank.transform.rotation;
                fishTank.transform.position = otherPos + (otherBox.fishTank.transform.up * boxWidthZ * direction);
                connectWalls(thisWall, otherBox, otherWall, true);

                connectedBoxes[otherBox].Add(inst);
                otherBox.connectedBoxes[this].Add(inst);
                return;
            }
        }
示例#2
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
                };
            }
        }