100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace GISTech.GISTerrainLoader
|
|
{
|
|
public class GISVirtualTextureTerrainGenerator : MonoBehaviour
|
|
{
|
|
public KeyCode GenerateKey;
|
|
|
|
public WayPoints GeoWaypoints;
|
|
|
|
public AirplaneDemo AirPlane;
|
|
|
|
public Text UIText;
|
|
|
|
public bool InstantiateGameObjects;
|
|
|
|
private string TerrainFilePath;
|
|
|
|
private RuntimeTerrainGenerator RuntimeGenerator;
|
|
|
|
private GISTerrainLoaderPrefs Prefs;
|
|
|
|
private GISTerrainLoaderRuntimePrefs RuntimePrefs;
|
|
|
|
[HideInInspector]
|
|
public bool TerrainGenerated;
|
|
|
|
private void Start()
|
|
{
|
|
TerrainFilePath = Application.streamingAssetsPath + "/GIS Terrains/GISVirtualTexture/Tererro.tif";
|
|
RuntimePrefs = GISTerrainLoaderMonoSingleton<GISTerrainLoaderRuntimePrefs>.Get;
|
|
Prefs = RuntimePrefs.Prefs;
|
|
RuntimeGenerator = GISTerrainLoaderMonoSingleton<RuntimeTerrainGenerator>.Get;
|
|
RuntimeTerrainGenerator.OnFinish += OnTerrainGeneratingCompleted;
|
|
if (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
|
|
{
|
|
StartCoroutine(GenerateTerrain(TerrainFilePath));
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(GenerateKey))
|
|
{
|
|
StartCoroutine(GenerateTerrain(TerrainFilePath));
|
|
}
|
|
if (TerrainGenerated)
|
|
{
|
|
UIText.text = "Latitude: " + AirPlane.GetAirPlaneLatLonElevation().y + " \nLongitude: " + AirPlane.GetAirPlaneLatLonElevation().x + " \nElevation:" + AirPlane.GetAirPlaneLatLonElevation().z + " m";
|
|
}
|
|
}
|
|
|
|
private IEnumerator GenerateTerrain(string TerrainPath)
|
|
{
|
|
yield return new WaitForSeconds(2f);
|
|
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
|
|
{
|
|
if (!string.IsNullOrEmpty(TerrainPath) && File.Exists(TerrainPath))
|
|
{
|
|
InitializingRuntimePrefs(TerrainPath);
|
|
StartCoroutine(RuntimeGenerator.StartGenerating(Prefs));
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Terrain file null or not supported.. Try againe");
|
|
yield return null;
|
|
}
|
|
}
|
|
else if (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
|
|
{
|
|
InitializingRuntimePrefs(TerrainPath);
|
|
StartCoroutine(RuntimeGenerator.StartGenerating(Prefs));
|
|
}
|
|
}
|
|
|
|
private void InitializingRuntimePrefs(string TerrainPath)
|
|
{
|
|
RuntimeGenerator.enabled = true;
|
|
Prefs.TerrainFilePath = TerrainPath;
|
|
Prefs.RemovePrvTerrain = OptionEnabDisab.Enable;
|
|
Prefs.TerrainElevation = TerrainElevation.RealWorldElevation;
|
|
Prefs.terrainDimensionMode = TerrainDimensionsMode.AutoDetection;
|
|
Prefs.heightmapResolution = 4097;
|
|
Prefs.textureMode = TextureMode.WithoutTexture;
|
|
Debug.Log("GIS Virtual Texture Not instaled on your project");
|
|
}
|
|
|
|
private void OnTerrainGeneratingCompleted(GISTerrainContainer m_container)
|
|
{
|
|
GeoWaypoints.ConvertLatLonToSpacePosition(RuntimeGenerator.GeneratedContainer, InstantiateGameObjects);
|
|
AirPlane.OnTerrainGeneratingCompleted();
|
|
TerrainGenerated = true;
|
|
Debug.Log("GIS Virtual Texture Not instaled on your project");
|
|
}
|
|
}
|
|
}
|