63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[CustomEditor(typeof(Region)), CanEditMultipleObjects]
|
|
public class RegionEditor : Editor
|
|
{
|
|
|
|
Region region;
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
DrawDefaultInspector();
|
|
|
|
if (GUILayout.Button("Populate Region"))
|
|
{
|
|
populateRegion();
|
|
}
|
|
|
|
if (GUILayout.Button("Fix Object Heights"))
|
|
{
|
|
heightFix();
|
|
}
|
|
}
|
|
|
|
public void heightFix()
|
|
{
|
|
|
|
}
|
|
|
|
public void populateRegion()
|
|
{
|
|
region = (Region)target;
|
|
//terrain = region.gameObject;
|
|
Debug.Log("Creating region models.");
|
|
|
|
|
|
if (region.scatterObjects == null)
|
|
{
|
|
Debug.Log("no scatter objects set.");
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < 400; i++)
|
|
{
|
|
for (int j = 0; j < 400; j++)
|
|
{
|
|
if (Random.Range(0,region.density) == 0)
|
|
{
|
|
GameObject g = region.scatterObjects[Random.Range(0, region.scatterObjects.Length)];
|
|
GameObject newObject = Instantiate(g);
|
|
float offsetX = region.transform.position.x - 200.0f;
|
|
float offsetZ = region.transform.position.z - 200.0f;
|
|
newObject.transform.position = new Vector3(j + offsetX, 22.5f, i + offsetZ);
|
|
newObject.transform.rotation = Quaternion.Euler(0,Random.Range(0, 100) * 45,0);
|
|
newObject.transform.parent = region.transform;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|