コード例 #1
0
        public override void EmitMarkers(DungeonBuilder builder)
        {
            var visited = new HashSet <IntVector>();
            var model   = builder.Model as GridDungeonModel;

            if (model == null)
            {
                return;
            }

            var   gridSize       = model.Config.GridCellSize;
            float overrideYValue = 0;

            if (overrideY)
            {
                overrideYValue = builder.Blackboard.FloatEntries.GetValue(overrideYBlackboardKey);
            }

            for (int d = 1; d <= distanceToCover; d++)
            {
                var indexedMarkerName = indexedMarkerNamePrefix + d;
                foreach (var cell in model.Cells)
                {
                    if (cell.CellType == CellType.Unknown)
                    {
                        continue;
                    }

                    var bounds = cell.Bounds;
                    bounds = Rectangle.ExpandBounds(bounds, d);
                    var points = bounds.GetBorderPoints();
                    foreach (var point in points)
                    {
                        var hash = new IntVector(point.x, 0, point.z);
                        if (!visited.Contains(hash))
                        {
                            // Check if this point does not lie in a cell
                            var cellInfo = model.GetGridCellLookup(point.x, point.z);
                            if (cellInfo.CellType == CellType.Unknown)
                            {
                                // Add an empty marker here
                                var position = point * gridSize;
                                position += Vector3.Scale(new Vector3(0.5f, 0, 0.5f), gridSize);
                                if (overrideY)
                                {
                                    position.y = overrideYValue;
                                }

                                var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);
                                builder.EmitMarker(markerName, transform, point, -1);
                                builder.EmitMarker(indexedMarkerName, transform, point, -1);
                            }

                            visited.Add(hash);
                        }
                    }
                }
            }
        }
コード例 #2
0
        void EmitCornerMarker(DungeonBuilder builder, GridDungeonModel model, IntVector point, string markerName)
        {
            // Add an empty marker here
            var gridSize = model.Config.GridCellSize;
            var position = point * gridSize;

            position += Vector3.Scale(new Vector3(0.5f, 0, 0.5f), gridSize);
            var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);

            builder.EmitMarker(markerName, transform, point, -1);
        }
コード例 #3
0
 void EmitForPoint(DungeonBuilder builder, GridDungeonModel model, IntVector point)
 {
     foreach (var config in CornerConfigs)
     {
         if (ConfigMatches(model, point, config))
         {
             EmitCornerMarker(builder, model, point, config.markerName);
             break;
         }
     }
 }
コード例 #4
0
        public override void EmitMarkers(DungeonBuilder builder)
        {
            if (!(builder is GridDungeonBuilder))
            {
                Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFindLowestPoint. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null"));
                return;
            }

            var gridModel = builder.Model as GridDungeonModel;
            var Min       = new Vector3(int.MaxValue, int.MaxValue, int.MaxValue);
            var Max       = new Vector3(-int.MaxValue, -int.MaxValue, -int.MaxValue);
            var gridSize  = gridModel.Config.GridCellSize;

            if (gridModel.Cells.Count == 0)
            {
                Min = Vector3.zero;
                Max = Vector3.zero;
            }
            else
            {
                foreach (var cell in gridModel.Cells)
                {
                    var location = cell.Bounds.Location * gridSize;
                    var size     = cell.Bounds.Size * gridSize;
                    Min.x = Mathf.Min(Min.x, location.x);
                    Min.y = Mathf.Min(Min.y, location.y);
                    Min.z = Mathf.Min(Min.z, location.z);

                    Max.x = Mathf.Max(Max.x, location.x + size.x);
                    Max.y = Mathf.Max(Max.y, location.y + size.y);
                    Max.z = Mathf.Max(Max.z, location.z + size.z);
                }
            }

            var rangeSize = Max - Min;

            var position = (Max + Min) / 2;

            position.y = Min.y;

            var scale     = new Vector3(rangeSize.x, 1, rangeSize.z);
            var transform = Matrix4x4.TRS(position, Quaternion.identity, scale);

            builder.EmitMarker(MarkerName, transform, IntVector.Zero, -1);

            // Save this for other markers to use, if needed
            builder.Blackboard.FloatEntries.SetValue(BlackboardKeyLowestY, Min.y);
        }
コード例 #5
0
        public override void EmitMarkers(DungeonBuilder builder)
        {
            if (!(builder is GridDungeonBuilder))
            {
                Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFindLowestPoint. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null"));
                return;
            }

            var gridModel = builder.Model as GridDungeonModel;

            foreach (var cell in gridModel.Cells)
            {
                var borderPoints = cell.Bounds.GetBorderPoints();
                foreach (var borderPoint in borderPoints)
                {
                    EmitForPoint(builder, gridModel, borderPoint);
                }
            }
        }
