// Revert to the hierarchical prefab public void ApplyChangesToHierarchicalPrefab() { // Try to get the prefab parent GameObject rHierarchicalPrefab = HierarchicalPrefab; if(rHierarchicalPrefab != null) { // Get the prefab path string oPrefabPath = AssetDatabase.GetAssetPath(rHierarchicalPrefab); // Save the prefab at this path if(NestedPrefabEditorUtility.SaveAsHierarchicalPrefab(gameObject, oPrefabPath)) { // Ensure the disconnection PrefabUtility.DisconnectPrefabInstance(gameObject); // Notify the other instances NestedPrefabEditorUtility.NotifyInstancesOfHierarchicalPrefabUpdate(m_rPrefabObject, this); } } }
// Save as button action private void SaveAsButtonAction() { // Chose path string oChosenPath = EditorUtility.SaveFilePanel( "Save as ...", GetLastFilePath(), m_rSelectedGameObject.name + ".prefab", "prefab"); // If a path has been selected if (oChosenPath.Length != 0) { // Check if the path is in the asset folder if (oChosenPath.Contains(Application.dataPath)) { string oAssetPath = Application.dataPath; oAssetPath = oAssetPath.Replace("Assets", ""); string oLocalChosenPath = oChosenPath; oLocalChosenPath = oLocalChosenPath.Replace(oAssetPath, ""); // Save if (NestedPrefabEditorUtility.SaveAsHierarchicalPrefab(m_rSelectedGameObject, oLocalChosenPath)) { // Ensure the disconnection PrefabUtility.DisconnectPrefabInstance(m_rSelectedGameObject); // Notify the other instances NestedPrefabEditorUtility.NotifyInstancesOfHierarchicalPrefabUpdate(m_rSelectedGameObject.GetComponent <HierarchicalPrefabInstance>().PrefabObject); } // Remember the chosen path SetLastFilePath(oChosenPath); } else { Debug.LogError("Please choose an emplacement included in the Asset folder."); } } }