专属撩妹开发之AssetsBundle更新游戏场景内容

阅读: 评论:0

专属撩妹开发之AssetsBundle更新游戏场景内容

专属撩妹开发之AssetsBundle更新游戏场景内容

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
//using UnityEngine.Networking;
//如何快速建立一个测试资源Web服务器及异步获取资源(Unity3D)
//.html
//有个小想法专属妹子APP,如果想要直接更换APP里面的内容。服务器这边之前更换AssetsBundle包就直接加载新场景
//新场景怎么设计都可以
public class LoadAssetsBundles : MonoBehaviour {string path1;string path2 ;string path3;string path4;Texture texture;public static string version = "version1";void Start(){//需要在这里赋值path1 = "Assets/AssetsBundles/object.unity3d";//包内容一个Cube和Sphere预设   包名+后缀path2 = "Assets/AssetsBundles/material.unity3d";//包内容一个材质球path3 = "Assets/AssetsBundles/texture.assetsbundle";//包内容一张名为timg的图片path4 = "Assets/AssetsBundles/scene.unity3d";//包内容  一个场景StartCoroutine(StartAB());}// Use this for initializationIEnumerator StartAB () {//第一种方式从内存中加载AB包#region 异步加载//异步加载// AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path1));// yield return request;// //加载共同依赖资源,如贴图  材质// AssetBundleCreateRequest request2 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path2));// yield return request2;// AssetBundleCreateRequest request3 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path3));// yield return request3;// AssetBundleCreateRequest request4 = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(path4));// yield return request4;// AssetBundle ab = request.assetBundle;//获取包// AssetBundle ab2 = request2.assetBundle;//获取包// AssetBundle ab3 = request3.assetBundle;// AssetBundle ab4 = request4.assetBundle;// //使用里面的资源// GameObject cube = ab.LoadAsset<GameObject>("Cube");// GameObject sphere = ab.LoadAsset<GameObject>("Sphere");//  texture = ab3.LoadAsset<Texture>("timg");//获取图片// Debug.Log(texture.width + texture.height+texture.name);// //场景中新建一个RawImage// GameObject.Find("Canvas/RawImage").GetComponent<RawImage>().texture = texture;// //获得场景包之后可以直接//SceneManager.LoadScene("AssetBundleScene");// Instantiate(cube);// Instantiate(sphere);#endregion//下载软件 MyWebServer服务器 .html#region 同步加载WWW www = new WWW("192.168.0.70/scene.unity3d");yield return www;WWW www1 = new WWW("192.168.0.70/1.jpg");yield return www1;WWW www2 = new WWW("192.168.0.");//版本号   注意txt的格式需要为ASCII格式yield return www2;//版本号的确认if (www2!=null){//版本不一致才需要更新if (!= version){if (www1 != null){//更新图片texture = ure;GameObject.Find("Canvas/RawImage").GetComponent<RawImage>().texture = texture;}else{Debug.Log("666");}AssetBundle ab1 = www.assetBundle;if (ab1 != null){//加载新场景(初始场景)SceneManager.LoadScene("AssetBundleScene");}//记录当前版本version = ;}else{Debug.Log("版本跟最新版保持一致不需要更新");}}#endregionStopAllCoroutines();}// Update is called once per framevoid Update () {}
}

本文发布于:2024-01-28 05:27:12,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063908365116.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:场景   内容   游戏   AssetsBundle
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23