Ejemplo n.º 1
0
        public override Map Generate()
        {
            if (carvedModule == null)
            {
                throw new InvalidOperationException("Must assign a map generator to carve entrances for.");
            }

            carvedModule.Seed = seed;
            Map       map      = carvedModule.Generate();
            Boundary  boundary = new Boundary(map.Length, map.Width);
            ITunneler tunneler = MapTunnelers.GetRandomDirectedTunneler(boundary, seed, MapTunnelers.Variance.Low);

            foreach (MapEntrance entrance in entrances)
            {
                int   numCoords    = entrance.GetCoords(boundary).Count();
                int   halfwayIndex = Mathf.Min(numCoords - 1, numCoords / 2);
                Coord midPoint     = entrance.GetCoords(boundary).Skip(halfwayIndex).First();
                ConnectEntrance(map, midPoint, tunneler);
                foreach (Coord coord in entrance.GetCoords(boundary))
                {
                    map[coord] = Tile.Floor;
                }
            }
            return(map);
        }
Ejemplo n.º 2
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (visualize && Event.current.type == EventType.Repaint)
     {
         MapGenModule mapGenerator = (MapGenModule)serializedObject.targetObject;
         if (mapGenerator != null)
         {
             Map map = mapGenerator.Generate();
             if (map != null)
             {
                 Texture texture = map.ToTexture();
                 GUI.DrawTexture(r, texture, ScaleMode.StretchToFill, false);
             }
         }
     }
 }
        public override Map Generate()
        {
            if (carvedModule == null)
            {
                throw new InvalidOperationException("Must assign a map generator to carve entrances for.");
            }

            carvedModule.Seed = seed;
            Map      map      = carvedModule.Generate();
            Boundary boundary = new Boundary(map.Length, map.Width);

            foreach (MapEntrance entrance in entrances)
            {
                foreach (Coord coord in entrance.GetCoords(boundary))
                {
                    map[coord] = Tile.Floor;
                }
            }
            MapBuilder.ConnectFloors(map, seed: seed, tunnelRadius: tunnelRadius);
            return(map);
        }
Ejemplo n.º 4
0
 public override void OnPreviewGUI(Rect position, GUIStyle background)
 {
     if (Event.current.type == EventType.Repaint)
     {
         bool         suppressErrors = serializedObject.FindProperty("suppressErrors").boolValue;
         MapGenModule mapGenerator   = GetMapGenModule();
         if (mapGenerator != null)
         {
             try
             {
                 Map map = mapGenerator.Generate();
                 if (map != null)
                 {
                     Texture texture = map.ToTexture();
                     GUI.DrawTexture(position, texture, ScaleMode.StretchToFill, false);
                 }
             }
             // If the generator is not configured properly yet, then errors may occur. The following
             // likely, non-fatal exceptions are caught and (optionally) suppressed here, to avoid flooding
             // the editor console while configuring. This behaviour is optional to avoid suppressing
             // useful diagnostic information if using this visualizer while writing new code.
             catch (InvalidOperationException) { if (!suppressErrors)
                                                 {
                                                     throw;
                                                 }
             }
             catch (NullReferenceException) { if (!suppressErrors)
                                              {
                                                  throw;
                                              }
             }
             catch (ArgumentException) { if (!suppressErrors)
                                         {
                                             throw;
                                         }
             }
         }
     }
 }