public override void OnInspectorGUI() { base.OnInspectorGUI(); MapGenModule mapGenerator = GetMapGenModule(); if (mapGenerator != null) { EditorHelpers.DrawFoldoutEditor("Map Generator", mapGenerator, ref foldout, ref editor); } }
void WindowFunction(int id) { infoResizer.Draw(rect); mapGenModule = (MapGenModule)EditorGUILayout.ObjectField("Map Gen Module:", mapGenModule, typeof(MapGenModule), false); if (mapGenModule != null) { Editor.CreateCachedEditor(mapGenModule, null, ref mapGenEditor); mapGenEditor.OnInspectorGUI(); } GUI.DragWindow(new Rect(0, 0, rect.width, WindowHelpers.WINDOW_TITLE_HEIGHT)); }
public override IEnumerable <Coord> GetBoundary() { var boundary = Enumerable.Empty <Coord>(); for (int i = 0; i < modules.Length; i++) { Coord offset = (Coord)offsets[i]; MapGenModule mod = modules[i]; boundary = boundary.Concat(mod.GetBoundary().Select(coord => coord + offset)); } return(boundary); }
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 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; } } } } }
public void Draw(Rect nodeRect, MapGenModule module, bool isSelected) { if (module != null) { Texture boundaryTexture = isSelected ? activeSquare : inactiveSquare; Vector2 center = WindowHelpers.RoundToLattice(nodeRect.center); Vector2 square = SQUARE_SIZE * Vector2.one; Rect rect = new Rect(center, square); foreach (Coord coord in module.GetBoundary()) { DrawBox(center, coord, rect, boundaryTexture); } Coord mapSize = module.GetMapSize(); Boundary boundary = new Boundary(mapSize.x, mapSize.y); foreach (MapEntrance entrance in module.GetOpenings()) { foreach (Coord coord in entrance.GetCoords(boundary)) { DrawBox(center, coord, rect, entranceSquare); } } } }
/// <param name="openings">Can be empty not but null.</param> /// <param name="tunnelRadius">Must be at least 1.</param> public static MapGenEntranceCarver Construct(MapGenModule mapGenerator, IEnumerable <MapEntrance> openings, int tunnelRadius = 1) { if (mapGenerator == null) { throw new ArgumentNullException("mapGenerator"); } if (openings == null) { throw new ArgumentNullException("openings"); } if (tunnelRadius < 1) { throw new ArgumentOutOfRangeException("tunnelRadius", "Tunnel radius must be at least 1."); } var carver = CreateInstance <MapGenEntranceCarver>(); carver.entrances = openings.ToArray(); carver.MapGenerator = mapGenerator; carver.tunnelRadius = tunnelRadius; return(carver); }
public MapGenWindow(int id, MapGenModule mapGenModule) { this.id = id; this.mapGenModule = mapGenModule; infoResizer = new RectResizer(NodeEditorSettings.RESIZE_HANDLE_SIZE, infoWindowLimits.BotLeft, infoWindowLimits.TopRight); }
void AddNode(Rect position, MapGenModule mapGenModule) { nodes.Add(new NodeGroup(nodeNumber, position, RemoveNode, mapGenModule)); nodeNumber++; }
public NodeGroup(int id, Rect position, Action <NodeGroup> onClickRemoveNode, MapGenModule mapGenModule) { this.id = id; node = new Node(position, () => onClickRemoveNode(this)); info = new MapGenWindow(id, mapGenModule); boundaryDrawer = new BoundaryDrawer(); }
public SavedNode(MapGenModule mapGenModule, Rect rect) { this.mapGenModule = mapGenModule; this.rect = rect; }