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