AssetBundle测试

来源:互联网 发布:免费摄像头监控软件 编辑:程序博客网 时间:2024/06/15 03:47

效果



代码如下:

using UnityEngine;using System.Collections;public class LoadTest : MonoBehaviour {    public GameObject man;    public bool state = true;    public string url = "http://192.168.2.105:8080/Test/AssetBundle/Cube.unity3d";    GameObject cube;// Use this for initializationvoid Start () {        man = GameObject.FindGameObjectWithTag("Player");}// Update is called once per framevoid Update () {        if (state ==true && Vector3.Distance(man.transform.position, transform.position) < 2f)        {           StartCoroutine( LoadCube());           state = false;        }        if (cube!=null && Vector3.Distance(man.transform.position, cube.transform.position) > 2f)        {            Destroy(cube);            state = true;        }}    IEnumerator LoadCube()    {        // Start a download of the given URL        // 开始从指定路径下载        WWW www = WWW.LoadFromCacheOrDownload(url, 1);        // Wait for download to complete        // 等待下载完成        yield return www;        if (www.error != null)        {            Debug.Log(www.error);            yield return null;        }        cube = Instantiate(www.assetBundle.mainAsset, transform.position, Quaternion.identity)as GameObject;        www.assetBundle.Unload(true);            }}


原创粉丝点击