| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using System.Reflection; |
| | 4 | | using UnityEditor; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// A helper class for instantiating ScriptableObjects in the editor. |
| | 9 | | /// </summary> |
| | 10 | | public class ScriptableObjectFactory |
| | 11 | | { |
| | 12 | | [MenuItem("Assets/Create/ScriptableObject")] |
| | 13 | | public static void CreateScriptableObject() |
| | 14 | | { |
| 0 | 15 | | var assembly = GetAssembly (); |
| | 16 | |
|
| | 17 | | // Get all classes derived from ScriptableObject |
| 0 | 18 | | var allScriptableObjects = (from t in assembly.GetTypes() |
| 0 | 19 | | where t.IsSubclassOf(typeof(ScriptableObject)) |
| | 20 | | select t).ToArray(); |
| | 21 | |
|
| | 22 | | // Show the selection window. |
| 0 | 23 | | ScriptableObjectWindow.Init(allScriptableObjects); |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Returns the assembly that contains the script code for this project (currently hard coded) |
| | 28 | | /// </summary> |
| 0 | 29 | | private static Assembly GetAssembly () { return Assembly.Load (new AssemblyName ("MainScripts")); } |
| | 30 | | } |