예제 #1
0
    /// <summary>
    /// Gets the closest door to worldOrigin on the path from worldOrigin to targetPos (if there is one)
    /// Assumes that
    /// </summary>
    /// <param name="worldOrigin">Origin World position to check from. This is required because e.g. Windoors may not appear closed from certain positions.</param>
    /// <param name="targetPos">target world position to check</param>
    /// <returns>The DoorTrigger of the closed door object specified in the summary, null if no such object
    /// exists at that location</returns>
    public static InteractableDoor GetClosedDoorAt(Vector3Int worldOrigin, Vector3Int targetPos, bool isServer)
    {
        // Check door on the local tile first
        Vector3Int       localTarget = Instance.WorldToLocalInt(targetPos, AtPoint(targetPos, isServer).Matrix);
        InteractableDoor originDoor  = Instance.GetFirst <InteractableDoor>(worldOrigin, isServer);

        if (originDoor && !originDoor.GetComponent <RegisterDoor>().IsPassableTo(localTarget, isServer))
        {
            return(originDoor);
        }

        // No closed door on local tile, check target tile
        Vector3Int       localOrigin = Instance.WorldToLocalInt(worldOrigin, AtPoint(worldOrigin, isServer).Matrix);
        InteractableDoor targetDoor  = Instance.GetFirst <InteractableDoor>(targetPos, isServer);

        if (targetDoor && !targetDoor.GetComponent <RegisterDoor>().IsPassable(localOrigin, isServer))
        {
            return(targetDoor);
        }

        // No closed doors on either tile
        return(null);
    }