Unity3D学习笔记

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值