public static void UpdatePrefabCollection(PrefabCollection collection) { if (Application.isPlaying) { return; } //Reset index if prefab mode if (!PrefabCollectionUtility.IsPrefabMode() && collection.isPrefab) { collection.isPrefab = false; collection.selectedIndex = -1; if (collection.spawnedObject != null) { GameObject.DestroyImmediate(collection.spawnedObject); } } //Auto Selection if (collection.spawnedObject == null && collection.prefabs != null && collection.prefabs.Count > 0) { if (collection.selectedIndex == -1) { PrefabCollectionUtility.SelectInitial(collection); } else { PrefabCollectionUtility.Select(collection.selectedIndex, collection); } } //Detect no prefabs if (collection.spawnedObject == null && (collection.prefabs == null || collection.prefabs.Count == 0)) { GameObject.DestroyImmediate(collection.spawnedObject); collection.spawnedObject = null; collection.selectedIndex = -1; EditorUtility.SetDirty(collection); } //Out of range if (collection.selectedIndex != -1 && collection.selectedIndex >= collection.prefabs.Count) { PrefabCollectionUtility.Select(collection.prefabs.Count - 1, collection); } else { //Detect change in current prefab bool isSamePrefab = true; if (collection.spawnedObject != null) { isSamePrefab = PrefabUtility.GetCorrespondingObjectFromSource(collection.spawnedObject) == collection.prefabs[collection.selectedIndex]; } if (collection.selectedIndex != -1 && !isSamePrefab) { PrefabCollectionUtility.Select(collection.selectedIndex, collection); } } }
public override void Step(int step) { PrefabCollectionUtility.Select(selectedIndex + step, this); }