ImagerGrayMat = resMgr:LoadMaterial("ui/mat/imagegray.unity3d", "ImageGray");
self.btnAllFreeFind:GetComponent('Image').material=ImagerGrayMat
C# 代码如下:
public Material LoadMaterial(string abName,string assetName)
{
if (m_mats.ContainsKey(abName)) return m_mats[abName];
Material m = LoadAsset<Material>(abName, assetName);
if (m != null)
{
m_mats.Add(abName, m);
}
return m;
}
public T LoadAsset<T>(string abname, string assetname,bool dontDestroy = false) where T : UnityEngine.Object {
#if UNITY_EDITOR
if (AppFacade.Instance.SimulateAssetBundleInEditor)
{
string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abname, assetname);
if (assetPaths.Length == 0)
{
Debug.LogError("There is no asset with name \"" + assetname + "\" in " + abname);
return null;
}
// @TODO: Now we only get the main object from the first asset. Should consider type also.
return AssetDatabase.LoadAssetAtPath<T>(assetPaths[0]);
}
#endif
AssetBundle bundle = LoadAssetBundle(abname, dontDestroy);
if (bundle == null)
{
Debug.Log("Load Bundle Error:" + abname);
return null;
}
float start = Time.realtimeSinceStartup;
T t = bundle.LoadAsset<T>(assetname);
float end = Time.realtimeSinceStartup;
if(end -start > 0.5) Debug.Log("Load Asset: " + assetname + "------Time:" + (end - start));
return t;
}
unity3d 加载 Material
猜你喜欢
转载自blog.csdn.net/jiuzhouhi/article/details/84995350
今日推荐
周排行