org.outernet.cesium-unity 1.15.3-linux.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +420 -0
- package/CHANGES.md.meta +7 -0
- package/Editor/BuildCesiumForUnity.cs +186 -0
- package/Editor/BuildCesiumForUnity.cs.meta +11 -0
- package/Editor/Cesium3DTilesetEditor.cs +542 -0
- package/Editor/Cesium3DTilesetEditor.cs.meta +11 -0
- package/Editor/CesiumBingMapsRasterOverlayEditor.cs +66 -0
- package/Editor/CesiumBingMapsRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumCameraControllerEditor.cs +174 -0
- package/Editor/CesiumCameraControllerEditor.cs.meta +11 -0
- package/Editor/CesiumCameraManagerEditor.cs +65 -0
- package/Editor/CesiumCameraManagerEditor.cs.meta +11 -0
- package/Editor/CesiumCartographicPolygonEditor.cs +23 -0
- package/Editor/CesiumCartographicPolygonEditor.cs.meta +11 -0
- package/Editor/CesiumDebugColorizeTilesRasterOverlayEditor.cs +41 -0
- package/Editor/CesiumDebugColorizeTilesRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumEditor.asmdef +26 -0
- package/Editor/CesiumEditor.asmdef.meta +7 -0
- package/Editor/CesiumEditorStyle.cs +188 -0
- package/Editor/CesiumEditorStyle.cs.meta +11 -0
- package/Editor/CesiumEditorUtility.cs +394 -0
- package/Editor/CesiumEditorUtility.cs.meta +11 -0
- package/Editor/CesiumEditorWindow.cs +447 -0
- package/Editor/CesiumEditorWindow.cs.meta +11 -0
- package/Editor/CesiumFlyToControllerEditor.cs +76 -0
- package/Editor/CesiumFlyToControllerEditor.cs.meta +11 -0
- package/Editor/CesiumGeoreferenceEditor.cs +277 -0
- package/Editor/CesiumGeoreferenceEditor.cs.meta +11 -0
- package/Editor/CesiumGlobeAnchorEditor.cs +202 -0
- package/Editor/CesiumGlobeAnchorEditor.cs.meta +11 -0
- package/Editor/CesiumInspectorGUI.cs +187 -0
- package/Editor/CesiumInspectorGUI.cs.meta +11 -0
- package/Editor/CesiumIonAsset.cs +192 -0
- package/Editor/CesiumIonAsset.cs.meta +11 -0
- package/Editor/CesiumIonAssetsWindow.cs +257 -0
- package/Editor/CesiumIonAssetsWindow.cs.meta +11 -0
- package/Editor/CesiumIonRasterOverlayEditor.cs +87 -0
- package/Editor/CesiumIonRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumIonServerManager.cs +153 -0
- package/Editor/CesiumIonServerManager.cs.meta +11 -0
- package/Editor/CesiumIonServerSelector.cs +127 -0
- package/Editor/CesiumIonServerSelector.cs.meta +11 -0
- package/Editor/CesiumIonSession.cs +102 -0
- package/Editor/CesiumIonSession.cs.meta +11 -0
- package/Editor/CesiumPolygonRasterOverlayEditor.cs +102 -0
- package/Editor/CesiumPolygonRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumRasterOverlayEditor.cs +230 -0
- package/Editor/CesiumRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumSubSceneEditor.cs +201 -0
- package/Editor/CesiumSubSceneEditor.cs.meta +11 -0
- package/Editor/CesiumTileMapServiceRasterOverlayEditor.cs +88 -0
- package/Editor/CesiumTileMapServiceRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumWebMapServiceRasterOverlayEditor.cs +111 -0
- package/Editor/CesiumWebMapServiceRasterOverlayEditor.cs.meta +11 -0
- package/Editor/CesiumWebMapTileServiceRasterOverlayEditor.cs +277 -0
- package/Editor/CesiumWebMapTileServiceRasterOverlayEditor.cs.meta +3 -0
- package/Editor/CompileCesiumForUnityNative.cs +581 -0
- package/Editor/CompileCesiumForUnityNative.cs.meta +11 -0
- package/Editor/ConfigureReinterop.cs +255 -0
- package/Editor/ConfigureReinterop.cs.meta +11 -0
- package/Editor/Helpers.cs +102 -0
- package/Editor/Helpers.cs.meta +11 -0
- package/Editor/IonAssetsMultiColumnHeader.cs +45 -0
- package/Editor/IonAssetsMultiColumnHeader.cs.meta +11 -0
- package/Editor/IonAssetsTreeView.cs +214 -0
- package/Editor/IonAssetsTreeView.cs.meta +11 -0
- package/Editor/IonMissingAssetWindow.cs +65 -0
- package/Editor/IonMissingAssetWindow.cs.meta +11 -0
- package/Editor/IonTokenTroubleshootingWindow.cs +615 -0
- package/Editor/IonTokenTroubleshootingWindow.cs.meta +11 -0
- package/Editor/NativeDownloadHandler.cs +35 -0
- package/Editor/NativeDownloadHandler.cs.meta +11 -0
- package/Editor/QuickAddItem.cs +43 -0
- package/Editor/QuickAddItem.cs.meta +11 -0
- package/Editor/Resources/Cesium-128x128.png +0 -0
- package/Editor/Resources/Cesium-128x128.png.meta +98 -0
- package/Editor/Resources/Cesium-24x24.png +0 -0
- package/Editor/Resources/Cesium-24x24.png.meta +123 -0
- package/Editor/Resources/Cesium-64x64.png +0 -0
- package/Editor/Resources/Cesium-64x64.png.meta +98 -0
- package/Editor/Resources/Cesium-for-Unity-dark.png +0 -0
- package/Editor/Resources/Cesium-for-Unity-dark.png.meta +123 -0
- package/Editor/Resources/Cesium-for-Unity-light.png +0 -0
- package/Editor/Resources/Cesium-for-Unity-light.png.meta +123 -0
- package/Editor/Resources/Cesium-icon-16x16.png +0 -0
- package/Editor/Resources/Cesium-icon-16x16.png.meta +98 -0
- package/Editor/Resources/FontAwesome/attribution.txt +9 -0
- package/Editor/Resources/FontAwesome/attribution.txt.meta +7 -0
- package/Editor/Resources/FontAwesome/book-reader-solid.png +0 -0
- package/Editor/Resources/FontAwesome/book-reader-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/book-reader-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/book-reader-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/check-solid.png +0 -0
- package/Editor/Resources/FontAwesome/check-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/check-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/check-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/cloud-upload-alt-solid.png +0 -0
- package/Editor/Resources/FontAwesome/cloud-upload-alt-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/cloud-upload-alt-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/cloud-upload-alt-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/folder.png +0 -0
- package/Editor/Resources/FontAwesome/folder.png.meta +147 -0
- package/Editor/Resources/FontAwesome/folder.svg +5 -0
- package/Editor/Resources/FontAwesome/folder.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/hands-helping-solid.png +0 -0
- package/Editor/Resources/FontAwesome/hands-helping-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/hands-helping-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/hands-helping-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/key-solid.png +0 -0
- package/Editor/Resources/FontAwesome/key-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/key-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/key-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/plus-solid.png +0 -0
- package/Editor/Resources/FontAwesome/plus-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/plus-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/plus-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/sign-out-alt-solid.png +0 -0
- package/Editor/Resources/FontAwesome/sign-out-alt-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/sign-out-alt-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/sign-out-alt-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/sync-alt-solid.png +0 -0
- package/Editor/Resources/FontAwesome/sync-alt-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/sync-alt-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/sync-alt-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome/times-solid.png +0 -0
- package/Editor/Resources/FontAwesome/times-solid.png.meta +98 -0
- package/Editor/Resources/FontAwesome/times-solid.svg +1 -0
- package/Editor/Resources/FontAwesome/times-solid.svg.meta +7 -0
- package/Editor/Resources/FontAwesome.meta +8 -0
- package/Editor/Resources.meta +8 -0
- package/Editor/SelectIonTokenWindow.cs +249 -0
- package/Editor/SelectIonTokenWindow.cs.meta +11 -0
- package/Editor/arm64.meta +8 -0
- package/Editor/csc.rsp +1 -0
- package/Editor/csc.rsp.meta +7 -0
- package/Editor/libCesiumForUnityNative-Editor.so +0 -0
- package/Editor/libCesiumForUnityNative-Editor.so.meta +2 -0
- package/Editor/libCesiumForUnityNative-Runtime.so +0 -0
- package/Editor/libCesiumForUnityNative-Runtime.so.meta +2 -0
- package/Editor/x86_64.meta +8 -0
- package/Editor.meta +8 -0
- package/LICENSE +201 -0
- package/LICENSE.meta +7 -0
- package/Plugins/Standalone/libCesiumForUnityNative-Runtime.so +0 -0
- package/Plugins/Standalone/libCesiumForUnityNative-Runtime.so.meta +2 -0
- package/Plugins/Standalone.meta +8 -0
- package/Plugins.meta +8 -0
- package/README.md +39 -0
- package/README.md.meta +7 -0
- package/Reinterop.deps.json +172 -0
- package/Reinterop.deps.json.meta +7 -0
- package/Reinterop.dll +0 -0
- package/Reinterop.dll.meta +79 -0
- package/Runtime/Cesium3DTile.cs +37 -0
- package/Runtime/Cesium3DTile.cs.meta +11 -0
- package/Runtime/Cesium3DTileset.cs +788 -0
- package/Runtime/Cesium3DTileset.cs.meta +11 -0
- package/Runtime/Cesium3DTilesetLoadFailureDetails.cs +65 -0
- package/Runtime/Cesium3DTilesetLoadFailureDetails.cs.meta +11 -0
- package/Runtime/CesiumBackwardCompatibility.cs +163 -0
- package/Runtime/CesiumBackwardCompatibility.cs.meta +11 -0
- package/Runtime/CesiumBingMapsRasterOverlay.cs +72 -0
- package/Runtime/CesiumBingMapsRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumCameraController.cs +827 -0
- package/Runtime/CesiumCameraController.cs.meta +11 -0
- package/Runtime/CesiumCameraManager.cs +105 -0
- package/Runtime/CesiumCameraManager.cs.meta +11 -0
- package/Runtime/CesiumCartographicPolygon.cs +152 -0
- package/Runtime/CesiumCartographicPolygon.cs.meta +11 -0
- package/Runtime/CesiumCreditSystem.cs +343 -0
- package/Runtime/CesiumCreditSystem.cs.meta +11 -0
- package/Runtime/CesiumCreditSystemUI.cs +402 -0
- package/Runtime/CesiumCreditSystemUI.cs.meta +11 -0
- package/Runtime/CesiumDebugColorizeTilesRasterOverlay.cs +21 -0
- package/Runtime/CesiumDebugColorizeTilesRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumEllipsoid.cs +107 -0
- package/Runtime/CesiumEllipsoid.cs.meta +11 -0
- package/Runtime/CesiumFeature.cs +279 -0
- package/Runtime/CesiumFeature.cs.meta +11 -0
- package/Runtime/CesiumFeatureIdAttribute.cs +61 -0
- package/Runtime/CesiumFeatureIdAttribute.cs.meta +11 -0
- package/Runtime/CesiumFeatureIdSet.cs +165 -0
- package/Runtime/CesiumFeatureIdSet.cs.meta +11 -0
- package/Runtime/CesiumFeatureIdTexture.cs +68 -0
- package/Runtime/CesiumFeatureIdTexture.cs.meta +11 -0
- package/Runtime/CesiumFlyToController.cs +539 -0
- package/Runtime/CesiumFlyToController.cs.meta +11 -0
- package/Runtime/CesiumGeoreference.cs +628 -0
- package/Runtime/CesiumGeoreference.cs.meta +11 -0
- package/Runtime/CesiumGlobeAnchor.cs +664 -0
- package/Runtime/CesiumGlobeAnchor.cs.meta +11 -0
- package/Runtime/CesiumGlobeAnchorBackwardCompatibility0dot2dot0.cs +105 -0
- package/Runtime/CesiumGlobeAnchorBackwardCompatibility0dot2dot0.cs.meta +11 -0
- package/Runtime/CesiumIntMatN.cs +398 -0
- package/Runtime/CesiumIntMatN.cs.meta +11 -0
- package/Runtime/CesiumIntVecN.cs +525 -0
- package/Runtime/CesiumIntVecN.cs.meta +11 -0
- package/Runtime/CesiumIonRasterOverlay.cs +110 -0
- package/Runtime/CesiumIonRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumIonServer.cs +137 -0
- package/Runtime/CesiumIonServer.cs.meta +11 -0
- package/Runtime/CesiumMetadata.cs +33 -0
- package/Runtime/CesiumMetadata.cs.meta +11 -0
- package/Runtime/CesiumMetadataValue.cs +1764 -0
- package/Runtime/CesiumMetadataValue.cs.meta +11 -0
- package/Runtime/CesiumMetadataValueType.cs +203 -0
- package/Runtime/CesiumMetadataValueType.cs.meta +11 -0
- package/Runtime/CesiumModelMetadata.cs +26 -0
- package/Runtime/CesiumModelMetadata.cs.meta +11 -0
- package/Runtime/CesiumObjectPool.cs +74 -0
- package/Runtime/CesiumObjectPool.cs.meta +11 -0
- package/Runtime/CesiumObjectPools.cs +39 -0
- package/Runtime/CesiumObjectPools.cs.meta +11 -0
- package/Runtime/CesiumOriginShift.cs +146 -0
- package/Runtime/CesiumOriginShift.cs.meta +11 -0
- package/Runtime/CesiumPointCloudRenderer.cs +246 -0
- package/Runtime/CesiumPointCloudRenderer.cs.meta +11 -0
- package/Runtime/CesiumPointCloudShading.cs +76 -0
- package/Runtime/CesiumPointCloudShading.cs.meta +11 -0
- package/Runtime/CesiumPolygonRasterOverlay.cs +109 -0
- package/Runtime/CesiumPolygonRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumPrimitiveFeatures.cs +130 -0
- package/Runtime/CesiumPrimitiveFeatures.cs.meta +11 -0
- package/Runtime/CesiumPropertyArray.cs +64 -0
- package/Runtime/CesiumPropertyArray.cs.meta +11 -0
- package/Runtime/CesiumPropertyTable.cs +126 -0
- package/Runtime/CesiumPropertyTable.cs.meta +11 -0
- package/Runtime/CesiumPropertyTableProperty.cs +1734 -0
- package/Runtime/CesiumPropertyTableProperty.cs.meta +11 -0
- package/Runtime/CesiumRasterOverlay.cs +239 -0
- package/Runtime/CesiumRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumRasterOverlayLoadFailureDetails.cs +65 -0
- package/Runtime/CesiumRasterOverlayLoadFailureDetails.cs.meta +11 -0
- package/Runtime/CesiumRuntime.asmdef +32 -0
- package/Runtime/CesiumRuntime.asmdef.meta +7 -0
- package/Runtime/CesiumRuntime.cs +3 -0
- package/Runtime/CesiumRuntime.cs.meta +11 -0
- package/Runtime/CesiumRuntimeSettings.cs +188 -0
- package/Runtime/CesiumRuntimeSettings.cs.meta +11 -0
- package/Runtime/CesiumSampleHeightResult.cs +47 -0
- package/Runtime/CesiumSampleHeightResult.cs.meta +11 -0
- package/Runtime/CesiumSimplePlanarEllipsoidCurve.cs +93 -0
- package/Runtime/CesiumSimplePlanarEllipsoidCurve.cs.meta +11 -0
- package/Runtime/CesiumSubScene.cs +473 -0
- package/Runtime/CesiumSubScene.cs.meta +11 -0
- package/Runtime/CesiumTileExcluder.cs +47 -0
- package/Runtime/CesiumTileExcluder.cs.meta +11 -0
- package/Runtime/CesiumTileMapServiceRasterOverlay.cs +93 -0
- package/Runtime/CesiumTileMapServiceRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumWebMapServiceRasterOverlay.cs +129 -0
- package/Runtime/CesiumWebMapServiceRasterOverlay.cs.meta +11 -0
- package/Runtime/CesiumWebMapTileServiceRasterOverlay.cs +414 -0
- package/Runtime/CesiumWebMapTileServiceRasterOverlay.cs.meta +3 -0
- package/Runtime/CesiumWgs84Ellipsoid.cs +75 -0
- package/Runtime/CesiumWgs84Ellipsoid.cs.meta +11 -0
- package/Runtime/ConfigureReinterop.cs +926 -0
- package/Runtime/ConfigureReinterop.cs.meta +11 -0
- package/Runtime/Helpers.cs +122 -0
- package/Runtime/Helpers.cs.meta +11 -0
- package/Runtime/ICesiumRestartable.cs +17 -0
- package/Runtime/ICesiumRestartable.cs.meta +11 -0
- package/Runtime/NativeCoroutine.cs +28 -0
- package/Runtime/NativeCoroutine.cs.meta +11 -0
- package/Runtime/NativeDownloadHandler.cs +29 -0
- package/Runtime/NativeDownloadHandler.cs.meta +11 -0
- package/Runtime/Resources/CesiumCreditSystem.prefab +78 -0
- package/Runtime/Resources/CesiumCreditSystem.prefab.meta +7 -0
- package/Runtime/Resources/CesiumCreditSystemRuntimeTheme.tss +2 -0
- package/Runtime/Resources/CesiumCreditSystemRuntimeTheme.tss.meta +11 -0
- package/Runtime/Resources/CesiumCreditSystemUI.uxml +4 -0
- package/Runtime/Resources/CesiumCreditSystemUI.uxml.meta +10 -0
- package/Runtime/Resources/CesiumCreditSystemUIPanelSettings.asset +38 -0
- package/Runtime/Resources/CesiumCreditSystemUIPanelSettings.asset.meta +8 -0
- package/Runtime/Resources/CesiumDefaultTilesetMaterial.mat +232 -0
- package/Runtime/Resources/CesiumDefaultTilesetMaterial.mat.meta +8 -0
- package/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph +14271 -0
- package/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph.meta +10 -0
- package/Runtime/Resources/CesiumPointCloudShading.hlsl +156 -0
- package/Runtime/Resources/CesiumPointCloudShading.hlsl.meta +7 -0
- package/Runtime/Resources/CesiumPointCloudShadingMaterial.mat +125 -0
- package/Runtime/Resources/CesiumPointCloudShadingMaterial.mat.meta +8 -0
- package/Runtime/Resources/CesiumPointCloudShadingShader.shader +73 -0
- package/Runtime/Resources/CesiumPointCloudShadingShader.shader.meta +10 -0
- package/Runtime/Resources/CesiumRasterOverlay.shadersubgraph +2207 -0
- package/Runtime/Resources/CesiumRasterOverlay.shadersubgraph.meta +10 -0
- package/Runtime/Resources/CesiumSelectTexCoords.shadersubgraph +722 -0
- package/Runtime/Resources/CesiumSelectTexCoords.shadersubgraph.meta +10 -0
- package/Runtime/Resources/CesiumUnlitTilesetMaterial.mat +261 -0
- package/Runtime/Resources/CesiumUnlitTilesetMaterial.mat.meta +8 -0
- package/Runtime/Resources/CesiumUnlitTilesetShader.shadergraph +5873 -0
- package/Runtime/Resources/CesiumUnlitTilesetShader.shadergraph.meta +10 -0
- package/Runtime/Resources/DynamicCamera.prefab +253 -0
- package/Runtime/Resources/DynamicCamera.prefab.meta +7 -0
- package/Runtime/Resources/TransformTextureCoordinates.shadersubgraph +2171 -0
- package/Runtime/Resources/TransformTextureCoordinates.shadersubgraph.meta +10 -0
- package/Runtime/Resources/green1x1.png +0 -0
- package/Runtime/Resources/green1x1.png.meta +123 -0
- package/Runtime/Resources.meta +8 -0
- package/Runtime/TestGltfModel.cs +56 -0
- package/Runtime/TestGltfModel.cs.meta +11 -0
- package/Runtime/TestReinterop.cs +21 -0
- package/Runtime/TestReinterop.cs.meta +11 -0
- package/Runtime/UnityLifetime.cs +27 -0
- package/Runtime/UnityLifetime.cs.meta +11 -0
- package/Runtime/WaitForTask.cs +25 -0
- package/Runtime/WaitForTask.cs.meta +11 -0
- package/Runtime/csc.rsp +1 -0
- package/Runtime/csc.rsp.meta +7 -0
- package/Runtime.meta +8 -0
- package/ThirdParty.json +27 -0
- package/ThirdParty.json.meta +7 -0
- package/WGS84.asset +18 -0
- package/WGS84.asset.meta +8 -0
- package/package.json +29 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using Unity.Mathematics;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
#if ENABLE_INPUT_SYSTEM
|
|
7
|
+
using UnityEngine.InputSystem;
|
|
8
|
+
#if UNITY_IOS || UNITY_ANDROID
|
|
9
|
+
using EnhancedTouch = UnityEngine.InputSystem.EnhancedTouch;
|
|
10
|
+
#endif
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
namespace CesiumForUnity
|
|
14
|
+
{
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// A camera controller that can easily move around and view the globe while
|
|
17
|
+
/// maintaining a sensible orientation. As the camera moves across the horizon,
|
|
18
|
+
/// it automatically changes its own up direction such that the world always
|
|
19
|
+
/// looks right-side up.
|
|
20
|
+
/// </summary>
|
|
21
|
+
[RequireComponent(typeof(Camera))]
|
|
22
|
+
[DisallowMultipleComponent]
|
|
23
|
+
[AddComponentMenu("Cesium/Cesium Camera Controller")]
|
|
24
|
+
[IconAttribute("Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")]
|
|
25
|
+
public class CesiumCameraController : MonoBehaviour
|
|
26
|
+
{
|
|
27
|
+
#region User-editable properties
|
|
28
|
+
|
|
29
|
+
[SerializeField]
|
|
30
|
+
private bool _enableMovement = true;
|
|
31
|
+
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// Whether movement is enabled on this controller. Movement is
|
|
34
|
+
/// controlled using the W, A, S, D keys, as well as the Q and E
|
|
35
|
+
/// keys for vertical movement with respect to the globe.
|
|
36
|
+
/// </summary>
|
|
37
|
+
public bool enableMovement
|
|
38
|
+
{
|
|
39
|
+
get => this._enableMovement;
|
|
40
|
+
set
|
|
41
|
+
{
|
|
42
|
+
this._enableMovement = value;
|
|
43
|
+
this.ResetSpeed();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[SerializeField]
|
|
48
|
+
private bool _enableRotation = true;
|
|
49
|
+
|
|
50
|
+
/// <summary>
|
|
51
|
+
/// Whether rotation is enabled on this controller. Rotation is
|
|
52
|
+
/// controlled by movement of the mouse.
|
|
53
|
+
/// </summary>
|
|
54
|
+
public bool enableRotation
|
|
55
|
+
{
|
|
56
|
+
get => this._enableRotation;
|
|
57
|
+
set => this._enableRotation = value;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[SerializeField]
|
|
61
|
+
[Min(0.0f)]
|
|
62
|
+
private float _defaultMaximumSpeed = 100.0f;
|
|
63
|
+
|
|
64
|
+
/// <summary>
|
|
65
|
+
/// The maximum speed of this controller when dynamic speed is disabled.
|
|
66
|
+
/// If dynamic speed is enabled, this value will not be used.
|
|
67
|
+
/// </summary>
|
|
68
|
+
public float defaultMaximumSpeed
|
|
69
|
+
{
|
|
70
|
+
get => this._defaultMaximumSpeed;
|
|
71
|
+
set => this._defaultMaximumSpeed = Mathf.Max(value, 0.0f);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[SerializeField]
|
|
75
|
+
private bool _enableDynamicSpeed = true;
|
|
76
|
+
|
|
77
|
+
/// <summary>
|
|
78
|
+
/// Whether to enable dynamic speed on this controller. If enabled,
|
|
79
|
+
/// the controller's speed will change dynamically based on elevation
|
|
80
|
+
/// and other factors.
|
|
81
|
+
/// </summary>
|
|
82
|
+
public bool enableDynamicSpeed
|
|
83
|
+
{
|
|
84
|
+
get => this._enableDynamicSpeed;
|
|
85
|
+
set => this._enableDynamicSpeed = value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
[SerializeField]
|
|
89
|
+
[Min(0.0f)]
|
|
90
|
+
private float _dynamicSpeedMinHeight = 20.0f;
|
|
91
|
+
|
|
92
|
+
/// <summary>
|
|
93
|
+
/// The minimum height where dynamic speed starts to take effect.
|
|
94
|
+
/// Below this height, the speed will be set to the object's height
|
|
95
|
+
/// from the Earth, which makes it move slowly when it is right above a tileset.
|
|
96
|
+
/// </summary>
|
|
97
|
+
public float dynamicSpeedMinHeight
|
|
98
|
+
{
|
|
99
|
+
get => this._dynamicSpeedMinHeight;
|
|
100
|
+
set => this._dynamicSpeedMinHeight = Mathf.Max(value, 0.0f);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
[SerializeField]
|
|
104
|
+
private bool _enableDynamicClippingPlanes = true;
|
|
105
|
+
|
|
106
|
+
/// <summary>
|
|
107
|
+
/// Whether to dynamically adjust the camera's clipping planes so that
|
|
108
|
+
/// the globe will not be clipped from far away. Objects that are close
|
|
109
|
+
/// to the camera but far above the globe in space may not appear.
|
|
110
|
+
/// </summary>
|
|
111
|
+
public bool enableDynamicClippingPlanes
|
|
112
|
+
{
|
|
113
|
+
get => this._enableDynamicClippingPlanes;
|
|
114
|
+
set => this._enableDynamicClippingPlanes = value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[SerializeField]
|
|
118
|
+
[Min(0.0f)]
|
|
119
|
+
private float _dynamicClippingPlanesMinHeight = 10000.0f;
|
|
120
|
+
|
|
121
|
+
/// <summary>
|
|
122
|
+
/// The height to start dynamically adjusting the camera's clipping planes.
|
|
123
|
+
/// Below this height, the clipping planes will be set to their initial values.
|
|
124
|
+
/// </summary>
|
|
125
|
+
public float dynamicClippingPlanesMinHeight
|
|
126
|
+
{
|
|
127
|
+
get => this._dynamicClippingPlanesMinHeight;
|
|
128
|
+
set => this._dynamicClippingPlanesMinHeight = Mathf.Max(value, 0.0f);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#if ENABLE_INPUT_SYSTEM
|
|
132
|
+
[SerializeField]
|
|
133
|
+
private InputActionProperty _lookAction;
|
|
134
|
+
|
|
135
|
+
[SerializeField]
|
|
136
|
+
private InputActionProperty _moveAction;
|
|
137
|
+
|
|
138
|
+
[SerializeField]
|
|
139
|
+
private InputActionProperty _moveUpAction;
|
|
140
|
+
|
|
141
|
+
[SerializeField]
|
|
142
|
+
private InputActionProperty _speedChangeAction;
|
|
143
|
+
|
|
144
|
+
[SerializeField]
|
|
145
|
+
private InputActionProperty _speedResetAction;
|
|
146
|
+
|
|
147
|
+
[SerializeField]
|
|
148
|
+
private InputActionProperty _toggleDynamicSpeedAction;
|
|
149
|
+
#endif
|
|
150
|
+
|
|
151
|
+
#endregion
|
|
152
|
+
|
|
153
|
+
#region Private variables
|
|
154
|
+
|
|
155
|
+
private Camera _camera;
|
|
156
|
+
private float _initialNearClipPlane;
|
|
157
|
+
private float _initialFarClipPlane;
|
|
158
|
+
|
|
159
|
+
private CharacterController _controller;
|
|
160
|
+
private CesiumGeoreference _georeference;
|
|
161
|
+
private CesiumGlobeAnchor _globeAnchor;
|
|
162
|
+
|
|
163
|
+
private Vector3 _velocity = Vector3.zero;
|
|
164
|
+
private float _lookSpeed = 10.0f;
|
|
165
|
+
|
|
166
|
+
// These numbers are borrowed from Cesium for Unreal.
|
|
167
|
+
private float _acceleration = 20000.0f;
|
|
168
|
+
private float _deceleration = 9999999959.0f;
|
|
169
|
+
private float _maxRaycastDistance = 1000 * 1000; // 1000 km;
|
|
170
|
+
|
|
171
|
+
private float _maxSpeed = 100.0f; // Maximum speed with the speed multiplier applied.
|
|
172
|
+
private float _maxSpeedPreMultiplier = 0.0f; // Max speed without the multiplier applied.
|
|
173
|
+
private AnimationCurve _maxSpeedCurve;
|
|
174
|
+
|
|
175
|
+
private float _speedMultiplier = 1.0f;
|
|
176
|
+
private float _speedMultiplierIncrement = 1.5f;
|
|
177
|
+
|
|
178
|
+
// If the near clip gets too large, Unity will throw errors. Keeping it
|
|
179
|
+
// at this value works fine even when the far clip plane gets large.
|
|
180
|
+
private float _maximumNearClipPlane = 1000.0f;
|
|
181
|
+
private float _maximumFarClipPlane = 500000000.0f;
|
|
182
|
+
|
|
183
|
+
// The maximum ratio that the far clip plane is allowed to be larger
|
|
184
|
+
// than the near clip plane. The near clip plane is set so that this
|
|
185
|
+
// ratio is never exceeded.
|
|
186
|
+
private float _maximumNearToFarRatio = 100000.0f;
|
|
187
|
+
|
|
188
|
+
#endregion
|
|
189
|
+
|
|
190
|
+
#region Input configuration
|
|
191
|
+
|
|
192
|
+
#if ENABLE_INPUT_SYSTEM
|
|
193
|
+
private bool HasInputAction(InputActionProperty property)
|
|
194
|
+
{
|
|
195
|
+
return (property.action != null && property.action.bindings.Any()) || (property.reference != null);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void ConfigureInputs()
|
|
199
|
+
{
|
|
200
|
+
#if UNITY_IOS || UNITY_ANDROID
|
|
201
|
+
EnhancedTouch.EnhancedTouchSupport.Enable();
|
|
202
|
+
#endif
|
|
203
|
+
InputActionMap map = new InputActionMap("Cesium Camera Controller");
|
|
204
|
+
|
|
205
|
+
if (!HasInputAction(_lookAction))
|
|
206
|
+
{
|
|
207
|
+
InputAction newLookAction = map.AddAction("look", binding: "<Mouse>/delta");
|
|
208
|
+
newLookAction.AddBinding("<Gamepad>/rightStick").WithProcessor("scaleVector2(x=15, y=15)");
|
|
209
|
+
_lookAction = new InputActionProperty(newLookAction);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!HasInputAction(_moveAction))
|
|
213
|
+
{
|
|
214
|
+
InputAction newMoveAction = map.AddAction("move", binding: "<Gamepad>/leftStick");
|
|
215
|
+
newMoveAction.AddCompositeBinding("Dpad")
|
|
216
|
+
.With("Up", "<Keyboard>/w")
|
|
217
|
+
.With("Down", "<Keyboard>/s")
|
|
218
|
+
.With("Left", "<Keyboard>/a")
|
|
219
|
+
.With("Right", "<Keyboard>/d")
|
|
220
|
+
.With("Up", "<Keyboard>/upArrow")
|
|
221
|
+
.With("Down", "<Keyboard>/downArrow")
|
|
222
|
+
.With("Left", "<Keyboard>/leftArrow")
|
|
223
|
+
.With("Right", "<Keyboard>/rightArrow");
|
|
224
|
+
_moveAction = new InputActionProperty(newMoveAction);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!HasInputAction(_moveUpAction))
|
|
228
|
+
{
|
|
229
|
+
InputAction newMoveUpAction = map.AddAction("moveUp");
|
|
230
|
+
newMoveUpAction.AddCompositeBinding("Dpad")
|
|
231
|
+
.With("Up", "<Keyboard>/space")
|
|
232
|
+
.With("Down", "<Keyboard>/c")
|
|
233
|
+
.With("Up", "<Keyboard>/e")
|
|
234
|
+
.With("Down", "<Keyboard>/q")
|
|
235
|
+
.With("Up", "<Gamepad>/rightTrigger")
|
|
236
|
+
.With("Down", "<Gamepad>/leftTrigger");
|
|
237
|
+
_moveUpAction = new InputActionProperty(newMoveUpAction);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!HasInputAction(_speedChangeAction))
|
|
241
|
+
{
|
|
242
|
+
InputAction newSpeedChangeAction = map.AddAction("speedChange", binding: "<Mouse>/scroll");
|
|
243
|
+
newSpeedChangeAction.AddCompositeBinding("Dpad")
|
|
244
|
+
.With("Up", "<Gamepad>/rightShoulder")
|
|
245
|
+
.With("Down", "<Gamepad>/leftShoulder");
|
|
246
|
+
_speedChangeAction = new InputActionProperty(newSpeedChangeAction);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!HasInputAction(_speedResetAction))
|
|
250
|
+
{
|
|
251
|
+
InputAction newSpeedResetAction = map.AddAction("speedReset", binding: "<Mouse>/middleButton");
|
|
252
|
+
newSpeedResetAction.AddBinding("<Gamepad>/buttonNorth");
|
|
253
|
+
_speedResetAction = new InputActionProperty(newSpeedResetAction);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!HasInputAction(_toggleDynamicSpeedAction))
|
|
257
|
+
{
|
|
258
|
+
InputAction newToggleDynamicSpeedAction =
|
|
259
|
+
map.AddAction("toggleDynamicSpeed", binding: "<Keyboard>/g");
|
|
260
|
+
newToggleDynamicSpeedAction.AddBinding("<Gamepad>/buttonEast");
|
|
261
|
+
_toggleDynamicSpeedAction = new InputActionProperty(newToggleDynamicSpeedAction);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_moveAction.action.Enable();
|
|
265
|
+
_lookAction.action.Enable();
|
|
266
|
+
_moveUpAction.action.Enable();
|
|
267
|
+
_speedChangeAction.action.Enable();
|
|
268
|
+
_speedResetAction.action.Enable();
|
|
269
|
+
_toggleDynamicSpeedAction.action.Enable();
|
|
270
|
+
}
|
|
271
|
+
#endif
|
|
272
|
+
|
|
273
|
+
#endregion
|
|
274
|
+
|
|
275
|
+
#region Initialization
|
|
276
|
+
|
|
277
|
+
private void InitializeCamera()
|
|
278
|
+
{
|
|
279
|
+
this._camera = this.gameObject.GetComponent<Camera>();
|
|
280
|
+
this._initialNearClipPlane = this._camera.nearClipPlane;
|
|
281
|
+
this._initialFarClipPlane = this._camera.farClipPlane;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private void InitializeController()
|
|
285
|
+
{
|
|
286
|
+
if (this._globeAnchor.GetComponent<CharacterController>() != null)
|
|
287
|
+
{
|
|
288
|
+
Debug.LogWarning(
|
|
289
|
+
"A CharacterController component was manually " +
|
|
290
|
+
"added to the CesiumGlobeAnchor's game object. " +
|
|
291
|
+
"This may interfere with the CesiumCameraController's movement.");
|
|
292
|
+
|
|
293
|
+
this._controller = this._globeAnchor.GetComponent<CharacterController>();
|
|
294
|
+
}
|
|
295
|
+
else
|
|
296
|
+
{
|
|
297
|
+
this._controller = this._globeAnchor.gameObject.AddComponent<CharacterController>();
|
|
298
|
+
this._controller.hideFlags = HideFlags.HideInInspector;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
this._controller.radius = 1.0f;
|
|
302
|
+
this._controller.height = 1.0f;
|
|
303
|
+
this._controller.center = Vector3.zero;
|
|
304
|
+
this._controller.detectCollisions = true;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/// <summary>
|
|
308
|
+
/// Creates a curve to control the bounds of the maximum speed before it is
|
|
309
|
+
/// multiplied by the speed multiplier. This prevents the camera from achieving
|
|
310
|
+
/// an unreasonably low or high speed.
|
|
311
|
+
/// </summary>
|
|
312
|
+
private void CreateMaxSpeedCurve()
|
|
313
|
+
{
|
|
314
|
+
// This creates a curve that is linear between the first two keys,
|
|
315
|
+
// then smoothly interpolated between the last two keys.
|
|
316
|
+
Keyframe[] keyframes = {
|
|
317
|
+
new Keyframe(0.0f, 4.0f),
|
|
318
|
+
new Keyframe(10000000.0f, 10000000.0f),
|
|
319
|
+
new Keyframe(13000000.0f, 2000000.0f)
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
keyframes[0].weightedMode = WeightedMode.Out;
|
|
323
|
+
keyframes[0].outTangent = keyframes[1].value / keyframes[0].value;
|
|
324
|
+
keyframes[0].outWeight = 0.0f;
|
|
325
|
+
|
|
326
|
+
keyframes[1].weightedMode = WeightedMode.In;
|
|
327
|
+
keyframes[1].inWeight = 0.0f;
|
|
328
|
+
keyframes[1].inTangent = keyframes[1].value / keyframes[0].value;
|
|
329
|
+
keyframes[1].outTangent = 0.0f;
|
|
330
|
+
|
|
331
|
+
keyframes[2].inTangent = 0.0f;
|
|
332
|
+
|
|
333
|
+
this._maxSpeedCurve = new AnimationCurve(keyframes);
|
|
334
|
+
this._maxSpeedCurve.preWrapMode = WrapMode.ClampForever;
|
|
335
|
+
this._maxSpeedCurve.postWrapMode = WrapMode.ClampForever;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
void Awake()
|
|
339
|
+
{
|
|
340
|
+
this._georeference = this.gameObject.GetComponentInParent<CesiumGeoreference>();
|
|
341
|
+
if (this._georeference == null)
|
|
342
|
+
{
|
|
343
|
+
Debug.LogError(
|
|
344
|
+
"CesiumCameraController must be nested under a game object " +
|
|
345
|
+
"with a CesiumGeoreference.");
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this._globeAnchor = this.gameObject.GetComponentInParent<CesiumGlobeAnchor>();
|
|
349
|
+
if (this._globeAnchor == null)
|
|
350
|
+
{
|
|
351
|
+
Debug.LogError("CesiumCameraController must have a CesiumGlobeAnchor " +
|
|
352
|
+
"attached to itself or a parent");
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
CesiumOriginShift originShift = this._globeAnchor.GetComponent<CesiumOriginShift>();
|
|
356
|
+
if (originShift == null)
|
|
357
|
+
{
|
|
358
|
+
Debug.LogError("CesiumCameraController expects a CesiumOriginShift " +
|
|
359
|
+
$"on {this._globeAnchor?.name}, none found");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this.InitializeCamera();
|
|
363
|
+
this.InitializeController();
|
|
364
|
+
this.CreateMaxSpeedCurve();
|
|
365
|
+
|
|
366
|
+
#if ENABLE_INPUT_SYSTEM
|
|
367
|
+
this.ConfigureInputs();
|
|
368
|
+
#endif
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
#if UNITY_EDITOR
|
|
372
|
+
// Ensures required components are present in the editor.
|
|
373
|
+
private void Reset()
|
|
374
|
+
{
|
|
375
|
+
CesiumGlobeAnchor anchor = this.gameObject.GetComponentInParent<CesiumGlobeAnchor>();
|
|
376
|
+
if (anchor == null)
|
|
377
|
+
{
|
|
378
|
+
anchor = this.gameObject.AddComponent<CesiumGlobeAnchor>();
|
|
379
|
+
Debug.LogWarning("CesiumCameraController missing a CesiumGlobeAnchor - adding");
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
CesiumOriginShift origin = anchor.GetComponent<CesiumOriginShift>();
|
|
383
|
+
if (origin == null)
|
|
384
|
+
{
|
|
385
|
+
origin = anchor.gameObject.AddComponent<CesiumOriginShift>();
|
|
386
|
+
Debug.LogWarning("CesiumCameraController missing a CesiumOriginShift - adding");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
#endif
|
|
390
|
+
|
|
391
|
+
#endregion
|
|
392
|
+
|
|
393
|
+
#region Update
|
|
394
|
+
|
|
395
|
+
void FixedUpdate()
|
|
396
|
+
{
|
|
397
|
+
this.HandlePlayerInputs();
|
|
398
|
+
|
|
399
|
+
if (this._enableDynamicClippingPlanes)
|
|
400
|
+
{
|
|
401
|
+
this.UpdateClippingPlanes();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
#endregion
|
|
406
|
+
|
|
407
|
+
#region Raycasting helpers
|
|
408
|
+
|
|
409
|
+
private bool RaycastTowardsEarthCenter(out float hitDistance)
|
|
410
|
+
{
|
|
411
|
+
if (this._georeference == null)
|
|
412
|
+
{
|
|
413
|
+
hitDistance = 0.0f;
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
double3 center =
|
|
418
|
+
this._georeference.TransformEarthCenteredEarthFixedPositionToUnity(new double3(0.0));
|
|
419
|
+
|
|
420
|
+
RaycastHit hitInfo;
|
|
421
|
+
if (Physics.Linecast(this.transform.position, (float3)center, out hitInfo))
|
|
422
|
+
{
|
|
423
|
+
hitDistance = Vector3.Distance(this.transform.position, hitInfo.point);
|
|
424
|
+
return true;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
hitDistance = 0.0f;
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private bool RaycastAlongForwardVector(float raycastDistance, out float hitDistance)
|
|
432
|
+
{
|
|
433
|
+
RaycastHit hitInfo;
|
|
434
|
+
if (Physics.Raycast(
|
|
435
|
+
this.transform.position,
|
|
436
|
+
this.transform.forward,
|
|
437
|
+
out hitInfo,
|
|
438
|
+
raycastDistance))
|
|
439
|
+
{
|
|
440
|
+
hitDistance = Vector3.Distance(this.transform.position, hitInfo.point);
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
hitDistance = 0.0f;
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
#endregion
|
|
449
|
+
|
|
450
|
+
#region Player movement
|
|
451
|
+
|
|
452
|
+
private void HandlePlayerInputs()
|
|
453
|
+
{
|
|
454
|
+
#if ENABLE_INPUT_SYSTEM
|
|
455
|
+
Vector2 lookDelta;
|
|
456
|
+
Vector2 moveDelta;
|
|
457
|
+
lookDelta = _lookAction.action.ReadValue<Vector2>();
|
|
458
|
+
moveDelta = _moveAction.action.ReadValue<Vector2>();
|
|
459
|
+
|
|
460
|
+
#if UNITY_IOS || UNITY_ANDROID
|
|
461
|
+
bool handledMove = false;
|
|
462
|
+
bool handledLook = false;
|
|
463
|
+
|
|
464
|
+
foreach(var touch in EnhancedTouch.Touch.activeTouches)
|
|
465
|
+
{
|
|
466
|
+
if(touch.startScreenPosition.x < Screen.width / 2)
|
|
467
|
+
{
|
|
468
|
+
if(!handledMove)
|
|
469
|
+
{
|
|
470
|
+
handledMove = true;
|
|
471
|
+
moveDelta = touch.screenPosition - touch.startScreenPosition;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
else
|
|
475
|
+
{
|
|
476
|
+
if(!handledLook)
|
|
477
|
+
{
|
|
478
|
+
handledLook = true;
|
|
479
|
+
lookDelta = touch.delta;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
#endif
|
|
484
|
+
|
|
485
|
+
float inputRotateHorizontal = lookDelta.x;
|
|
486
|
+
float inputRotateVertical = lookDelta.y;
|
|
487
|
+
|
|
488
|
+
float inputForward = moveDelta.y;
|
|
489
|
+
float inputRight = moveDelta.x;
|
|
490
|
+
|
|
491
|
+
float inputUp = _moveUpAction.action.ReadValue<Vector2>().y;
|
|
492
|
+
|
|
493
|
+
float inputSpeedChange = _speedChangeAction.action.ReadValue<Vector2>().y;
|
|
494
|
+
bool inputSpeedReset = _speedResetAction.action.ReadValue<float>() > 0.5f;
|
|
495
|
+
|
|
496
|
+
bool toggleDynamicSpeed = _toggleDynamicSpeedAction.action.ReadValue<float>() > 0.5f;
|
|
497
|
+
#else
|
|
498
|
+
float inputRotateHorizontal = Input.GetAxis("Mouse X");
|
|
499
|
+
float inputRotateVertical = Input.GetAxis("Mouse Y");
|
|
500
|
+
|
|
501
|
+
float inputForward = Input.GetAxis("Vertical");
|
|
502
|
+
float inputRight = Input.GetAxis("Horizontal");
|
|
503
|
+
float inputUp = 0.0f;
|
|
504
|
+
|
|
505
|
+
if (Input.GetKeyDown("q"))
|
|
506
|
+
{
|
|
507
|
+
inputUp -= 1.0f;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (Input.GetKeyDown("e"))
|
|
511
|
+
{
|
|
512
|
+
inputUp += 1.0f;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
float inputSpeedChange = Input.GetAxis("Mouse ScrollWheel");
|
|
516
|
+
bool inputSpeedReset =
|
|
517
|
+
Input.GetMouseButtonDown(2) || Input.GetKeyDown("joystick button 3");
|
|
518
|
+
|
|
519
|
+
bool toggleDynamicSpeed =
|
|
520
|
+
Input.GetKeyDown("g") || Input.GetKeyDown("joystick button 1");
|
|
521
|
+
#endif
|
|
522
|
+
|
|
523
|
+
Vector3 movementInput = new Vector3(inputRight, inputUp, inputForward);
|
|
524
|
+
|
|
525
|
+
if (this._enableRotation)
|
|
526
|
+
{
|
|
527
|
+
this.Rotate(inputRotateHorizontal, inputRotateVertical);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
if (toggleDynamicSpeed)
|
|
531
|
+
{
|
|
532
|
+
this._enableDynamicSpeed = !this._enableDynamicSpeed;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (inputSpeedReset ||
|
|
536
|
+
(this._enableDynamicSpeed && movementInput == Vector3.zero))
|
|
537
|
+
{
|
|
538
|
+
this.ResetSpeedMultiplier();
|
|
539
|
+
}
|
|
540
|
+
else
|
|
541
|
+
{
|
|
542
|
+
this.HandleSpeedChange(inputSpeedChange);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (this._enableMovement)
|
|
546
|
+
{
|
|
547
|
+
this.Move(movementInput);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private void HandleSpeedChange(float speedChangeInput)
|
|
552
|
+
{
|
|
553
|
+
if (this._enableDynamicSpeed)
|
|
554
|
+
{
|
|
555
|
+
this.UpdateDynamicSpeed();
|
|
556
|
+
}
|
|
557
|
+
else
|
|
558
|
+
{
|
|
559
|
+
this.SetMaxSpeed(this._defaultMaximumSpeed);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (speedChangeInput != 0.0f)
|
|
563
|
+
{
|
|
564
|
+
if (speedChangeInput > 0.0f)
|
|
565
|
+
{
|
|
566
|
+
this._speedMultiplier *= this._speedMultiplierIncrement;
|
|
567
|
+
}
|
|
568
|
+
else
|
|
569
|
+
{
|
|
570
|
+
this._speedMultiplier /= this._speedMultiplierIncrement;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
float max = this._enableDynamicSpeed ? 50.0f : 50000.0f;
|
|
574
|
+
this._speedMultiplier = Mathf.Clamp(this._speedMultiplier, 0.1f, max);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/// <summary>
|
|
579
|
+
/// Rotate the camera with the specified amounts.
|
|
580
|
+
/// </summary>
|
|
581
|
+
/// <remarks>
|
|
582
|
+
/// Horizontal rotation (i.e. looking left or right) corresponds to rotation around the Y-axis.
|
|
583
|
+
/// Vertical rotation (i.e. looking up or down) corresponds to rotation around the X-axis.
|
|
584
|
+
/// </remarks>
|
|
585
|
+
/// <param name="horizontalRotation">The amount to rotate horizontally, i.e. around the Y-axis.</param>
|
|
586
|
+
/// <param name="verticalRotation">The amount to rotate vertically, i.e. around the X-axis.</param>
|
|
587
|
+
private void Rotate(float horizontalRotation, float verticalRotation)
|
|
588
|
+
{
|
|
589
|
+
if (horizontalRotation == 0.0f && verticalRotation == 0.0f)
|
|
590
|
+
{
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
float valueX = verticalRotation * this._lookSpeed * Time.fixedDeltaTime;
|
|
595
|
+
float valueY = horizontalRotation * this._lookSpeed * Time.fixedDeltaTime;
|
|
596
|
+
|
|
597
|
+
// Rotation around the X-axis occurs counter-clockwise, so the look range
|
|
598
|
+
// maps to [270, 360] degrees for the upper quarter-sphere of motion, and
|
|
599
|
+
// [0, 90] degrees for the lower. Euler angles only work with positive values,
|
|
600
|
+
// so map the [0, 90] range to [360, 450] so the entire range is [270, 450].
|
|
601
|
+
// This makes it easy to clamp the values.
|
|
602
|
+
float rotationX = this.transform.localEulerAngles.x;
|
|
603
|
+
if (rotationX <= 90.0f)
|
|
604
|
+
{
|
|
605
|
+
rotationX += 360.0f;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
float newRotationX = Mathf.Clamp(rotationX - valueX, 270.0f, 450.0f);
|
|
609
|
+
float newRotationY = this.transform.localEulerAngles.y + valueY;
|
|
610
|
+
this.transform.localRotation =
|
|
611
|
+
Quaternion.Euler(newRotationX, newRotationY, this.transform.localEulerAngles.z);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/// <summary>
|
|
615
|
+
/// Moves the controller with the given player input.
|
|
616
|
+
/// </summary>
|
|
617
|
+
/// <remarks>
|
|
618
|
+
/// The x-coordinate affects movement along the transform's right axis.
|
|
619
|
+
/// The y-coordinate affects movement along the georeferenced up axis.
|
|
620
|
+
/// The z-coordinate affects movement along the transform's forward axis.
|
|
621
|
+
/// </remarks>
|
|
622
|
+
/// <param name="movementInput">The player input.</param>
|
|
623
|
+
private void Move(Vector3 movementInput)
|
|
624
|
+
{
|
|
625
|
+
Vector3 inputDirection =
|
|
626
|
+
this.transform.right * movementInput.x + this.transform.forward * movementInput.z;
|
|
627
|
+
|
|
628
|
+
if (this._georeference != null)
|
|
629
|
+
{
|
|
630
|
+
double3 positionECEF = this._globeAnchor.positionGlobeFixed;
|
|
631
|
+
double3 upECEF = this._georeference.ellipsoid.GeodeticSurfaceNormal(positionECEF);
|
|
632
|
+
double3 upUnity =
|
|
633
|
+
this._georeference.TransformEarthCenteredEarthFixedDirectionToUnity(upECEF);
|
|
634
|
+
|
|
635
|
+
inputDirection = (float3)inputDirection + (float3)upUnity * movementInput.y;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if (inputDirection != Vector3.zero)
|
|
639
|
+
{
|
|
640
|
+
// If the controller was already moving, handle the direction change
|
|
641
|
+
// separately from the magnitude of the velocity.
|
|
642
|
+
if (this._velocity.magnitude > 0.0f)
|
|
643
|
+
{
|
|
644
|
+
Vector3 directionChange = inputDirection - this._velocity.normalized;
|
|
645
|
+
this._velocity +=
|
|
646
|
+
directionChange * this._velocity.magnitude * Time.fixedDeltaTime;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
this._velocity += inputDirection * this._acceleration * Time.fixedDeltaTime;
|
|
650
|
+
this._velocity = Vector3.ClampMagnitude(this._velocity, this._maxSpeed);
|
|
651
|
+
}
|
|
652
|
+
else
|
|
653
|
+
{
|
|
654
|
+
// Decelerate
|
|
655
|
+
float speed = Mathf.Max(
|
|
656
|
+
this._velocity.magnitude - this._deceleration * Time.fixedDeltaTime,
|
|
657
|
+
0.0f);
|
|
658
|
+
|
|
659
|
+
this._velocity = Vector3.ClampMagnitude(this._velocity, speed);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (this._velocity != Vector3.zero)
|
|
663
|
+
{
|
|
664
|
+
this._controller.Move(this._velocity * Time.fixedDeltaTime);
|
|
665
|
+
|
|
666
|
+
// Other controllers may disable detectTransformChanges to control their own
|
|
667
|
+
// movement, but the globe anchor should be synced even if detectTransformChanges
|
|
668
|
+
// is false.
|
|
669
|
+
if (!this._globeAnchor.detectTransformChanges)
|
|
670
|
+
{
|
|
671
|
+
this._globeAnchor.Sync();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
#endregion
|
|
677
|
+
|
|
678
|
+
#region Dynamic speed computation
|
|
679
|
+
|
|
680
|
+
/// <summary>
|
|
681
|
+
/// Gets the dynamic speed of the controller based on the camera's height from
|
|
682
|
+
/// the earth's center and its distance from objects along the forward vector.
|
|
683
|
+
/// </summary>
|
|
684
|
+
/// <param name="overrideSpeed">Whether the returned speed should override the
|
|
685
|
+
/// previous speed, even if the new value is lower.</param>
|
|
686
|
+
/// <param name="newSpeed">The new dynamic speed of the controller.</param>
|
|
687
|
+
/// <returns>Whether a valid speed value was found.</returns>
|
|
688
|
+
private bool GetDynamicSpeed(out bool overrideSpeed, out float newSpeed)
|
|
689
|
+
{
|
|
690
|
+
if (this._georeference == null)
|
|
691
|
+
{
|
|
692
|
+
overrideSpeed = false;
|
|
693
|
+
newSpeed = 0.0f;
|
|
694
|
+
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
float height, viewDistance;
|
|
699
|
+
|
|
700
|
+
// Raycast from the camera to the Earth's center and compute the distance.
|
|
701
|
+
// Ignore the result if the height is approximately 0.
|
|
702
|
+
if (!this.RaycastTowardsEarthCenter(out height) || height < 0.000001f)
|
|
703
|
+
{
|
|
704
|
+
overrideSpeed = false;
|
|
705
|
+
newSpeed = 0.0f;
|
|
706
|
+
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// Also ignore the result if the speed will increase or decrease by too much at once.
|
|
711
|
+
// This can be an issue when 3D tiles are loaded/unloaded from the scene.
|
|
712
|
+
if (this._maxSpeedPreMultiplier > 0.5f)
|
|
713
|
+
{
|
|
714
|
+
float heightToMaxSpeedRatio = height / this._maxSpeedPreMultiplier;
|
|
715
|
+
|
|
716
|
+
// The asymmetry of these ratios is intentional. When traversing tilesets
|
|
717
|
+
// with many height differences (e.g. a city with tall buildings), flying over
|
|
718
|
+
// taller geometry will cause the camera to slow down suddenly, and sometimes
|
|
719
|
+
// cause it to stutter.
|
|
720
|
+
if (heightToMaxSpeedRatio > 1000.0f || heightToMaxSpeedRatio < 0.01f)
|
|
721
|
+
{
|
|
722
|
+
overrideSpeed = false;
|
|
723
|
+
newSpeed = 0.0f;
|
|
724
|
+
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Raycast along the camera's view (forward) vector.
|
|
730
|
+
float raycastDistance =
|
|
731
|
+
Mathf.Clamp(this._maxSpeed * 3.0f, 0.0f, this._maxRaycastDistance);
|
|
732
|
+
|
|
733
|
+
// If the raycast does not hit, then only override speed if the height
|
|
734
|
+
// is lower than the maximum threshold. Otherwise, if both raycasts hit,
|
|
735
|
+
// always override the speed.
|
|
736
|
+
if (!this.RaycastAlongForwardVector(raycastDistance, out viewDistance) ||
|
|
737
|
+
viewDistance < 0.000001f)
|
|
738
|
+
{
|
|
739
|
+
overrideSpeed = height <= this._dynamicSpeedMinHeight;
|
|
740
|
+
}
|
|
741
|
+
else
|
|
742
|
+
{
|
|
743
|
+
overrideSpeed = true;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Set the speed to be the height of the camera from the Earth's center.
|
|
747
|
+
newSpeed = height;
|
|
748
|
+
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
private void ResetSpeedMultiplier()
|
|
753
|
+
{
|
|
754
|
+
this._speedMultiplier = 1.0f;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
private void SetMaxSpeed(float speed)
|
|
758
|
+
{
|
|
759
|
+
float actualSpeed = this._maxSpeedCurve.Evaluate(speed);
|
|
760
|
+
this._maxSpeed = this._speedMultiplier * actualSpeed;
|
|
761
|
+
this._acceleration =
|
|
762
|
+
Mathf.Clamp(this._maxSpeed * 5.0f, 20000.0f, 10000000.0f);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
private void UpdateDynamicSpeed()
|
|
766
|
+
{
|
|
767
|
+
bool overrideSpeed;
|
|
768
|
+
float newSpeed;
|
|
769
|
+
if (this.GetDynamicSpeed(out overrideSpeed, out newSpeed))
|
|
770
|
+
{
|
|
771
|
+
if (overrideSpeed || newSpeed >= this._maxSpeedPreMultiplier)
|
|
772
|
+
{
|
|
773
|
+
this._maxSpeedPreMultiplier = newSpeed;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
this.SetMaxSpeed(this._maxSpeedPreMultiplier);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
private void ResetSpeed()
|
|
781
|
+
{
|
|
782
|
+
this._maxSpeed = this._defaultMaximumSpeed;
|
|
783
|
+
this._maxSpeedPreMultiplier = 0.0f;
|
|
784
|
+
this.ResetSpeedMultiplier();
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
#endregion
|
|
788
|
+
|
|
789
|
+
#region Dynamic clipping plane adjustment
|
|
790
|
+
|
|
791
|
+
private void UpdateClippingPlanes()
|
|
792
|
+
{
|
|
793
|
+
if (this._camera == null)
|
|
794
|
+
{
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// Raycast from the camera to the Earth's center and compute the distance.
|
|
799
|
+
float height = 0.0f;
|
|
800
|
+
if (!this.RaycastTowardsEarthCenter(out height))
|
|
801
|
+
{
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
float nearClipPlane = this._initialNearClipPlane;
|
|
806
|
+
float farClipPlane = this._initialFarClipPlane;
|
|
807
|
+
|
|
808
|
+
if (height >= this._dynamicClippingPlanesMinHeight)
|
|
809
|
+
{
|
|
810
|
+
farClipPlane = height + (float)(2.0 * this._georeference.ellipsoid.GetMaximumRadius());
|
|
811
|
+
farClipPlane = Mathf.Min(farClipPlane, this._maximumFarClipPlane);
|
|
812
|
+
|
|
813
|
+
float farClipRatio = farClipPlane / this._maximumNearToFarRatio;
|
|
814
|
+
|
|
815
|
+
if (farClipRatio > nearClipPlane)
|
|
816
|
+
{
|
|
817
|
+
nearClipPlane = Mathf.Min(farClipRatio, this._maximumNearClipPlane);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
this._camera.nearClipPlane = nearClipPlane;
|
|
822
|
+
this._camera.farClipPlane = farClipPlane;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
#endregion
|
|
826
|
+
}
|
|
827
|
+
}
|