public ByteArray GetProtoBytes(string file) { if (!_protoBytes.ContainsKey(file)) { if (LGameConfig.GetInstance().isDebug) { LArchiveBinFile cArc = new LArchiveBinFile(); string strFullPath = LGameConfig.GetInstance().GetLoadUrl(LGameConfig.DATA_CATAGORY_LUA + "/Game/Proto/" + file + ".bytes"); if (!cArc.Open(strFullPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { return(null); } if (!cArc.IsValid()) { return(null); } int nContentLength = (int)cArc.GetStream().Length; byte[] aContents = new byte[nContentLength]; cArc.ReadBuffer(ref aContents, nContentLength); cArc.Close(); _protoBytes.Add(file, new ByteArray(aContents)); } else { TextAsset asset = LLoadBundle.GetInstance().LoadAsset <TextAsset>("@lua.ab", "@Lua/Game/Proto/" + file + ".bytes"); _protoBytes.Add(file, new ByteArray(asset.bytes)); } } return(_protoBytes[file]); }
public Sprite[] GetSpritesByName(string bundlePath, string atlasName) { List <Sprite> arr = new List <Sprite>(); if (LGameConfig.GetInstance().isDebug) { Sprite[] sprites = Resources.LoadAll <Sprite>(bundlePath); foreach (Sprite s in sprites) { if (string.IsNullOrEmpty(atlasName) || s.name.StartsWith(atlasName)) { arr.Add(s); } } } else { string bundleName = LGameConfig.GetABNameWithAtlasPath(bundlePath.Split('.')[0] + ".png"); AssetBundle assetBundle = this.GetBundleByName(bundleName); if (assetBundle) { Sprite[] sprites = assetBundle.LoadAllAssets <Sprite>(); foreach (Sprite s in sprites) { if (string.IsNullOrEmpty(atlasName) || s.name.StartsWith(atlasName)) { arr.Add(s); } } } } return(arr.ToArray()); }
public T LoadAsset <T>(string bundleName, string assetName) where T : Object { T prefab = null; if (LGameConfig.GetInstance().isDebug) { assetName = assetName.Split('.')[0]; prefab = Resources.Load <T>(assetName); } else { AssetBundle b; bundles.TryGetValue(bundleName, out b); if (b != null) { // Debug.Log(string.Format(LGameConfig.ASSET_BASE_FORMAT, assetName)); prefab = b.LoadAsset <T>(string.Format(LGameConfig.ASSET_BASE_FORMAT, assetName)); } else { Debug.Log("bundle not exist! : " + bundleName); } } return(prefab); }
protected LWindowBase loadWindow(string name) { LWindowBase ret = null; if (cacheWindows.ContainsKey(name)) { ret = cacheWindows[name]; } else if (delayDisposeWindows.ContainsKey(name)) { ret = delayDisposeWindows[name]; } else { string abName = LGameConfig.GetABNameWithAtlasPath(name); GameObject res = LLoadBundle.GetInstance().LoadAsset <GameObject>(abName, name); GameObject obj = Instantiate(res); obj.name = name; obj.GetComponent <RectTransform>().sizeDelta = canvas.GetComponent <RectTransform>().rect.size; ret = obj.GetComponent <LWindowBase>(); if (ret) { ret.name = obj.name; } } return(ret); }
public void checkUpdate() { Debug.Log("开始热更"); //初始化 LocalResVersion = new Dictionary <string, string>(); ServerResVersion = new Dictionary <string, string>(); NeedDownFiles = new List <string>(); Debug.Log("客户端ver:" + LOCAL_RES_URL + VERSION_FILE); //加载本地version配置 StartCoroutine(DownLoad(LOCAL_RES_URL + VERSION_FILE, delegate(WWW localVersion) { //保存本地的version ParseVersionFile(localVersion.text, LocalResVersion); Debug.Log("服务端ver:" + LGameConfig.GetInstance().SERVER_RES_URL + Path.DirectorySeparatorChar + VERSION_FILE); //加载服务端version配置 StartCoroutine(this.DownLoad(LGameConfig.GetInstance().SERVER_RES_URL + Path.DirectorySeparatorChar + VERSION_FILE, delegate(WWW serverVersion) { //保存服务端version ParseVersionFile(serverVersion.text, ServerResVersion); //计算出需要重新加载的资源 CompareVersion(); //加载需要更新的资源 DownLoadRes(); })); })); }
protected byte[] loadFileWithSuffix(string strFile) { if (string.IsNullOrEmpty(strFile)) { return(null); } strFile.Replace(".", "/"); strFile += LGameConfig.FILE_AFFIX_LUA; string strLuaPath = LGameConfig.DATA_CATAGORY_LUA + Path.DirectorySeparatorChar + strFile; string strFullPath = LGameConfig.GetInstance().GetLoadUrl(strLuaPath); // Read from file. LArchiveBinFile cArc = new LArchiveBinFile(); if (!cArc.Open(strFullPath, FileMode.Open, FileAccess.Read)) { return(null); } if (!cArc.IsValid()) { return(null); } int nContentLength = (int)cArc.GetStream().Length; byte[] aContents = new byte[nContentLength]; cArc.ReadBuffer(ref aContents, nContentLength); cArc.Close(); return(aContents); }
public Object LoadAsset(string bundleName, string assetName, System.Type assetType) { Object prefab = null; if (LGameConfig.GetInstance().isDebug) { assetName = assetName.Split('.')[0]; prefab = Resources.Load(string.Format("Prefabs/{0}", assetName), assetType); } else { AssetBundle b; bundles.TryGetValue(bundleName, out b); if (b != null) { Debug.Log(string.Format(LGameConfig.ASSETBUNDLE_LOAD_FORMAT, assetName)); prefab = b.LoadAsset(string.Format(LGameConfig.ASSETBUNDLE_LOAD_FORMAT, assetName), assetType); } else { Debug.Log("bundle not exist! : " + bundleName); } } return(prefab); }
void Start() { Application.targetFrameRate = LGameConfig.DEFAULT_FRAME_RATE; if (_l == null) { #if UNITY_5 Application.logMessageReceived += this.log; #else Application.RegisterLogCallback(this.log); #endif if (LGameConfig.GetInstance().isDebug) { LuaState.loaderDelegate = loadFileWithSuffix; } else { LuaState.loaderDelegate = loadLuaWithAb; } _l = new LuaSvr(); _l.init(tick, complete); } else { complete(); } }
public static LGameConfig GetInstance() { if (null == m_cInstance) { m_cInstance = new LGameConfig(); } return(m_cInstance); }
public void LoadAllBundles(string[] bundle_names, UnityAction callFunc, UnityAction <int> progressFunc = null) { if (LGameConfig.GetInstance().isDebug) { callFunc.Invoke(); } else { StartCoroutine(Load(bundle_names, callFunc, progressFunc)); } }
static public int get_CachingAssetsPath(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); pushValue(l, true); pushValue(l, self.CachingAssetsPath); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int GetInstance_s(IntPtr l) { try { var ret = LGameConfig.GetInstance(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int get_SERVER_RES_URL(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); pushValue(l, true); pushValue(l, self.SERVER_RES_URL); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int get_isEncrypt(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); pushValue(l, true); pushValue(l, self.isEncrypt); return(2); } catch (Exception e) { return(error(l, e)); } }
void complete() { if (LGameConfig.GetInstance().isShowFps) { LFPSView.Show(); } if (!LGameConfig.GetInstance().isDebug) //生产环境 { if (LGameConfig.GetInstance().isHotFix) { GameObject canvas = GameObject.Find("Canvas"); Text lab_unzip = null; if (canvas.transform.Find("prog")) { canvas.transform.Find("prog").gameObject.SetActive(true); lab_unzip = canvas.transform.Find("prog/lab_unzip").GetComponent <Text>(); } GameObject obj = new GameObject(); obj.name = "ResUpdate"; LResUpdate resUpdate = obj.AddComponent <LResUpdate> (); resUpdate.onUnzipProgressHandler = (int step) => { if (lab_unzip) { lab_unzip.text = step.ToString(); } Debug.Log(" unzip " + step); }; resUpdate.onCompleteHandler = () => { Destroy(obj); LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () => { _l.start("main"); }); }; resUpdate.checkUpdate(); } else { LLoadBundle.GetInstance().LoadAllBundles(new string[] { "@lua.ab", "@luaconfig.ab" }, () => { _l.start("main"); }); } } else //PC端开发 { _l.start("main"); } }
static public int set_isEncrypt(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); System.Boolean v; checkType(l, 2, out v); self.isEncrypt = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
protected byte[] loadLuaWithAb(string strFile) { string ext = LGameConfig.GetInstance().isEncrypt ? ".bytes" : ".txt"; TextAsset asset = LLoadBundle.GetInstance().LoadAsset <TextAsset>("@lua.ab", "@Lua/" + strFile + ext); if (asset == null) { return(null); } //if (LGameConfig.GetInstance().isEncrypt) // return LUtil.AESDecrypt(asset.bytes, LGameConfig.EncryptKey32, LGameConfig.EncryptKey16); //else return(asset.bytes); }
static public int GetABNameWithAtlasPath_s(IntPtr l) { try { System.String a1; checkType(l, 1, out a1); var ret = LGameConfig.GetABNameWithAtlasPath(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int set_SERVER_RES_URL(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); System.String v; checkType(l, 2, out v); self.SERVER_RES_URL = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int GetLoadUrl(IntPtr l) { try { LGameConfig self = (LGameConfig)checkSelf(l); System.String a1; checkType(l, 2, out a1); var ret = self.GetLoadUrl(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public T[] LoadAllAsset <T>(string bundleName, string assetName) where T : Object { T[] prefabs = null; if (LGameConfig.GetInstance().isDebug) { prefabs = Resources.LoadAll <T>(string.Format("Prefabs/{0}", assetName)); } else { AssetBundle b = bundles[bundleName]; if (b != null) { prefabs = b.LoadAllAssets <T>(); } } return(prefabs); }
public Sprite[] GetSpritesByName(string bundlePath, string atlasName) { string key = string.Format("{0}_{1}", bundlePath, atlasName); if (spritesCache.ContainsKey(key)) { return(spritesCache[key]); } else { List <Sprite> arr = new List <Sprite>(); if (LGameConfig.GetInstance().isDebug) { Sprite[] sprites = Resources.LoadAll <Sprite>(bundlePath); int spritesLen = sprites.Length; for (int i = 0; i < spritesLen; i++) { Sprite s = sprites[i]; if (string.IsNullOrEmpty(atlasName) || s.name.StartsWith(atlasName)) { arr.Add(s); } } } else { string bundleName = LGameConfig.GetABNameWithAtlasPath(bundlePath.Split('.')[0] + ".png"); AssetBundle assetBundle = this.GetBundleByName(bundleName); if (assetBundle) { Sprite[] sprites = assetBundle.LoadAllAssets <Sprite>(); int spritesLen = sprites.Length; for (int i = 0; i < spritesLen; i++) { Sprite s = sprites[i]; if (string.IsNullOrEmpty(atlasName) || s.name.StartsWith(atlasName)) { arr.Add(s); } } } } spritesCache.Add(key, arr.ToArray()); return(spritesCache[key]); } }
public Object LoadAsset(string bundleName, string assetName, System.Type assetType) { Object prefab = null; if (LGameConfig.GetInstance().isDebug) { prefab = Resources.Load(string.Format("Prefabs/{0}", assetName), assetType); } else { AssetBundle b = bundles[bundleName]; if (b != null) { prefab = b.LoadAsset(string.Format(LGameConfig.ASSETBUNDLE_LOAD_FORMAT, assetName.ToLower()), assetType); } } return(prefab); }
//依次加载需要更新的资源 private void DownLoadRes() { if (NeedDownFiles.Count == 0) { UpdateLocalVersionFile(); return; } string file = NeedDownFiles[0]; NeedDownFiles.RemoveAt(0); StartCoroutine(this.DownLoad(LGameConfig.GetInstance().SERVER_RES_URL + Path.DirectorySeparatorChar + file, delegate(WWW w) { //将下载的资源替换本地就的资源 ReplaceLocalRes(file, w.bytes); DownLoadRes(); })); }
public T[] LoadAllAsset <T>(string bundleName, string assetName) where T : Object { T[] prefabs = null; if (LGameConfig.GetInstance().isDebug) { assetName = assetName.Split('.')[0]; prefabs = Resources.LoadAll <T>(assetName); } else { AssetBundle b; bundles.TryGetValue(bundleName, out b); if (b != null) { prefabs = b.LoadAllAssets <T>(); } } return(prefabs); }
void complete() { LFPSView.Show(); if (!LGameConfig.GetInstance().isDebug) //生产环境 { GameObject obj = new GameObject(); obj.name = "ResUpdate"; LResUpdate resUpdate = obj.AddComponent <LResUpdate>(); resUpdate.onCompleteHandler = () => { Destroy(obj); _l.start("main"); }; resUpdate.checkUpdate(); } else { _l.start("main"); } }
// void OnEnable() // { // #if UNITY_5 // Application.logMessageReceived += LGameConfig.GetInstance().HandleLog; // #else // Application.RegisterLogCallback(LGameConfig.HandleLog); // #endif // } // void OnDisable() // { // #if UNITY_5 // Application.logMessageReceived -= LGameConfig.GetInstance().HandleLog; // #else // Application.RegisterLogCallback(null); // #endif // } void Update() { ++frames; float timeNow = Time.realtimeSinceStartup; if (timeNow > lastInterval + updateInterval) { fps = (float)(frames / (timeNow - lastInterval)); frames = 0; lastInterval = timeNow; } if (Input.GetKeyDown(KeyCode.BackQuote) || Input.acceleration.sqrMagnitude > 3) { if (LGameConfig.GetInstance().openGmViewFunc != null) { LGameConfig.GetInstance().openGmViewFunc.Invoke(); } } }
public Sprite[] GetSpritesByName(string bundlePath, string assetName) { string key = bundlePath; if (spritesCache.ContainsKey(key)) { return(spritesCache[key]); } else { if (LGameConfig.GetInstance().isDebug) { Sprite[] sprites = Resources.LoadAll <Sprite>(bundlePath); spritesCache.Add(key, sprites); } else { string bundleName = LGameConfig.GetABNameWithAtlasPath(bundlePath.Split('.')[0] + ".png"); AssetBundle assetBundle = this.GetBundleByName(bundleName); if (assetBundle) { Sprite[] sprites = assetBundle.LoadAllAssets <Sprite>(); spritesCache.Add(key, sprites); } } List <Sprite> _arr = new List <Sprite>(); Sprite[] _sprites = spritesCache[key]; foreach (Sprite s in _sprites) { if (s.name.StartsWith(assetName)) { _arr.Add(s); } } return(_arr.ToArray()); } }
void Start() { Application.targetFrameRate = LGameConfig.DEFAULT_FRAME_RATE; if (_l == null) { if (LGameConfig.GetInstance().isDebug) { LuaState.loaderDelegate = loadFileWithSuffix; } else { LuaState.loaderDelegate = loadLuaWithAb; } _l = new LuaSvr(); _l.init(tick, complete); } else { complete(); } }
public Sprite LoadAtlas(string atlasName, out string txt) { txt = ""; Sprite atlas = null; if (LGameConfig.GetInstance().isDebug) { atlas = Resources.Load <Sprite>(string.Format("Atlas/{0}", atlasName)); txt = Resources.Load <TextAsset>(string.Format("Atlas/{0}", atlasName)).text; } else { AssetBundle b; bundles.TryGetValue(atlasName.ToLower(), out b); if (b != null) { Debug.Log(string.Format(LGameConfig.ASSETBUNDLE_ATLAS_FORMAT, atlasName)); atlas = b.LoadAsset <Sprite>(string.Format(LGameConfig.ASSETBUNDLE_ATLAS_FORMAT, atlasName) + ".png"); txt = b.LoadAsset <TextAsset>(string.Format(LGameConfig.ASSETBUNDLE_ATLAS_FORMAT, atlasName) + ".txt").text; } } return(atlas); }
public static LGameConfig GetInstance() { if (null == m_cInstance) { m_cInstance = new LGameConfig(); } return m_cInstance; }