GridPlacement 6.0 (formerly GridBuilding)
Development ⚠️ GridPlacement 6.0 documentation is in active development. APIs and content may change, and the site may be temporarily unstable.

Code Examples

Welcome to the examples collection! Here you’ll find practical implementations, code snippets, and complete projects that demonstrate how to use the Grid Building Plugin in real-world scenarios.

Repo Note: In this monorepo, the authoritative C# source for GridPlacement 6.0 (formerly GridBuilding) lives under plugins/gameplay/GridPlacement/. Demo projects such as demos/grid_building_dev are exported snapshots and may lag behind; treat them as examples only, not the source of truth.

🚀 Quick Examples

Basic Grid Setup

Get started with a simple grid setup and basic building placement. Perfect for understanding the core concepts.

Concepts covered:
GridBuilder GBOwner Basic Placement

Isometric Grid

Implement an isometric grid system with proper coordinate transformation and visual alignment.

Concepts covered:
Isometric Coordinate Transform Visual Alignment

3D Grid Building

Create a 3D grid building system with elevation support and multi-layer construction.

Concepts covered:
3D Grid Elevation Multi-Layer

🎮 Game-Specific Examples

Strategy Games

City Builder

Complete city building mechanics with zones, utilities, and population management.

Features:
Zoning System Resource Management Population Logic

Tower Defense

Strategic tower placement with pathfinding, range visualization, and wave management.

Features:
Pathfinding Range Indicators Wave System

RTS Base Building

Real-time strategy base building with resource gathering, unit production, and tech trees.

Features:
Tech Trees Resource System Unit Production

Simulation Games

Farm Simulator

Agricultural simulation with crop placement, growth cycles, and seasonal changes.

Features:
Crop System Seasonal Logic Irrigation

Factory Builder

Industrial simulation with production lines, conveyor systems, and automation.

Features:
Production Lines Conveyor Systems Automation

Colony Sim

Colony management with habitat construction, resource management, and population needs.

Features:
Habitat System Life Support Population Needs

💡 Advanced Techniques

Custom Validation Rules

Advanced Placement Validation

Learn how to implement custom validation rules for complex placement scenarios, including terrain analysis, resource requirements, and spatial constraints.

// Custom validation example
public class TerrainValidator : IPlacementValidator
{
    public bool ValidatePlacement(GridPosition position, BuildingType type)
    {
        // Check terrain suitability
        var terrain = TerrainManager.GetTerrainAt(position);
        var requirements = BuildingDatabase.GetRequirements(type);
        
        return terrain.SupportsBuilding(requirements);
    }
}

Performance Optimization

Large-Scale Grid Performance

Techniques for optimizing grid performance with thousands of cells, including culling, batching, and efficient data structures.

// Performance optimization example
public class OptimizedGridRenderer
{
    private readonly Dictionary<Vector2Int, GridCell> _visibleCells;
    
    public void UpdateVisibility(Camera camera)
    {
        var frustum = camera.GetFrustum();
        _visibleCells.Clear();
        
        foreach (var cell in GetAllCells())
        {
            if (frustum.Contains(cell.Position))
                _visibleCells[cell.Position] = cell;
        }
    }
}

🔧 Code Snippets

Basic Setup

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
// Initialize grid builder
var gridBuilder = new GridBuilder();
gridBuilder.Initialize(new BuildingSettings
{
    GridSize = new Vector2Int(50, 50),
    CellSize = 1.0f,
    GridType = CellShape.Square
});

// Set up grid owner
var owner = new PlayerGridOwner();
gridBuilder.SetOwner(owner);

Custom Building Type

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[CreateAssetMenu]
public class CustomBuildingType : BuildingType
{
    [Header("Custom Properties")]
    public int ProductionRate;
    public ResourceType ResourceType;
    
    public override bool CanPlaceAt(GridPosition position)
    {
        // Custom placement logic
        return base.CanPlaceAt(position) && 
               HasRequiredResources(position);
    }
}

Event Handling

1
2
3
4
5
6
7
8
9
// Subscribe to building events
gridBuilder.OnBuildingPlaced += OnBuildingPlaced;
gridBuilder.OnBuildingRemoved += OnBuildingRemoved;

private void OnBuildingPlaced(Building building)
{
    Debug.Log($"Building {building.name} placed at {building.Position}");
    UpdateProduction(building);
}

📚 Learning Resources

Step-by-Step Tutorials

  1. Your First Grid - Complete beginner’s guide
  2. Advanced Validation - Custom placement rules
  3. Performance Optimization - Large-scale grids
  4. Multiplayer Integration - Network synchronization

Video Tutorials

Community Projects


🎯 Start Building

Ready to dive in? Here’s our recommended learning path:

  1. Start with Basic Setup - Understand the fundamentals
  2. Try a Game Example - See real-world implementation
  3. Explore Advanced Topics - Customize for your needs
  4. Join the Community - Share and learn with others

Start Creating Amazing Grid Systems

These examples will help you master the Grid Building Plugin and create incredible games.