Nextrek
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
*
* Adventure Creator
* by Chris Burton, 2013-2014
*
* "CustomAssetUtility.cs"
*
* This script allows assets to be created based on a supplied script.
* It is based on code written by Jacob Pennock (http://www.jacobpennock.com/Blog/?p=670)
* and code by Steven van Rossum (https://gist.github.com/JvetS/5208916)
*
*/
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.IO;
public static class CustomAssetUtility
{
public static string GetUniqueAssetPathNameOrFallback (string filename)
{
string path;
try
{
System.Type assetdatabase = typeof (UnityEditor.AssetDatabase);
path = (string) assetdatabase.GetMethod ("GetUniquePathNameAtSelectedPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke(assetdatabase, new object[] { filename });
}
catch
{
path = UnityEditor.AssetDatabase.GenerateUniqueAssetPath("Assets/" + filename);
}
return path;
}
public static void CreateAsset<T> () where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string assetPathAndName = GetUniqueAssetPathNameOrFallback ("New " + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
EditorUtility.FocusProjectWindow ();
Selection.activeObject = asset;
}
public static void CreateAsset<T> (string filename, string path) where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath ("Assets" + Path.DirectorySeparatorChar.ToString () + path + Path.DirectorySeparatorChar.ToString () + filename + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
EditorUtility.FocusProjectWindow ();
}
public static T CreateAndReturnAsset<T> (string filename, string path) where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath ("Assets" + Path.DirectorySeparatorChar.ToString () + path + Path.DirectorySeparatorChar.ToString () + filename + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
EditorUtility.FocusProjectWindow ();
return asset;
}
public static T CreateAndReturnAsset<T> (string path) where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath ("Assets" + Path.DirectorySeparatorChar.ToString () + path + Path.DirectorySeparatorChar.ToString () + typeof(T).ToString() + ".asset");
AssetDatabase.CreateAsset (asset, assetPathAndName);
AssetDatabase.SaveAssets ();
EditorUtility.FocusProjectWindow ();
return asset;
}
}
#endif
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|