本文整理汇总了C#中UnityEngine.AssetBundle.Load方法的典型用法代码示例。如果您正苦于以下问题:C# AssetBundle.Load方法的具体用法?C# AssetBundle.Load怎么用?C# AssetBundle.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AssetBundle
的用法示例。
在下文中一共展示了AssetBundle.Load方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadBundle
/// <summary>
/// 创建
/// </summary>
/// <param name="decryptedData"></param>
/// <returns></returns>
IEnumerator LoadBundle(byte[] decryptedData)
{
AssetBundleCreateRequest acr = AssetBundle.CreateFromMemory(decryptedData);
yield return acr;
assetBundel = acr.assetBundle;
Instantiate(assetBundel.Load("Cube"));
}
示例2: LoadFromBundle
private UnityEngine.Object LoadFromBundle(AssetBundle bundle, string name)
{
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6
return bundle.Load(name);
#else
return bundle.LoadAsset(name);
#endif
}
示例3: initialize
/// <summary>
/// 初始化
/// </summary>
void initialize() {
string uri = string.Empty;
//------------------------------------Shared--------------------------------------
uri = Util.DataPath + "shared.assetbundle";
Debug.LogWarning("LoadFile::>> " + uri);
shared = AssetBundle.CreateFromFile(uri);
shared.Load("Dialog", typeof(GameObject));
ioo.gameManager.OnResourceInited(); //回调游戏管理器,执行后续操作
}
示例4: LoadBundle
public IEnumerator LoadBundle()
{
ImBusy = true;
string url = "file:///"+Path.GetFullPath(ResPath);
MessageServiceClass.MessageProcessing("Loadin bundle from "+url);
WWW www = WWW.LoadFromCacheOrDownload(url, version);
yield return www;
MessageServiceClass.MessageProcessing("Bundle resources are loaded from "+ url);
assetBundle = www.assetBundle;
CircleGameObjPref = assetBundle.Load("circle") as GameObject;
for (int i = 0;i <4; i++){
BundleResourceTextures2d[i] = assetBundle.Load (BundleTexturesNames[i]) as Texture2D;
}// int i = 0;i <4; i++
assetBundle.Unload(false);
ImBusy = false;
}
示例5: LoadAssetsFromBundle
public IEnumerator LoadAssetsFromBundle(AssetBundle bundle, string[] names)
{
objects = new List<Object>();
foreach (var name in names)
{
Object obj = bundle.Load(name);
TryAddAsset(name, obj, objects);
}
yield return null;
}
示例6: initialize
/// <summary>
/// 初始化
/// </summary>
public void initialize(Action func) {
byte[] stream;
string uri = string.Empty;
//------------------------------------Shared--------------------------------------
uri = Util.DataPath + "shared.assetbundle";
Debug.LogWarning("LoadFile::>> " + uri);
stream = File.ReadAllBytes(uri);
shared = AssetBundle.CreateFromMemoryImmediate(stream);
#if UNITY_5
shared.LoadAsset("Dialog", typeof(GameObject));
#else
shared.Load("Dialog", typeof(GameObject));
#endif
if (func != null) func(); //资源初始化完成,回调游戏管理器,执行后续操作
}
示例7: loadAssetBundle
/**
(3):AssetBundle
关于AssetBundle的介绍已经有很多了。简而言之就是把prefab或者二进制文件封装成AssetBundle文件(也是一种二进制)。
但是也有硬伤,就是在移动端无法更新脚本。下面简单的总结下:
1:是Unity3D定义的一种二进制类型。
2:最好将prefab封装成AseetBundle,不过上面不是才说了在移动端无法更新脚本吗?
那从Assetbundle中拿到的Prefab上挂的脚本是不是就无法运行了?也不一定,只要这个prefab上挂的是本地脚本,就可以。
3:使用WWW类来下载。
* */
IEnumerator loadAssetBundle()
{
AssetBundle AssetBundleCsv = new AssetBundle();
//读取放入StreamingAssets文件夹中的bundle文件
string str = Application.streamingAssetsPath + "/" + "Test.bundle";
WWW www = new WWW(str);
www = WWW.LoadFromCacheOrDownload(str, 0);
AssetBundleCsv = www.assetBundle;
string path = "Test";
TextAsset test = AssetBundleCsv.Load(path, typeof(TextAsset)) as TextAsset;
string result = test.ToString();
yield return null;
}
示例8: initialize
/// <summary>
/// 初始化
/// </summary>
public void initialize(Action func) {
if (AppConst.ExampleMode) {
byte[] stream;
string uri = string.Empty;
//------------------------------------Shared--------------------------------------
uri = Util.DataPath + "shared" + AppConst.ExtName;
Debug.LogWarning("LoadFile::>> " + uri);
stream = File.ReadAllBytes(uri);
shared = AssetBundle.LoadFromMemory(stream);
#if UNITY_5
shared.LoadAsset("Dialog", typeof(GameObject));
#else
shared.Load("Dialog", typeof(GameObject));
#endif
}
if (func != null) func(); //资源初始化完成,回调游戏管理器,执行后续操作
}
示例9: StartCreatePanel
/// <summary>
/// 创建面板
/// </summary>
IEnumerator StartCreatePanel(string name, AssetBundle bundle, string text = null) {
name += "Panel";
GameObject prefab = bundle.Load(name) as GameObject;
yield return new WaitForEndOfFrame();
if (Parent.FindChild(name) != null || prefab == null) {
yield break;
}
GameObject go = Instantiate(prefab) as GameObject;
go.name = name;
go.layer = LayerMask.NameToLayer("Default");
go.transform.parent = Parent;
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero;
yield return new WaitForEndOfFrame();
go.AddComponent<BaseLua>().OnInit(bundle);
Debug.Log("StartCreatePanel------>>>>" + name);
}
示例10: AddPackage
/// <summary>
/// Add a UI package from two assetbundles with a optional main asset name.
/// </summary>
/// <param name="desc">A assetbunble contains description file.</param>
/// <param name="res">A assetbundle contains resources.</param>
/// <param name="mainAssetName">Main asset name.</param>
/// <returns>UIPackage</returns>
public static UIPackage AddPackage(AssetBundle desc, AssetBundle res, string mainAssetName)
{
string source = null;
#if UNITY_5
if (mainAssetName != null)
{
TextAsset ta = desc.LoadAsset<TextAsset>(mainAssetName);
if (ta != null)
source = ta.text;
}
else
{
string[] names = desc.GetAllAssetNames();
foreach (string n in names)
{
if (n.IndexOf("@") == -1)
{
TextAsset ta = desc.LoadAsset<TextAsset>(n);
if (ta != null)
{
source = ta.text;
if (mainAssetName == null)
mainAssetName = Path.GetFileNameWithoutExtension(n);
break;
}
}
}
}
#else
if (mainAssetName != null)
{
TextAsset ta = (TextAsset)desc.Load(mainAssetName, typeof(TextAsset));
if (ta != null)
source = ta.text;
}
else
{
source = ((TextAsset)desc.mainAsset).text;
mainAssetName = desc.mainAsset.name;
}
#endif
if (source == null)
throw new Exception("FairyGUI: invalid package.");
if (desc != res)
desc.Unload(true);
return AddPackage(source, res, mainAssetName);
}
示例11: DownloadAssetBundle
private IEnumerator DownloadAssetBundle(string asset, string bundleName, int version)
{
loadedAsset = null;
// Wait for the Caching system to be ready
while (!Caching.ready)
{
yield return null;
}
string url = baseURL + bundleName;
// Start the download
using (WWW www = WWW.LoadFromCacheOrDownload(url, version))
{
yield return www;
if (www.error != null)
{
throw new System.Exception("AssetBundle - WWW download:" + www.error);
}
thisAssetBundle = www.assetBundle;
//load the specified asset into memory
loadedAsset = thisAssetBundle.Load(asset, typeof(GameObject));
www.Dispose();
isDone = true;
}
}
示例12: LoadAsset
public static GameObject LoadAsset(AssetBundle bundle, string name)
{
#if UNITY_5
return bundle.LoadAsset(name, typeof(GameObject)) as GameObject;
#else
return bundle.Load(name, typeof(GameObject)) as GameObject;
#endif
}
示例13: Load
IEnumerator Load()
{
string filePath = string.Empty;
if(GooglePlayDownloader.RunningOnAndroid()){
if(mainPath == null){
needServerDownload = true;
message = "MainFile still not found!";
Debug.Log(message);
}
if(needServerDownload){
filePath = ServerURL + "/" + AssetBundleName + ".unity3d";
} else {
filePath = "jar:file://" + mainPath;
filePath += "!/"+AssetBundleName+".unity3d";
}
} else {
filePath = "file://" + Application.dataPath;
filePath += "/"+AssetBundleName+".unity3d";
}
message = "FilePath: " + filePath;
Debug.Log(message);
www = WWW.LoadFromCacheOrDownload(filePath,AssetVersionNumber);
yield return www;
bundle = www.assetBundle;
loadedAssets.Clear();
foreach(var name in PrefabNames){
GameObject go = bundle.Load(name, typeof(GameObject)) as GameObject;
loadedAssets.Add(name, go);
}
if(loadingScreen != null && loadingScreen.renderer != null)
loadingScreen.renderer.enabled = false;
Application.LoadLevel(ChangeToScene);
}