26 private static Mesh _previewSphereMesh;
30 private double _activationRadius = 1000;
41 get => this._activationRadius;
44 this._activationRadius = value;
49 private bool _showActivationRadius =
true;
56 get => this._showActivationRadius;
57 set => this._showActivationRadius = value;
70 get => this._originAuthority;
73 this._originAuthority = value;
79 private double _latitude = 39.736401;
89 get => this._latitude;
92 this._latitude = value;
98 private double _longitude = -105.25737;
108 get => this._longitude;
111 this._longitude = value;
117 private double _height = 2250.0;
132 this._height = value;
138 private double _ecefX = 6378137.0;
157 private double _ecefY = 0.0;
176 private double _ecefZ = 0.0;
208 private double3 _oldParentCoordinates = double3.zero;
254 private void CopyParentCoordinates()
256 this._longitude = this._parentGeoreference.
longitude;
257 this._latitude = this._parentGeoreference.
latitude;
258 this._height = this._parentGeoreference.
height;
260 this._ecefX = this._parentGeoreference.
ecefX;
261 this._ecefY = this._parentGeoreference.
ecefY;
262 this._ecefZ = this._parentGeoreference.
ecefZ;
265 private void DetachFromParentIfNeeded()
267 if (this._parentGeoreference !=
null)
269 this._parentGeoreference.changed -= this.OnParentChanged;
270 this._parentGeoreference =
null;
274 private void UpdateParentReference()
276 DetachFromParentIfNeeded();
278 this._parentGeoreference = this.GetComponentInParent<CesiumGeoreference>();
280 if (this._parentGeoreference !=
null)
283 this._parentGeoreference.changed += this.OnParentChanged;
292 private void OnValidate()
305 this.UpdateParentReference();
309 if (this._parentGeoreference !=
null)
320 this.CopyParentCoordinates();
325 private void OnEnable()
327 this.UpdateParentReference();
330 if (this._parentGeoreference ==
null)
331 throw new InvalidOperationException(
332 "CesiumSubScene is not nested inside a game object with a CesiumGeoreference.");
335 CesiumSubScene[] subscenes = this._parentGeoreference.GetComponentsInChildren<CesiumSubScene>();
336 foreach (CesiumSubScene scene
in subscenes)
340 scene.gameObject.SetActive(
false);
345 this._oldParentOriginAuthority = this._parentGeoreference.
originAuthority;
348 this._oldParentCoordinates =
new double3(this._parentGeoreference.
ecefX,
this._parentGeoreference.ecefY,
this._parentGeoreference.ecefZ);
352 this._oldParentCoordinates =
new double3(this._parentGeoreference.
longitude,
this._parentGeoreference.latitude,
this._parentGeoreference.height);
359 private void OnParentChanged()
361 if (!this.isActiveAndEnabled)
364 this.UpdateParentReference();
367 if (this._parentGeoreference ==
null)
369 throw new InvalidOperationException(
370 "CesiumSubScene should have been nested inside a game object with a CesiumGeoreference.");
375 this.CopyParentCoordinates();
378 private void OnDisable()
380 DetachFromParentIfNeeded();
383 private void OnDestroy()
385 DetachFromParentIfNeeded();
388 private void UpdateOtherCoordinates()
390 if(this._parentGeoreference ==
null)
392 this.UpdateParentReference();
394 if(this._parentGeoreference ==
null)
396 throw new InvalidOperationException(
"CesiumSubScene should have been nested inside a game object with a CesiumGeoreference.");
408 this._ecefX = ecef.x;
409 this._ecefY = ecef.y;
410 this._ecefZ = ecef.z;
421 this._longitude = llh.x;
422 this._latitude = llh.y;
423 this._height = llh.z;
433 UpdateOtherCoordinates();
435 if (this.isActiveAndEnabled)
437 this.UpdateParentReference();
439 if (this._parentGeoreference ==
null)
440 throw new InvalidOperationException(
"CesiumSubScene is not nested inside a game object with a CesiumGeoreference.");
456 private void OnDrawGizmos()
458 if (this._showActivationRadius)
462 if (_previewSphereMesh ==
null)
464 _previewSphereMesh = Resources.GetBuiltinResource<Mesh>(
"Sphere.fbx");
467 Gizmos.color = Color.blue;
468 Gizmos.DrawWireMesh(_previewSphereMesh, this.transform.position, Quaternion.identity, (float3)
new double3(this._activationRadius, this._activationRadius, this._activationRadius));