Created
January 4, 2015 12:07
-
-
Save anonymous/d2575f36b144392bdc14 to your computer and use it in GitHub Desktop.
Add a create instance button on the inspector of scripts that can generate a ScriptableObject
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
using UnityEditor; | |
using UnityEngine; | |
// From https://www.youtube.com/watch?v=SyR4OYZpVqQ | |
[CustomEditor(typeof(MonoScript))] | |
public class ScriptInspector : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
MonoScript monoScript = target as MonoScript; | |
System.Type type = monoScript.GetClass(); | |
if (type != null && | |
type.IsSubclassOf(typeof(ScriptableObject)) && | |
!type.IsSubclassOf(typeof(UnityEditor.Editor))) | |
{ | |
if (GUILayout.Button("Create Instance", GUILayout.Height(30))) | |
{ | |
ScriptableObject asset = ScriptableObject.CreateInstance(type); | |
string path = AssetDatabase.GenerateUniqueAssetPath("Assets/" + type.Name + ".asset"); | |
AssetDatabase.CreateAsset(asset, path); | |
EditorGUIUtility.PingObject(asset); | |
} | |
GUILayout.Space(10); | |
} | |
GUILayout.Label(monoScript.text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment