public static void Select(Object obj)
{
// I'm sure this function can be written with fewer lines of code, but we want to keep this clearly layouted
GameObject newGO = obj as GameObject;
MBObject newObj = (newGO) ? newGO.GetComponent<MBObject>() : obj != null ? (MBObject)obj : null;
// Null Prefabs
if (newObj && PrefabUtility.GetPrefabType(newObj) == PrefabType.Prefab)
newObj = null;
if (newObj == SelectedObject) return; // nothing changed, exit!
MBParticleSystem newSys = (newObj) ? newObj.ParticleSystem : null;
bool InitAll = true;
bool InitEM = false;
// Case I: Leaving a system to a non MB object
if (SelectedParticleSystem && !newSys) {
if (!Application.isPlaying)
SelectedParticleSystem.Halt();
// detach hook
EditorApplication.update -= EditorUpdate;
//EditorApplication.playmodeStateChanged -= OnPlaymodeChange;
} else
// Case II: Entering a system from a non MB object
if (!SelectedParticleSystem && newSys) {
if (!Application.isPlaying){
// attach hook
EditorApplication.update -= EditorUpdate;
EditorApplication.update += EditorUpdate;
EditorApplication.playmodeStateChanged -= OnPlaymodeChange;
EditorApplication.playmodeStateChanged += OnPlaymodeChange;
// Load System
newSys.mbReloadHierarchy();
newSys.GenerateTextureMap(true);
// Initialize Timing
mRealTime = (float)EditorApplication.timeSinceStartup;
LastEditorFrameTime = mRealTime;
newSys.GlobalTime = mRealTime;
}
} else
// Case III: Switching to another system
if (SelectedParticleSystem && newSys && SelectedParticleSystem != newSys) {
if (!Application.isPlaying)
SelectedParticleSystem.Halt();
// Load System
newSys.mbReloadHierarchy();
newSys.GenerateTextureMap(true);
// Initialize Timing
newSys.GlobalTime = mRealTime;
}
else {
// CASE IV: Selecting within system
InitAll = false;
InitEM = (newObj is MBEmitter || (newObj is MBParameter && newObj.Parent != SelectedEmitter));
}
SelectedObject = newObj;
if (_instance) {
if (InitAll)
_instance.Initialize();
if (InitEM)
_instance.InitializeEmitter();
if (_instance.mAutoSelect && SelectedObject)
Selection.activeGameObject = SelectedObject.gameObject;
if (SelectedObject is MBParameter)
_instance.SelectParameterTab();
RepaintEditor(false);
}
}