-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateScriptableObject.cs
46 lines (39 loc) · 1.05 KB
/
CreateScriptableObject.cs
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
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using System.IO;
#endif
namespace CatAstropheGames
{
public class CreateScriptableObject : MonoBehaviour
{
#if UNITY_EDITOR
public static void CreateMyAsset<T>() where T : ScriptableObject
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (CheckDir(path))
{
T asset = ScriptableObject.CreateInstance<T>();
ProjectWindowUtil.CreateAsset(asset, path + "/New Scriptable Object.asset");
}
}
private static bool CheckDir(string path)
{
if (path.Length > 0)
{
if (Directory.Exists(path))
{
return true;
} else
{
Debug.LogError("Don't select a file, clik in a directory");
}
} else
{
Debug.LogError("Not in assets folder");
}
return false;
}
#endif
}
}