Cesium for Unity 1.15.2
Loading...
Searching...
No Matches
CesiumGlobeAnchorBackwardCompatibility0dot2dot0.cs
Go to the documentation of this file.
1using Unity.Mathematics;
2using UnityEditor;
3using UnityEngine;
4using UnityEngine.Serialization;
5
6namespace CesiumForUnity
7{
8 [ExecuteInEditMode]
9 [AddComponentMenu("")]
10 [DefaultExecutionOrder(-1000000)]
11 internal class CesiumGlobeAnchorBackwardCompatibility0dot2dot0 : CesiumGlobeAnchor, IBackwardCompatibilityComponent<CesiumGlobeAnchor>
12 {
13 public enum CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2
14 {
15 None,
18 UnityCoordinates
19 }
20
21 [FormerlySerializedAs("_adjustOrientationForGlobeWhenMoving")]
22 public bool _adjustOrientationForGlobeWhenMoving0dot2dot0 = false;
23 [FormerlySerializedAs("_detectTransformChanges")]
24 public bool _detectTransformChanges0dot2dot0 = false;
25 [FormerlySerializedAs("_positionAuthority")]
26 public CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2 _positionAuthority0dot2dot0 = CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2.None;
27 [FormerlySerializedAs("_latitude")]
28 public double _latitude0dot2dot0 = 0.0;
29 [FormerlySerializedAs("_longitude")]
30 public double _longitude0dot2dot0 = 0.0;
31 [FormerlySerializedAs("_height")]
32 public double _height0dot2dot0 = 0.0;
33 [FormerlySerializedAs("_ecefX")]
34 public double _ecefX0dot2dot0 = 0.0;
35 [FormerlySerializedAs("_ecefY")]
36 public double _ecefY0dot2dot0 = 0.0;
37 [FormerlySerializedAs("_ecefZ")]
38 public double _ecefZ0dot2dot0 = 0.0;
39 [FormerlySerializedAs("_unityX")]
40 public double _unityX0dot2dot0 = 0.0;
41 [FormerlySerializedAs("_unityY")]
42 public double _unityY0dot2dot0 = 0.0;
43 [FormerlySerializedAs("_unityZ")]
44 public double _unityZ0dot2dot0 = 0.0;
45
46#if UNITY_EDITOR
47 [CustomEditor(typeof(CesiumGlobeAnchorBackwardCompatibility0dot2dot0))]
48 internal class CesiumGlobeAnchorBackwardCompatibility0dot2dot0Editor : Editor
49 {
50 public override void OnInspectorGUI()
51 {
52 if (GUILayout.Button("Upgrade"))
53 {
54 CesiumGlobeAnchorBackwardCompatibility0dot2dot0 o = (CesiumGlobeAnchorBackwardCompatibility0dot2dot0)this.target;
55 CesiumBackwardCompatibility<CesiumGlobeAnchor>.Upgrade(o);
56 }
57 }
58 }
59
60 void OnEnable()
61 {
62 CesiumBackwardCompatibility<CesiumGlobeAnchor>.Upgrade(this);
63 }
64#endif
65
66 public string VersionToBeUpgraded => "v0.2.0";
67
68 public void Upgrade(GameObject gameObject, CesiumGlobeAnchor upgraded)
69 {
70 // Temporarily disable orientation adjustment so that we can set the position without
71 // risking rotating the object.
72 upgraded.adjustOrientationForGlobeWhenMoving = false;
73 upgraded.detectTransformChanges = false;
74
75 switch (this._positionAuthority0dot2dot0)
76 {
77 case CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2.None:
78 // This shouldn't happen, but if it does, just leave the position at the default.
79 break;
80 case CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2.LongitudeLatitudeHeight:
81 upgraded.longitudeLatitudeHeight = new double3(this._longitude0dot2dot0, this._latitude0dot2dot0, this._height0dot2dot0);
82 break;
83 case CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2.EarthCenteredEarthFixed:
84 upgraded.positionGlobeFixed = new double3(this._ecefX0dot2dot0, this._ecefY0dot2dot0, this._ecefZ0dot2dot0);
85 break;
86 case CesiumGlobeAnchorPositionAuthorityBackwardCompatibility0dot1dot2.UnityCoordinates:
87 // Any backward compatibility for CesiumGeoreference must have a more negative
88 // DefaultExecutionOrder so that the real CesiumGeoreference is created first.
89 // If this component is not nested inside a CesiumGeoreference, converting Unity coordinates
90 // to ECEF is impossible, so just keep the default position.
91 CesiumGeoreference georeference = this.GetComponentInParent<CesiumGeoreference>();
92 if (georeference != null)
93 {
94 georeference.Initialize();
95 double3 ecef = georeference.TransformUnityPositionToEarthCenteredEarthFixed(new double3(this._unityX0dot2dot0, this._unityY0dot2dot0, this._unityZ0dot2dot0));
96 upgraded.positionGlobeFixed = ecef;
97 }
98 break;
99 }
100
101 upgraded.adjustOrientationForGlobeWhenMoving = this._adjustOrientationForGlobeWhenMoving0dot2dot0;
102 upgraded.detectTransformChanges = this._detectTransformChanges0dot2dot0;
103 }
104 }
105}
@ EarthCenteredEarthFixed
The CesiumGeoreference.ecefX, CesiumGeoreference.ecefY, and CesiumGeoreference.ecefZ properties autho...
@ LongitudeLatitudeHeight
The CesiumGeoreference.longitude, CesiumGeoreference.latitude, and CesiumGeoreference....