AssetDatabase类
一、委托和事件
1.委托
public delegate void ImportPackageCallback(string packageName);
public delegate void ImportPackageFailedCallback(string packageName, string errorMessage);
三、举例
1.保存资源
bool isTrigger = true;
Vector3 center = Vector3.zero;
Vector3 size = Vector3.zero;
private void OnGUI()
{
GUILayout.BeginVertical();
GUILayout.Label("BoxCollider");
isTrigger = GUILayout.Toggle(isTrigger, "isTrigger");
center = EditorGUILayout.Vector3Field("center", center);
size = EditorGUILayout.Vector3Field("size", size);
if (GUILayout.Button("设置内容"))
{
int length = 0;
var objs = Selection.GetFiltered<Object>(SelectionMode.Assets);
for (int i = 0; i < objs.Length; i++)
{
string path = AssetDatabase.GetAssetPath(objs[i]);
if (string.IsNullOrEmpty(path))
continue;
GameObject obj = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
if (obj)
{
BoxCollider box = obj.GetComponent<BoxCollider>();
if (box)
{
box.isTrigger = isTrigger;
box.center = center;
box.size = size;
length++;
EditorUtility.SetDirty(obj);
}
}
}
if (length > 0)
{
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
}
}
GUILayout.EndVertical();
}