unity3D热更新——(3)Assetbundle资源加载部分

public class ResourceLoad
{
/// < summary >
/// 创建物体
/// </ summary >
/// < param name = "path" ></ param >
/// < returns ></ returns >
public static Object CreatGameObject( string path)
{
Object obj = ResourcesLoad( path);
if ( obj == null)
{
LogOutput. Err_Level_0( "创建物体失败!");
}
return obj;
}
public static Object ResourcesLoad( string path)
{
//ab包在PC上的路径是:C:/Users/Administrator/Desktop/DynamicLoadResource/Assets/StreamingAssets/Android/resources/prefad/ui/xxx
if ( Application. platform == RuntimePlatform. WindowsEditor)
{
return Resources. Load( path);
}
else if ( Application. platform == RuntimePlatform. Android)
{
Debug. Log( Application. persistentDataPath);
//ab包在Android上的路径是
string assPath = Application. persistentDataPath + "/" + Application. platform. ToString() + "/" + AssetPath. ResourcesFilesName + "/" + path. ToLower() + AssetPath. unity3dSuffix;
return AssetBundle. LoadFromFile( assPath). LoadAllAssets()[ 0];
}
else if ( Application. platform == RuntimePlatform. IPhonePlayer)
{
//ab包在IPhonePlayer上的路径是
string assPath = Application. persistentDataPath + "/" + Application. platform. ToString() + "/" + AssetPath. ResourcesFilesName + "/" + path. ToLower() + AssetPath. unity3dSuffix;
return AssetBundle. LoadFromFile( assPath). LoadAllAssets()[ 0];
}
else
{
return null;
}
}
}


猜你喜欢

转载自blog.csdn.net/qq_36512517/article/details/80777078