游戏开发论坛

 找回密码
 立即注册
搜索
查看: 7455|回复: 0

Unity3D???LuaFramework????(?)??????

[复制链接]

5万

主题

5万

帖子

9万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
90194
发表于 2016-10-26 09:40:47 | 显示全部楼层 |阅读模式
?????????????????????lua????????????????????????????????????????????????????????

???/?? @???

??1?????

???????????????????????????????????????

image002.jpg
???????

????????????????????go?????????????(1,1,1)????????????????????????????????Main.lua??????
  1. function Main()                                       
  2.         local go = UnityEngine.GameObject ('go')
  3.         go.transform.position = Vector3.one               
  4. end
复制代码

image004.jpg
????????go????

?????????????????????????tankPrefab????????????Assets/Tank????????????????????

image006.jpg

???????????????????????????Unity3D?????????????????????????????????????????????????????????????????????UI??????????????????????Unity3D?????????????????????????????????????????

??2?????

??LuaFramework??????????????????????????Assets/LuaFramework/Editor/Packager.cs??????????????????Assets/Tank?????????.prefab??????tank???

image008.jpg
??????

????Build Windows Resource????StreamingAssets??????????

image010.jpg
????????

????????Unity3D??????????????????????????????????????????????????????????????????????????API????

image012.jpg
Unity3D????

??3???????

??????lua???main.lua???????????????resMgr???tank??TankPrefab??????????OnLoadFinish????OnLoadFinish???Instantiate??????
  1. --???????????lua??
  2. function Main()                                       
  3.         LuaHelper = LuaFramework.LuaHelper;
  4.         resMgr = LuaHelper.GetResManager();
  5.         resMgr:LoadPrefab('tank', { 'TankPrefab' }, OnLoadFinish);
  6. end
  7. --????????--
  8. function OnLoadFinish(objs)
  9.         local go = UnityEngine.GameObject.Instantiate(objs[0]);
  10.         LuaFramework.Util.Log("Finish");       
  11. end
复制代码

????????????????????????

image014.jpg
?????????

??4????????

?????????????LoadPrefab??????????????????LoadPrefab?ResourceManager????????Assets\LuaFramework\Scripts\Manager\ResourceManager.cs?????????????????

??LoadPrefab????????????????????????????????OnLoadAsset??????????????????????

image016.jpg
LoadPrefab???

??ResourceManager????m_AssetBundleManifest?m_Dependencies?m_LoadedAssetBundles?m_LoadRequests?4????????????????????????????????????4?????????

image018.jpg
ResourceManager???????

??m_AssetBundleManifest

????m_AssetBundleManifest????????Unity3D?????????tank.unity3D?????????????????????????????????????????????Unity3D????????????????????????

image020.jpg
????????????

????????????????????????????????????????????????????????????????????????????????????????????????TankPrefab??????????common.unity3D????????????

image022.jpg
????

??????Unity3D???????AssetBundle.manifest?????????????StreamingAssets???????????????????????????????????m_AssetBundleManifest??????????????????

image024.jpg
m_AssetBundleManifest????AssetBundle.manifest???

????????????????????????????????????????

  1. string[] dependencies = m_AssetBundleManifest.GetAllDependencies(??);
复制代码

??m_LoadedAssetBundles

???????m_LoadedAssetBundles??????????????????????????????????????????????????????????????
  1. IEnumerator OnLoadAsset(XXX)
  2. {
  3.       AssetBundleInfo bundle = GetLoadedAssetBundle(XXX);  
  4.       if(!bundle)
  5.             bundle  =  OnLoadAssetBundle(??);  
  6.       ????
  7.       ??????
  8. }
复制代码

????GetLoadedAssetBundle?????????????m_LoadedAssetBundles?????????OnLoadAssetBundle????????????

????????????? bundle.LoadAssetAsync(???,??)??????????

??m_Dependencies

??m_Dependencies??????????????????GetLoadedAssetBundle??????????????????????????????????????????????
  1. IEnumerator OnLoadAssetBundle(??)
  2. {
  3.       //?????
  4.       string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName);
  5.       m_Dependencies.Add(abName, dependencies); //?????
  6.       //?????
  7.       for (int i = 0; i < dependencies.Length; i++)
  8.             OnLoadAssetBundle(XXX)  
  9.   //????????
  10.        download = WWW.LoadFromCacheOrDownload(??)
  11. //?????       m_LoadedAssetBundles.Add(XXX)
  12. }
复制代码
  1. AssetBundleInfo GetLoadedAssetBundle(??)
  2. {
  3.        //?????
  4.        AssetBundleInfo bundle = m_LoadedAssetBundles[??];
  5.        if (bundle == null) return null;
  6.        //?????
  7.        foreach (string ???? in m_Dependencies[??])
  8.        {
  9.               if (m_LoadedAssetBundles[????]== null)
  10.                      return null;
  11.        }
  12.        return bundle;
  13. }
复制代码
m_LoadRequests

??m_LoadRequests???<string, List<LoadAssetRequest>>??????LoadAssetRequest??????????????????

image026.jpg
LoadAssetRequest

??????????????????????????????????????????????????

image028.jpg
????????

?????????????2?????????????????????????2???????????????????????????????????m_LoadRequests??????????????????????????????m_LoadRequests??????????????

image030.jpg
????2?????

???????????

  1. void LoadAsset(??)
  2. {
  3.        If(m_LoadRequests[abName] == null)
  4.        {
  5.               m_LoadRequests[??].Add(?????);
  6.               OnLoadAsset();
  7.        }
  8.        else
  9.        {
  10.               m_LoadRequests[??].Add(?????);
  11.        }
  12. }

  13. IEnumerator OnLoadAsset(XXX)
  14. {
  15.        ???
  16.        ????
  17.        foreach( request in  m_LoadRequests[??] )
  18.        {
  19.               Request.????();
  20.        }
  21. }
复制代码

??5??????

??????????????????????????????????????????????????????????????????

??????????LuaFramework????????????????????????????????????????

???????Unity3D???LuaFramework????

??????????????????????????????????????????
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-9-14 21:15

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表