Unity3D学习笔记:AssetBundle有依赖关系时
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadDependency : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
LaodModelFromFile();
}
/// <summary>
/// AssetBundle依赖管理
/// </summary>
void LaodModelFromFile() {
AssetBundle bundle = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/StandaloneWindows");
//加载主配置文件
AssetBundleManifest manifest = bundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
string[] dependencies = manifest.GetAllDependencies("hero.unity3d");
//以次加载依赖文件
foreach (string dependency in dependencies) {
AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + dependency);
}
//因为存在依赖关系,所以bundle必须加载被依赖的资源
AssetBundle bundle1 = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/hero.unity3d");
GameObject gameObject = (GameObject)Instantiate(bundle1.LoadAsset<GameObject>("GameObject"));
gameObject.transform.position = Vector3.zero;
bundle1.Unload(false);
}
// Update is called once per frame
void Update()
{
}
}
需要共同使用的材质设置为public
模型设为预设体,放入到Source目录下的Materials文件中,需要共用的材质也放入到Material中
两个相同的模型(模型GameObject跟模型GameObject1)要使用相同的材质(LEVELSELECTION_2)
图片不能设置成sprite2D否则只能放在Image上,而我们需要的是将图片挂在模型上。
https://blog.csdn.net/qq_35361471/article/details/82854560