73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using GISTech.GISTerrainLoader;
|
|
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class GetSetRealWorldPosition : MonoBehaviour
|
|
{
|
|
public TerrainSourceMode terrainSourceMode;
|
|
|
|
public GameObject Player;
|
|
|
|
public RealWorldElevation GetElevationMode = RealWorldElevation.Altitude;
|
|
|
|
private GISTerrainContainer container;
|
|
|
|
[Space(10f)]
|
|
public DVector2 Coordinates = new DVector2(2.72289517819244, 33.8634254169107);
|
|
|
|
public SetElevationMode SetElevationMode = SetElevationMode.RelativeToSeaLevel;
|
|
|
|
public float StartElevation = 20f;
|
|
|
|
private void Start()
|
|
{
|
|
if (terrainSourceMode == TerrainSourceMode.FromEditMode)
|
|
{
|
|
GetTerrainData();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.G))
|
|
{
|
|
DVector3 objectLatLonElevation = GetObjectLatLonElevation();
|
|
Debug.Log("Lat/Lon: " + objectLatLonElevation.x + " " + objectLatLonElevation.y + " Elevation :" + objectLatLonElevation.z);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.S))
|
|
{
|
|
Player.transform.position = GISTerrainLoaderGeoConversion.RealWorldCoordinatesToUnityWorldSpace(container, Coordinates, StartElevation, SetElevationMode);
|
|
}
|
|
}
|
|
|
|
public void GetTerrainData()
|
|
{
|
|
container = Object.FindObjectOfType<GISTerrainContainer>();
|
|
if ((bool)container)
|
|
{
|
|
container.GetStoredHeightmap();
|
|
}
|
|
}
|
|
|
|
public void GetPosition()
|
|
{
|
|
DVector3 objectLatLonElevation = GetObjectLatLonElevation();
|
|
Debug.Log("Lat/Lon: " + objectLatLonElevation.x + " " + objectLatLonElevation.y + " Elevation :" + objectLatLonElevation.z);
|
|
}
|
|
|
|
public void SetPosition()
|
|
{
|
|
container = Object.FindObjectOfType<GISTerrainContainer>();
|
|
if ((bool)container)
|
|
{
|
|
Player.transform.position = GISTerrainLoaderGeoConversion.RealWorldCoordinatesToUnityWorldSpace(container, Coordinates, StartElevation, SetElevationMode);
|
|
}
|
|
}
|
|
|
|
public DVector3 GetObjectLatLonElevation()
|
|
{
|
|
container = Object.FindObjectOfType<GISTerrainContainer>();
|
|
return GISTerrainLoaderGeoConversion.UnityWorldSpaceToRealWorldCoordinates(Player.transform.position, container, GetElevation: true, GetElevationMode);
|
|
}
|
|
}
|