Created
March 27, 2023 08:57
-
-
Save Denchyaknow/f070c728b61da26a533ead07ba7bff8a to your computer and use it in GitHub Desktop.
HowTo_CustomInspector_Prefabbing
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
//Creating a Prefab from Custom Inspector To create a Prefab from a custom inspector, you can use the PrefabUtility.CreatePrefab method. Here's an example of how you can use this method: | |
using UnityEditor; | |
using UnityEngine; | |
public class MyCustomEditor : EditorWindow | |
{ | |
[MenuItem("MyTools/CreatePrefab")] | |
static void CreatePrefab() | |
{ | |
// Get the selected object in the editor | |
GameObject selectedObject = Selection.activeGameObject; | |
// Create a new Prefab from the selected object | |
Object prefab = PrefabUtility.CreatePrefab("Assets/Prefabs/" + selectedObject.name + ".prefab", selectedObject); | |
// Select the new Prefab in the editor | |
Selection.activeObject = prefab; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment