82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace GISTech.GISTerrainLoader
|
|
{
|
|
public class AirplaneDemo : MonoBehaviour
|
|
{
|
|
public RealWorldElevation ElevationMode = RealWorldElevation.Altitude;
|
|
|
|
public DVector2 StartPositionLatLon;
|
|
|
|
public float StartElevation = 1500f;
|
|
|
|
public float Movingspeed;
|
|
|
|
public float RotationSpeed;
|
|
|
|
public WayPoints waypoints;
|
|
|
|
[HideInInspector]
|
|
public Vector3 TargetPoint = new Vector3(0f, 0f, 0f);
|
|
|
|
private Quaternion rotation;
|
|
|
|
private int wayIndex;
|
|
|
|
[HideInInspector]
|
|
public bool EnableFlying;
|
|
|
|
public GISTerrainContainer container;
|
|
|
|
public void OnTerrainGeneratingCompleted()
|
|
{
|
|
base.transform.position = GISTerrainLoaderGeoConversion.RealWorldCoordinatesToUnityWorldSpace(GISTerrainLoaderMonoSingleton<RuntimeTerrainGenerator>.Get.GeneratedContainer, StartPositionLatLon, StartElevation, SetElevationMode.RelativeToSeaLevel);
|
|
if (container == null)
|
|
{
|
|
container = Object.FindObjectOfType<GISTerrainContainer>(includeInactive: true);
|
|
}
|
|
if (waypoints.UnityWorldSpacePoints.Count > 0)
|
|
{
|
|
TargetPoint = waypoints.UnityWorldSpacePoints[0];
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (!(TargetPoint != Vector3.zero))
|
|
{
|
|
return;
|
|
}
|
|
AirPlaneGuidance(TargetPoint);
|
|
if (Vector3.Distance(base.transform.position, TargetPoint) < 10f)
|
|
{
|
|
wayIndex++;
|
|
if (wayIndex > waypoints.UnityWorldSpacePoints.Count - 1)
|
|
{
|
|
wayIndex = 0;
|
|
}
|
|
TargetPoint = waypoints.UnityWorldSpacePoints[wayIndex];
|
|
}
|
|
}
|
|
|
|
private void AirPlaneGuidance(Vector3 target)
|
|
{
|
|
Vector3 vector = target - base.transform.position;
|
|
vector = target - base.transform.position;
|
|
rotation = Quaternion.LookRotation(vector, base.transform.up);
|
|
base.transform.rotation = Quaternion.RotateTowards(base.transform.rotation, rotation, RotationSpeed * Time.fixedDeltaTime);
|
|
base.transform.Translate(base.transform.forward * Movingspeed * Time.deltaTime, Space.World);
|
|
}
|
|
|
|
public DVector3 GetAirPlaneLatLonElevation()
|
|
{
|
|
return GISTerrainLoaderGeoConversion.UnityWorldSpaceToRealWorldCoordinates(base.transform.position, container, GetElevation: true, ElevationMode);
|
|
}
|
|
|
|
public DVector2 GetWayPointLatLon()
|
|
{
|
|
return GISTerrainLoaderGeoConversion.UnityWorldSpaceToRealWorldCoordinates(TargetPoint, container).ToDVector2();
|
|
}
|
|
}
|
|
}
|