コード例 #6
0
        void Initialize()
        {
            if (config == null)
            {
                config = GetComponent <DungeonConfig> ();
            }

            if (sceneProvider == null)
            {
                sceneProvider = GetComponent <PooledDungeonSceneProvider> ();
            }

            if (dungeonBuilder == null)
            {
                dungeonBuilder = GetComponent <DungeonBuilder> ();
            }

            if (dungeonModel == null)
            {
                dungeonModel = GetComponent <DungeonModel> ();
            }
        }
コード例 #7
0
ファイル: DungeonMarkerEmitter.cs プロジェクト: Borgeshc/Game
 /// <summary>
 /// Called by the dungeon object right after the dungeon is created
 /// </summary>
 /// <param name="builder">reference to the builder object used to build the dungeon</param>
 public virtual void EmitMarkers(DungeonBuilder builder)
 {
 }
コード例 #8
0
        public override void EmitMarkers(DungeonBuilder builder)
        {
            if (!(builder is GridDungeonBuilder))
            {
                Debug.LogWarning("Unsupported builder type used with marker emitter MarkerEmitterFreeSpaceDecorator. Expected GridDungeonBuilder. Received:" + (builder != null ? builder.GetType().ToString() : "null"));
                return;
            }

            var model    = builder.Model as GridDungeonModel;
            var gridSize = model.Config.GridCellSize;


            var visited  = new HashSet <IntVector>();
            var occupied = new HashSet <IntVector>();

            foreach (var cell in model.Cells)
            {
                if (cell.CellType == CellType.Unknown)
                {
                    continue;
                }

                for (var distance = 2; distance <= 2; distance++)
                {
                    var bounds = cell.Bounds;
                    bounds = Rectangle.ExpandBounds(bounds, distance);
                    var points = bounds.GetBorderPoints();
                    foreach (var point in points)
                    {
                        var hash = new IntVector(point.x, 0, point.z);
                        if (!visited.Contains(hash))
                        {
                            visited.Add(hash);
                            if (occupied.Contains(hash))
                            {
                                continue;
                            }

                            // Check if this point does not lie in a cell
                            var cellInfo = model.GetGridCellLookup(point.x, point.z);
                            if (cellInfo.CellType == CellType.Unknown)
                            {
                                // Make sure the surrounding area is free so we can place a decorative item
                                bool valid = true;
                                var  s     = distanceFromEdge - 1;
                                for (var dx = -s; dx <= s; dx++)
                                {
                                    for (var dz = -s; dz <= s; dz++)
                                    {
                                        var x            = point.x + dx;
                                        var z            = point.z + dz;
                                        var neighborHash = new IntVector(x, 0, z);
                                        if (occupied.Contains(neighborHash))
                                        {
                                            valid = false;
                                            break;
                                        }
                                        var neighborCellInfo = model.GetGridCellLookup(x, z);
                                        if (neighborCellInfo.CellType != CellType.Unknown)
                                        {
                                            // Occupied by an existing cell
                                            occupied.Add(neighborHash);
                                            valid = false;
                                            break;
                                        }
                                    }
                                    if (!valid)
                                    {
                                        break;
                                    }
                                }


                                if (valid)
                                {
                                    // Valid space.  Occupy the space here
                                    for (var dx = -s; dx <= s; dx++)
                                    {
                                        for (var dz = -s; dz <= s; dz++)
                                        {
                                            var x = point.x + dx;
                                            var z = point.z + dz;
                                            occupied.Add(new IntVector(x, 0, z));
                                        }
                                    }

                                    var pushDownY = 0.0f;
                                    foreach (var pushDownAxis in pushDownTestAxis)
                                    {
                                        var delta        = pushDownAxis * distanceFromEdge;
                                        var x            = point.x + Mathf.RoundToInt(delta.x);
                                        var z            = point.z + Mathf.RoundToInt(delta.z);
                                        var testCellInfo = model.GetGridCellLookup(x, z);
                                        if (testCellInfo.CellType != CellType.Unknown)
                                        {
                                            pushDownY = pushDownAmount;
                                        }
                                    }

                                    var position = point * gridSize + new Vector3(gridSize.x, 0, gridSize.z) * 0.5f;
                                    position.y -= pushDownY;
                                    var transform = Matrix4x4.TRS(position, Quaternion.identity, Vector3.one);

                                    builder.EmitMarker(markerName, transform, point, -1);
                                }
                            }
                            else
                            {
                                // Occupied by a cell
                                occupied.Add(hash);
                            }
                        }
                    }
                }
            }
        }