赞
踩
AssetDatabase 只能在Editor状态下使用,其可以获取Asset文件夹下的任意路径资源
AssetDatabase.ImportAsset(path, ImportAssetOptions.Default);
AssetDatabase.LoadAssetAtPath();
AssetDatabase.LoadMainAssetAtPath();
AssetDatabase.LoadAllAssetRepresentationsAtPath();
AssetDatabase.LoadAllAssetsAtPath();
获取资源,默认返回的GameObject类型
函数原型:
public static T LoadAssetAtPath<T>(string assetPath) where T : UnityEngine.Object;
返回指定类型资源:
Material m_garyMaterial = AssetDatabase.LoadAssetAtPath<Material>("Assets/Material/Gray.mat");
注意:路径需要加Asset,不然获取不到
注意:路径需要加Asset,不然获取不到
注意:路径需要加Asset,不然获取不到
// 创建一个材质
Material material = new Material(Shader.Find("Specular"));
AssetDatabase.CreateAsset(material, "Assets/MyMaterial.mat");
// 创建一个目录
string folder_guid = AssetDatabase.CreateFolder("Assets", "NewFolder");
AssetDatabase.Refresh();
string src_path = "Assets/MyMaterial.mat";
string new_path = "Assets/Copyed_Material.mat";
bool op_success = AssetDatabase.CopyAsset(src_path, new_path);
// 删除至回收站
bool op_success = AssetDatabase.MoveAssetToTrash("Assets/Copyed_Material.mat");
// 删除
bool op_succ = AssetDatabase.DeleteAsset("Assets/Copyed_Material.mat");
string renamed_mat_guid = AssetDatabase.RenameAsset("Assets/Copyed_Material.mat", "NewMatrial2.mat");
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。