Unity editor script to create prefab from selected game object.
This file contains 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
|/// Creates a prefab from a selected game object.|
|const string menuName = "GameObject/Create Prefab From Selected";|
|/// Adds a menu named "Create Prefab From Selected" to the GameObject menu.|
|static void CreatePrefabMenu ()|
|var go = Selection.activeGameObject;|
|var prefab = EditorUtility.CreateEmptyPrefab("Assets/" + go.name + ".prefab");|
|/// Validates the menu.|
|/// The item will be disabled if no game object is selected.|
|/// <returns>True if the menu item is valid.</returns>|
|static bool ValidateCreatePrefabMenu ()|
|return Selection.activeGameObject != null;|
Nov 20, 2014
@jarequo: Indeed, this is redundant now. I'm unsure if
PrefabUtility.CreatePrefab didn't exist when I wrote this script, or if I simply missed it.
Oct 17, 2016
it didn't exist when you wrote this article.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment