65 lines
1.8 KiB
C#
65 lines
1.8 KiB
C#
using System.Collections;
|
|
using GISTech.GISTerrainLoader;
|
|
using UnityEngine;
|
|
|
|
public class LoadVectorData : MonoBehaviour
|
|
{
|
|
public VectorType vectorType;
|
|
|
|
public KeyCode UpdateKey;
|
|
|
|
public bool LoadTexture;
|
|
|
|
public GISTerrainContainer container;
|
|
|
|
private void Start()
|
|
{
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
|
|
{
|
|
StartCoroutine(UpdateVecotrData());
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(UpdateKey))
|
|
{
|
|
StartCoroutine(UpdateVecotrData());
|
|
}
|
|
}
|
|
|
|
public IEnumerator UpdateVecotrData()
|
|
{
|
|
GISTerrainLoaderPrefs Prefs = new GISTerrainLoaderPrefs();
|
|
Prefs.LoadSettings();
|
|
Prefs.TerrainFilePath = Application.streamingAssetsPath + "/GIS Terrains/Example_VectorData/Desert.tif";
|
|
Prefs.textureMode = TextureMode.WithTexture;
|
|
Prefs.vectorType = vectorType;
|
|
Prefs.EnableRoadGeneration = OptionEnabDisab.Enable;
|
|
Prefs.EnableTreeGeneration = OptionEnabDisab.Enable;
|
|
Prefs.EnableBuildingGeneration = OptionEnabDisab.Enable;
|
|
if (LoadTexture)
|
|
{
|
|
Prefs.textureMode = TextureMode.WithTexture;
|
|
yield return StartCoroutine(container.GenerateTextures(Prefs, ClearLayers: true));
|
|
}
|
|
yield return new WaitForSeconds(2f);
|
|
yield return StartCoroutine(container.GenerateVectorData(Prefs));
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
TreeInstance[] treeInstances = new TreeInstance[0];
|
|
GISTerrainTile[,] terrains = container.terrains;
|
|
int upperBound = terrains.GetUpperBound(0);
|
|
int upperBound2 = terrains.GetUpperBound(1);
|
|
for (int i = terrains.GetLowerBound(0); i <= upperBound; i++)
|
|
{
|
|
for (int j = terrains.GetLowerBound(1); j <= upperBound2; j++)
|
|
{
|
|
terrains[i, j].terrainData.treeInstances = treeInstances;
|
|
}
|
|
}
|
|
}
|
|
}
|