CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
358 stars 83 forks source link

Modify CesiumSubScene to use parent CesiumGeoreference's coordinates when added in-editor. #391

Closed azrogers closed 9 months ago

azrogers commented 10 months ago

Fixes #343.

When CesiumSubScene::OnEnable is called, it sets the coordinates of the parent CesiumGeoreference to the coordinates it has set. This means when adding a new CesiumSubScene component as a child of an existing CesiumGeoreference, it would reset the coordinates of the parent to the default coordinates. This change uses the Reset event to restore the georeference's original coordinates without changing the behavior outside of the editor.

j9liu commented 9 months ago

Actually, the solution in my previous comment fails to account for existing sub-scenes when they're enabled in the editor. 🙃 And I don't know if the call is to make that isInitialized variable [Serialized]. So ignore what I wrote. I think the solution you found is fine; I'd like to add a bit of clarity to the comment but I'll put a suggestion tomorrow morning.

Just because it was driving me crazy, I looked up if there was an event for any time a component was added in the editor. I found that the ObjectFactory class exists and has a componentWasAdded event on it, but I have no idea when this event is called in relation to the component's event cycle. It's probably not worth exploring at this point.

azrogers commented 9 months ago

@j9liu Updated review based on feedback - let me know if I missed anything!

j9liu commented 9 months ago

Looks great, thanks @azrogers !