Last active
May 13, 2016 11:05
-
-
Save paulhayes/027ebfba95e6fe14c9ee70648e75ab10 to your computer and use it in GitHub Desktop.
Allows a user to save a prefab in play mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections; | |
| public class SavePrefab : MonoBehaviour { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| using System.Collections; | |
| [CustomEditor(typeof(SavePrefab))] | |
| public class SavePrefabEditor : Editor { | |
| public override void OnInspectorGUI(){ | |
| SavePrefab saveTarget = target as SavePrefab; | |
| if( GUILayout.Button("Save") ){ | |
| Object parentObject = PrefabUtility.GetPrefabParent(saveTarget.gameObject); | |
| if( parentObject == null ){ | |
| Debug.LogWarningFormat("No prefab found for GameObject {0}",saveTarget.gameObject.name); | |
| return; | |
| } | |
| PrefabUtility.ReplacePrefab( saveTarget.gameObject, parentObject ); | |
| AssetDatabase.SaveAssets(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment