コード例 #1
0
    private void rotateToAttach(GameObject exitToAttachTo, GameObject thisSectionExit)
    {
        ExplorableSectionExit toAttachExit = exitToAttachTo.GetComponent <ExplorableSectionExit>();
        ExplorableSectionExit ownedExit    = thisSectionExit.GetComponent <ExplorableSectionExit>();

        ExplorableSectionExit.ExitDirection directionToRotateTo = getDirectionOpposite(toAttachExit.ExitOrientation);
        int numberOfRotations = getNumberOfRotationsRequired(ownedExit.ExitOrientation, directionToRotateTo);

        transform.Rotate(0, 0, numberOfRotations * 90);
        updateExitOrientations(numberOfRotations);
    }
コード例 #2
0
    private ExplorableSectionExit.ExitDirection getDirectionOpposite(ExplorableSectionExit.ExitDirection inputDirection)
    {
        // Opposites are all spaced two apart in the enum
        int oppositeDirection  = (int)inputDirection;
        int lengthOfDirections = ((ExplorableSectionExit.ExitDirection[])System.Enum.GetValues(typeof(ExplorableSectionExit.ExitDirection))).Length;

        for (int i = 0; i < 2; i++)
        {
            oppositeDirection += 1;
            if (oppositeDirection >= lengthOfDirections)
            {
                oppositeDirection -= lengthOfDirections;
            }
        }
        return(((ExplorableSectionExit.ExitDirection[])System.Enum.GetValues(typeof(ExplorableSectionExit.ExitDirection)))[oppositeDirection]);
    }
コード例 #3
0
 void Awake()
 {
     createdRooms = new List <GameObject>();
     CreateRoomBuildingPool();
     startingRoom = Instantiate(startingRoomPrefab, transform.position, Quaternion.identity);
     ExplorableSectionExit.ExitDirection startingPlayerExit = ExplorableSectionExit.ExitDirection.west;
     GameObject[] startingRoomExits = startingRoom.GetComponent <ExplorableSection>().Exits;
     for (int i = 0; i < startingRoomExits.Length; i++)
     {
         ExplorableSectionExit startingRoomExit = startingRoomExits[i].GetComponent <ExplorableSectionExit>();
         if (startingRoomExit.ExitOrientation == startingPlayerExit)
         {
             playerStartPoint = startingRoomExits[i];
         }
     }
 }
コード例 #4
0
    private int getNumberOfRotationsRequired(ExplorableSectionExit.ExitDirection currentDirection, ExplorableSectionExit.ExitDirection directionToMatch)
    {
        ExplorableSectionExit.ExitDirection[] exitDirections = (ExplorableSectionExit.ExitDirection[])System.Enum.GetValues(typeof(ExplorableSectionExit.ExitDirection));

        int startingDirectionIdx = 0;

        for (int i = 0; i < exitDirections.Length; i++)
        {
            if (currentDirection == exitDirections[i])
            {
                startingDirectionIdx = i;
                break;
            }
        }

        int targetDirectionIdx = 0;

        for (int i = 0; i < exitDirections.Length; i++)
        {
            if (directionToMatch == exitDirections[i])
            {
                targetDirectionIdx = i;
                break;
            }
        }

        int numberOfStepsToMatchDirection = 0;

        while (startingDirectionIdx != targetDirectionIdx)
        {
            startingDirectionIdx += 1;
            if (startingDirectionIdx >= exitDirections.Length)
            {
                startingDirectionIdx = startingDirectionIdx - exitDirections.Length;
            }
            numberOfStepsToMatchDirection += 1;
        }

        return(numberOfStepsToMatchDirection);
    }
コード例 #5
0
    private ExplorableSectionExit.ExitDirection getNewDirectionFromRotations(int numberOfRotations, ExplorableSectionExit.ExitDirection startingOrientation)
    {
        ExplorableSectionExit.ExitDirection[] exitDirections = (ExplorableSectionExit.ExitDirection[])System.Enum.GetValues(typeof(ExplorableSectionExit.ExitDirection));
        int orientationIdx = 0;

        for (int i = 0; i < exitDirections.Length; i++)
        {
            if (startingOrientation == exitDirections[i])
            {
                orientationIdx = i;
                break;
            }
        }

        ExplorableSectionExit.ExitDirection newDirection;
        for (int i = 0; i < numberOfRotations; i++)
        {
            orientationIdx += 1;
            if (orientationIdx >= exitDirections.Length)
            {
                orientationIdx = orientationIdx - exitDirections.Length;
            }
        }
        newDirection = exitDirections[orientationIdx];

        return(newDirection);
    }