// Instantiate a nested prefab private void InstantiateNestedPrefab(NestedPrefabData a_rNestedPrefabData) { // Instantiate the prefab GameObject rNestedPrefabInstantiated = PrefabUtility.InstantiatePrefab(a_rNestedPrefabData.Prefab) as GameObject; if (rNestedPrefabInstantiated != null) { // Load its property modifications a_rNestedPrefabData.LoadModifications(rNestedPrefabInstantiated); // Change the parent without changing the local transform information NestedPrefabUtility.ChangeParentAndKeepSameLocalTransform(rNestedPrefabInstantiated.transform, gameObject.transform); } }
// Reload the nested prefab data (either by its reloading instantiator prefab data or revert to prefab resource) private void ReloadNestedPrefabData(NestedPrefabData a_rNestedPrefabData) { // If there is a nested prefab data if (a_rNestedPrefabData != null) { // Reload property modification a_rNestedPrefabData.LoadModifications(gameObject); return; } // If it doesn't has a instantiator revert to resource PrefabUtility.RevertPrefabInstance(gameObject); }
// Try to reinstantiate a hierarchical prefab public bool TryToReloadData(HierarchicalPrefabInstance a_rHierarchicalPrefabInstance) { // Try to find a prefab data corresponding to the hierarchical prefab NestedPrefabData rNestedPrefabData = TryGrabNestedPrefabData(a_rHierarchicalPrefabInstance.gameObject); if (rNestedPrefabData != null) { // Load its property modifications rNestedPrefabData.LoadModifications(a_rHierarchicalPrefabInstance.gameObject); return(true); } return(false); }