Created
February 6, 2013 22:39
-
-
Save mstevenson/4726563 to your computer and use it in GitHub Desktop.
Creates an on-disk instance of a Unity ScriptableObject. To install, copy CreateAssetFromScript.cs into an Editor folder in your Unity project. To use, first select a script that inherits from ScriptableObject in the Project window, then select the menu Assets > Create Asset From 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 UnityEngine; | |
using UnityEditor; | |
using System; | |
public class CreateAssetFromScript : Editor { | |
[MenuItem("Assets/Create Asset From Manager Script", false, 10000)] | |
public static void CreateManager () | |
{ | |
ScriptableObject asset = ScriptableObject.CreateInstance (Selection.activeObject.name); | |
AssetDatabase.CreateAsset (asset, String.Format ("Assets/{0}.asset", Selection.activeObject.name)); | |
EditorUtility.FocusProjectWindow (); | |
Selection.activeObject = asset; | |
} | |
[MenuItem("Assets/Create Asset From Manager Script", true, 10000)] | |
public static bool CreateManagerValidate () | |
{ | |
if (Selection.activeObject.GetType () != typeof(MonoScript)) | |
return false; | |
MonoScript script = (MonoScript)Selection.activeObject; | |
var scriptClass = script.GetClass (); | |
if (scriptClass == null) | |
return false; | |
return typeof(Manager).IsAssignableFrom (scriptClass.BaseType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment