I’m not sure my title makes much sense but I couldn’t find a better one…
My problem:
I have code which runs constantly in OnGUI() for an editor window:
GameObject fbx, model, prefab;
bool childUpdateOnly = false;
bool dontCheck = false;
void OnGUI()
{
// Create selection field to allow the selection of the object to process
model = (GameObject)EditorGUILayout.ObjectField( "Select FBX Object", fbx, typeof( GameObject ), true );
oldPrefab = (GameObject)EditorGUILayout.ObjectField( "Select Prefab To Update", oldPrefab, typeof( GameObject ), false );
childUpdateOnly = (bool)EditorGUILayout.BeginToggleGroup( "Child Update Only", childUpdateOnly );
if( model && prefab )
{
if( model.name == prefab.name && dontCheck == false )
{
childUpdateOnly == false;
}
}
}
As you can see in the code above, ‘childUpdateOnly’ gets set on every update tick so that if the user removes a GameObject from one of the ObjectFields, it automatically gets set to the correct state.
But I also want to be able to check/un-check it manually by clicking the toggle field in the EditorWindow, problem is, since the code checks for the ObjectFields state on every tick, ‘childUpdateOnly’ gets set back automatically so I can’t manually check/un-check it.
How can I get around this problem? Is there a way to maybe use the Event system, with something like this:
if( Event.current.type == EventType.MouseClickUp )
{
childUpdateOnly = !childUpdateOnly;
dontCheck = true;
}
But then how do I set ‘dontCheck = true’ if the user removes or adds a GameObject from one of the ObjectFields?
I hope I’m explaining my problem clearly enough, if not I’m sorry
Any help will be greatly appreciated as always, thanks for your time guys.
Stephane