44 set => _distance = value;
49 [Tooltip(
"The maximum distance between the origin of the Unity coordinate system and " +
50 "the game object to which this component is attached. When this distance is" +
51 "exceeded, the CesiumGeoreference origin is shifted to bring it close to the " +
53 "When the value of this property is 0.0, the origin is shifted continuously.")]
54 private double _distance = 0.0;
60 if (georeference ==
null)
62 Debug.LogWarning(
"CesiumOriginShift is doing nothing because it is not nested inside a game object with a CesiumGeoreference component.");
66 CesiumGlobeAnchor anchor = this.GetComponent<CesiumGlobeAnchor>();
69 if (anchor ==
null || !anchor.isActiveAndEnabled)
71 Debug.LogWarning(
"CesiumOriginShift is doing nothing because its CesiumGlobeAnchor component is missing or disabled.");
75 this.UpdateFromEcef(georeference, anchor.positionGlobeFixed);
78 private List<CesiumSubScene> _sublevelsScratch =
new List<CesiumSubScene>();
80 private void UpdateFromEcef(CesiumGeoreference georeference, double3 ecef)
82 CesiumSubScene closestLevel =
null;
83 double distanceSquaredToClosest =
double.MaxValue;
86 georeference.GetComponentsInChildren<CesiumSubScene>(
true, this._sublevelsScratch);
87 foreach (CesiumSubScene level
in this._sublevelsScratch)
90 double x = level.ecefX - ecef.x;
91 double y = level.ecefY - ecef.y;
92 double z = level.ecefZ - ecef.z;
93 double distanceSquared = x * x + y * y + z * z;
94 if (distanceSquared > level.activationRadius * level.activationRadius)
98 if (closestLevel ==
null || distanceSquared < distanceSquaredToClosest)
100 closestLevel = level;
101 distanceSquaredToClosest = distanceSquared;
105 if (closestLevel !=
null)
107 if (!closestLevel.isActiveAndEnabled)
110 closestLevel.gameObject.SetActive(
true);
111 closestLevel.enabled =
true;
113 Physics.SyncTransforms();
118 bool deactivatedAnySublevel =
false;
121 foreach (CesiumSubScene level
in this._sublevelsScratch)
123 if (level.isActiveAndEnabled)
125 level.gameObject.SetActive(
false);
126 deactivatedAnySublevel =
true;
130 double distance = math.length(
new double3(georeference.ecefX, georeference.ecefY, georeference.ecefZ) - ecef);
135 georeference.SetOriginEarthCenteredEarthFixed(ecef.x, ecef.y, ecef.z);
137 Physics.SyncTransforms();
139 else if (deactivatedAnySublevel)
141 Physics.SyncTransforms();