Ejemplo n.º 1
0
 private int CompareDoorwaysTileWeight(DoorwayPair x, DoorwayPair y)
 {
     // Reversed to sort with highest TileWeight value first
     return(y.TileWeight.CompareTo(x.TileWeight));
 }
Ejemplo n.º 2
0
        protected TilePlacementResult TryPlaceTile(DoorwayPair pair, DungeonArchetype archetype, out Tile tile)
        {
            tile = null;

            var toTemplate  = pair.NextTemplate;
            var fromDoorway = pair.PreviousDoorway;

            if (toTemplate == null)
            {
                return(TilePlacementResult.TemplateIsNull);
            }

            int toDoorwayIndex = pair.NextTemplate.Doorways.IndexOf(pair.NextDoorway);

            if (fromDoorway != null)
            {
                // Move the proxy object into position
                GameObject toProxyDoor = toTemplate.ProxySockets[toDoorwayIndex];
                UnityUtil.PositionObjectBySocket(toTemplate.Proxy, toProxyDoor, fromDoorway.gameObject);

                Bounds proxyBounds = toTemplate.Proxy.GetComponent <Collider>().bounds;

                // Check if the new tile is outside of the valid bounds
                if (RestrictDungeonToBounds && !TilePlacementBounds.Contains(proxyBounds))
                {
                    return(TilePlacementResult.OutOfBounds);
                }

                // Check if the new tile is colliding with any other
                if (IsCollidingWithAnyTile(proxyBounds))
                {
                    return(TilePlacementResult.TileIsColliding);
                }
            }

            TilePlacementData newTile = new TilePlacementData(toTemplate, (Status == GenerationStatus.MainPath), archetype, pair.NextTileSet, currentDungeon);

            if (newTile == null)
            {
                return(TilePlacementResult.NewTileIsNull);
            }

            if (newTile.IsOnMainPath)
            {
                if (pair.PreviousTile != null)
                {
                    newTile.PathDepth = pair.PreviousTile.Placement.PathDepth + 1;
                }
            }
            else
            {
                newTile.PathDepth   = pair.PreviousTile.Placement.PathDepth;
                newTile.BranchDepth = (pair.PreviousTile.Placement.IsOnMainPath) ? 0 : pair.PreviousTile.Placement.BranchDepth + 1;
            }

            if (fromDoorway != null)
            {
                newTile.Root.transform.parent = Root.transform;
                Doorway toDoorway = newTile.AllDoorways[toDoorwayIndex];

                UnityUtil.PositionObjectBySocket(newTile.Root, toDoorway.gameObject, fromDoorway.gameObject);
                currentDungeon.MakeConnection(fromDoorway, toDoorway, RandomStream);
            }
            else
            {
                newTile.Root.transform.parent        = Root.transform;
                newTile.Root.transform.localPosition = Vector3.zero;
            }

            currentDungeon.AddTile(newTile.Tile);

            if (!newTile.Tile.OverrideAutomaticTileBounds)
            {
                newTile.RecalculateBounds(IgnoreSpriteBounds, UpVector);
            }
            else
            {
                newTile.Bounds      = newTile.Tile.transform.TransformBounds(newTile.Tile.TileBoundsOverride);
                newTile.LocalBounds = newTile.Tile.TileBoundsOverride;
            }

            if (PlaceTileTriggers)
            {
                newTile.Tile.AddTriggerVolume();
                newTile.Root.layer = TileTriggerLayer;
            }

            allDoorways.AddRange(newTile.AllDoorways);

            tile = newTile.Tile;
            placedTilePrefabs[tile] = toTemplate.Prefab;

            return(TilePlacementResult.None);
        }