| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using UnityEditor; |
| | 4 | | using UnityEditor.ProjectWindowCallback; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | internal class EndNameEdit : EndNameEditAction |
| | 8 | | { |
| | 9 | |
|
| | 10 | | #region implemented abstract members of EndNameEditAction |
| | 11 | |
|
| 0 | 12 | | public override void Action (int instanceId, string pathName, string resourceFile) { AssetDatabase.CreateAsset(Edito |
| | 13 | |
|
| | 14 | | #endregion |
| | 15 | |
|
| | 16 | | } |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Scriptable object window. |
| | 20 | | /// </summary> |
| | 21 | | public class ScriptableObjectWindow : EditorWindow |
| | 22 | | { |
| | 23 | | private int selectedIndex; |
| | 24 | | private static string[] names; |
| | 25 | |
|
| | 26 | | private static Type[] types; |
| | 27 | |
|
| | 28 | | private static Type[] Types |
| | 29 | | { |
| | 30 | | get { return types; } |
| | 31 | | set |
| | 32 | | { |
| | 33 | | types = value; |
| | 34 | | names = types.Select(t => t.FullName).ToArray(); |
| | 35 | | } |
| | 36 | | } |
| | 37 | |
|
| | 38 | | public static void Init(Type[] scriptableObjects) |
| | 39 | | { |
| | 40 | | Types = scriptableObjects; |
| | 41 | |
|
| | 42 | | var window = EditorWindow.GetWindow<ScriptableObjectWindow>(true, "Create a new ScriptableObject", true); |
| | 43 | | window.ShowPopup(); |
| | 44 | | } |
| | 45 | |
|
| | 46 | | public void OnGUI() |
| | 47 | | { |
| | 48 | | GUILayout.Label("ScriptableObject Class"); |
| | 49 | | selectedIndex = EditorGUILayout.Popup(selectedIndex, names); |
| | 50 | |
|
| | 51 | | if (GUILayout.Button("Create")) |
| | 52 | | { |
| | 53 | | var asset = ScriptableObject.CreateInstance(types[selectedIndex]); |
| | 54 | | ProjectWindowUtil.StartNameEditingIfProjectWindowExists( |
| | 55 | | asset.GetInstanceID(), |
| | 56 | | ScriptableObject.CreateInstance<EndNameEdit>(), |
| | 57 | | string.Format("{0}.asset", names[selectedIndex]), |
| | 58 | | AssetPreview.GetMiniThumbnail(asset), |
| | 59 | | null); |
| | 60 | |
|
| | 61 | | Close(); |
| | 62 | | } |
| | 63 | | } |
| | 64 | | } |