using System.Collections.Generic;
using System.Linq;
using InfinityCode.RealWorldTerrain.Generators;
using InfinityCode.RealWorldTerrain.OSM;
using UnityEditor;
using UnityEngine;
public class InterceptBuildingGeneration:EditorWindow
{
private static GameObject container;
[MenuItem("RWT Extra/Intercept Building Generation")]
public static void InterceptGeneration()
{
// Intercept generation of buildings
RealWorldTerrainBuildingGenerator.OnGenerateBuilding = OnGenerateBuilding;
Debug.Log("Generation of buildings intercepted");
}
///
/// This method is called when generating each building
///
/// List of points in Unity World Space
/// Reference to the way
/// Dictionary of all the nodes of all buildings.
/// True - the building was generated successfully, false - generate the building with a built-in generator.
private static bool OnGenerateBuilding(List points, RealWorldTerrainOSMWay way, Dictionary nodes)
{
// Here you generate a building
if (container == null)
{
container = new GameObject("Building Container");
}
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
go.name = way.id;
Bounds bounds = new Bounds(points[0], Vector3.zero);
for (int i = 1; i < points.Count; i++)
{
bounds.Encapsulate(points[i]);
}
go.transform.SetParent(container.transform);
go.transform.position = bounds.center;
return true;
}
[MenuItem("RWT Extra/Restore Building Generation")]
public static void RestoreGeneration()
{
// Restore generation of buildings
RealWorldTerrainBuildingGenerator.OnGenerateBuilding = null;
Debug.Log("Generation of buildings restored");
}
}