You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
5.9 KiB
C#
133 lines
5.9 KiB
C#
|
4 years ago
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using SiegeSong;
|
||
|
|
|
||
|
|
namespace SiegeSong
|
||
|
|
{
|
||
|
|
public class TerrainPlateInstantiator : MonoBehaviour
|
||
|
|
{
|
||
|
|
public GameObject TerrainObject;
|
||
|
|
public GameObject[][] AreaPlates;
|
||
|
|
public GameObject[][] LocalePlates;
|
||
|
|
public GameObject[][] RegionPlates;
|
||
|
|
|
||
|
|
public string TerrainName;
|
||
|
|
public string TopTerrainName;
|
||
|
|
public string LeftTerrainName;
|
||
|
|
public string BottomTerrainName;
|
||
|
|
public string RightTerrainName;
|
||
|
|
|
||
|
|
float TerrainWidth = 1024.0f;
|
||
|
|
Color AreaRenderColor = Color.blue;
|
||
|
|
float AreaWidth = 32.0f;
|
||
|
|
float AreaHeight = 1.0f;
|
||
|
|
Color LocaleRenderColor = Color.green;
|
||
|
|
float LocaleWidth = 128.0f;
|
||
|
|
float LocaleHeight = 1.0f;
|
||
|
|
Color RegionRenderColor = Color.red;
|
||
|
|
float RegionWidth = 256.0f;
|
||
|
|
float RegionHeight = 1.0f;
|
||
|
|
|
||
|
|
int rotationX = 270;
|
||
|
|
int verticalOffset = 30;
|
||
|
|
|
||
|
|
public void InstantiatePlates()
|
||
|
|
{
|
||
|
|
TerrainObject = gameObject;
|
||
|
|
|
||
|
|
TerrainName = gameObject.name;
|
||
|
|
|
||
|
|
var regionsObject = new GameObject("Regions");
|
||
|
|
regionsObject.transform.parent = TerrainObject.transform;
|
||
|
|
var regionCount = (TerrainWidth / RegionWidth);
|
||
|
|
|
||
|
|
for (var i = 0; i < regionCount; i++)
|
||
|
|
{
|
||
|
|
for (var j = 0; j < regionCount; j++)
|
||
|
|
{
|
||
|
|
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||
|
|
cube.transform.position = new Vector3(RegionWidth * i, RegionWidth * j, 0);
|
||
|
|
cube.transform.localScale = new Vector3(RegionWidth, RegionWidth, RegionHeight);
|
||
|
|
cube.transform.parent = regionsObject.transform;
|
||
|
|
cube.GetComponent<Renderer>().material.SetColor("_Color", RegionRenderColor);
|
||
|
|
cube.layer = 11;
|
||
|
|
cube.GetComponent<MeshRenderer>().enabled = false;
|
||
|
|
cube.AddComponent<BoxCollider>();
|
||
|
|
cube.AddComponent<LoadingPlate>();
|
||
|
|
cube.name = $"{TerrainName}_Region_{i}_{j}";
|
||
|
|
cube.GetComponent<LoadingPlate>().LocationName = $"{TerrainName}_Region_{i}_{j}";
|
||
|
|
cube.GetComponent<LoadingPlate>().Public = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().Dangerous = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().LoadClass = LoadZoneClassification.Region;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
regionsObject.transform.eulerAngles = new Vector3(rotationX, 0, 0);
|
||
|
|
regionsObject.transform.position = new Vector3(RegionWidth / 2, verticalOffset, RegionWidth / -2);
|
||
|
|
|
||
|
|
var localesObject = new GameObject("Locales");
|
||
|
|
localesObject.transform.parent = TerrainObject.transform;
|
||
|
|
var localeCount = (TerrainWidth / LocaleWidth);
|
||
|
|
|
||
|
|
for (var i = 0; i < localeCount; i++)
|
||
|
|
{
|
||
|
|
for (var j = 0; j < localeCount; j++)
|
||
|
|
{
|
||
|
|
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||
|
|
cube.transform.position = new Vector3(LocaleWidth * i, LocaleWidth * j, 0);
|
||
|
|
cube.transform.localScale = new Vector3(LocaleWidth, LocaleWidth, LocaleHeight);
|
||
|
|
cube.transform.parent = localesObject.transform;
|
||
|
|
cube.GetComponent<Renderer>().material.SetColor("_Color", LocaleRenderColor);
|
||
|
|
cube.layer = 11;
|
||
|
|
cube.GetComponent<MeshRenderer>().enabled = false;
|
||
|
|
cube.AddComponent<BoxCollider>();
|
||
|
|
cube.AddComponent<LoadingPlate>();
|
||
|
|
cube.GetComponent<LoadingPlate>().LocationName = $"{TerrainName}_Locale_{i}_{j}";
|
||
|
|
cube.name = $"{TerrainName}_Locale_{i}_{j}";
|
||
|
|
cube.GetComponent<LoadingPlate>().Public = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().Dangerous = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().LoadClass = LoadZoneClassification.Locale;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
localesObject.transform.eulerAngles = new Vector3(rotationX, 0, 0);
|
||
|
|
localesObject.transform.position = new Vector3(LocaleWidth / 2, verticalOffset, LocaleWidth / -2);
|
||
|
|
|
||
|
|
var areasObject = new GameObject("Areas");
|
||
|
|
areasObject.transform.parent = TerrainObject.transform;
|
||
|
|
var areaCount = (TerrainWidth / AreaWidth);
|
||
|
|
|
||
|
|
for (var i = 0; i < areaCount; i++)
|
||
|
|
{
|
||
|
|
for (var j = 0; j < areaCount; j++)
|
||
|
|
{
|
||
|
|
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||
|
|
cube.transform.position = new Vector3(AreaWidth * i, AreaWidth * j, 0);
|
||
|
|
cube.transform.localScale = new Vector3(AreaWidth, AreaWidth, AreaHeight);
|
||
|
|
cube.transform.parent = areasObject.transform;
|
||
|
|
cube.GetComponent<Renderer>().material.SetColor("_Color", AreaRenderColor);
|
||
|
|
cube.layer = 11;
|
||
|
|
cube.GetComponent<MeshRenderer>().enabled = false;
|
||
|
|
cube.AddComponent<BoxCollider>();
|
||
|
|
cube.AddComponent<LoadingPlate>();
|
||
|
|
cube.name = $"{TerrainName}_Area_{i}_{j}";
|
||
|
|
cube.GetComponent<LoadingPlate>().LocationName = $"{TerrainName}_Area_{i}_{j}";
|
||
|
|
cube.GetComponent<LoadingPlate>().Public = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().Dangerous = true;
|
||
|
|
cube.GetComponent<LoadingPlate>().LoadClass = LoadZoneClassification.Area;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
areasObject.transform.eulerAngles = new Vector3(rotationX, 0, 0);
|
||
|
|
areasObject.transform.position = new Vector3(AreaWidth / 2, verticalOffset, AreaWidth / -2);
|
||
|
|
}
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|