[Unity3D学习]Unity代码热更新 源码下载
2015-12-07 22:46
381 查看
转载自:http://blog.gamerisker.com/archives/608.html
之前的一篇文章《[Unity3D学习]Unity代码热更新解决方案测试结果总结》只是说了一下方案的流程,今天刚好有时间,又再看了一下热更新这一块!就直接将代码分享出来。代码热更新的核心基本实现,只是需要处理一些依赖等等。
资源都是放在我blog的服务器上,提供给大家测试。
时间有点晚了1:30,直接贴代码睡觉了!(最近一个月拼死的加班,实在太累。)
demo : http://pan.baidu.com/s/1c0cuTZa
Index.cs
Game.cs
参考文章:
http://blog.csdn.net/janeky/article/details/25923151
http://docs.unity3d.com/Manual/scriptsinassetbundles.html
之前的一篇文章《[Unity3D学习]Unity代码热更新解决方案测试结果总结》只是说了一下方案的流程,今天刚好有时间,又再看了一下热更新这一块!就直接将代码分享出来。代码热更新的核心基本实现,只是需要处理一些依赖等等。
资源都是放在我blog的服务器上,提供给大家测试。
时间有点晚了1:30,直接贴代码睡觉了!(最近一个月拼死的加班,实在太累。)
demo : http://pan.baidu.com/s/1c0cuTZa
Index.cs
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | using UnityEngine;using System.Collections; /// <summary>/// 游戏壳的入口,用于加载真实的代码/// </summary>public class Index : MonoBehaviour { private WWW www; public static WWW uiWWW; private System.Reflection.Assembly assembly; // Use this for initialization void Start () { StartCoroutine(loadSprite()); //GameObject go = new GameObject(); //go.AddComponent<Game>(); } void Update() { } private IEnumerator loadSprite() { www = new WWW("http://game.gamerisker.com/assets/Core.assetbundle"); yield return www; if (www.isDone) { AssetBundle bundle = www.assetBundle; TextAsset asset = bundle.Load("Core", typeof(TextAsset)) as TextAsset; assembly = System.Reflection.Assembly.Load(asset.bytes); System.Type script = assembly.GetType("Game"); Debug.Log("Load Game Script Complete..."); gameObject.AddComponent(script); } }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | using UnityEngine; using System.Collections; /// <summary> /// 这个类是真正的游戏入口类,这个类中存放业务逻辑 代码热更新的就是这边的代码!~ /// </summary> public class Game : MonoBehaviour { private WWW www; private WWW fontWWW; // Use this for initialization void Start() { Debug.Log("Start Load UIAtlas!"); StartCoroutine(LoadAtlas()); StartCoroutine(LoadFont()); } void Update() { if (www != null && !www.isDone) { Debug.Log("atlas progress : " + www.progress); } if (fontWWW != null && !fontWWW.isDone) { Debug.Log("font progress : " + fontWWW.progress); } } private IEnumerator LoadFont() { fontWWW = new WWW("http://game.gamerisker.com/assets/Font.assetbundle"); yield return fontWWW; Complete(); } private IEnumerator LoadAtlas() { www = new WWW("http://game.gamerisker.com/assets/Atlas.assetbundle"); yield return www; Complete(); } private void Complete() { if (fontWWW.isDone && www.isDone) { GameObject atlas = www.assetBundle.Load("Default", typeof(GameObject)) as GameObject; UISprite sprite = NGUITools.AddChild<UISprite>(gameObject); UIAtlas uiatlas = atlas.GetComponent<UIAtlas>(); sprite.atlas = uiatlas; sprite.spriteName = "default_tishikuang"; sprite.width = 300; sprite.height = 300; //这里的字体 是NGUI 例子里面的字体,我直接将他的prefab 打成了assetbundle 使用 GameObject font = fontWWW.assetBundle.Load("SciFi Font - Normal",typeof(GameObject)) as GameObject; UIFont uifont = font.GetComponent<UIFont>(); UILabel label = NGUITools.AddChild<UILabel>(sprite.gameObject); label.text = "Load Script Succeed!"; label.transform.localPosition = Vector3.zero; label.transform.localScale = Vector3.one; label.width = 300; label.bitmapFont = uifont; Debug.Log("Complete."); } } } |
http://blog.csdn.net/janeky/article/details/25923151
http://docs.unity3d.com/Manual/scriptsinassetbundles.html
相关文章推荐
- Kinect结合Unity3D引擎开发体感游戏(一)
- Unity3D中脚本的执行顺序和编译顺序
- Unity3D动态对象优化代码分享
- Unity3D获取当前键盘按键及Unity3D鼠标、键盘的基本操作
- Unity3d获取系统时间
- Node.js巧妙实现Web应用代码热更新
- unity3d发布apk在android虚拟机中运行的详细步骤(unity3d导出android apk)
- Unity3D游戏引擎实现在Android中打开WebView的实例
- unity3d调用手机或电脑摄像头
- Unity3d发布IOS9应用时出现中文乱码的解决方法
- 分享一个开源的网络游戏服务器架构—HouHai
- Unity3D插件详细评测及教学下载
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关