-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modify CesiumSubScene to use parent CesiumGeoreference's coordinates when added in-editor. #391
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @azrogers ! I hadn't realized that OnEnable
runs before Reset
, so I can see how this became more complicated than anticipated.
Still I wonder if this can be simplified (ish)? Instead of storing the parent coordinates, is it possible to have a bool
variable called isInitialized
? (name can be improved if possible)
Then in OnEnable
, you could have this code towards the end
if (Application.isPlaying)
// In play mode, the subscene coordinates should be used as-is.
this.isInitialized = true;
if (isInitialized) {
this.UpdateOrigin()
}
Then Reset
could look something like this:
this.UpdateParentReference();
if(this._parentGeoreference != null) {
// adopt parent georeference coordinates here
isInitialized = true;
}
How does that sound? If it helps with clarity, we could potentially surround these segments with #if EDITOR
statements.
I confirmed that this implementation works otherwise. I just think the internal state management is a little confusing.
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 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azrogers I left a few more comments, just for code clarity + organization.
@j9liu Updated review based on feedback - let me know if I missed anything! |
Looks great, thanks @azrogers ! |
Fixes #343.
When
CesiumSubScene::OnEnable
is called, it sets the coordinates of the parentCesiumGeoreference
to the coordinates it has set. This means when adding a newCesiumSubScene
component as a child of an existingCesiumGeoreference
, it would reset the coordinates of the parent to the default coordinates. This change uses theReset
event to restore the georeference's original coordinates without changing the behavior outside of the editor.