/// <summary> /// 创建一个VIEW /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public BaseUIView CreateView <T>() { BaseUIView uiView = Activator.CreateInstance(typeof(T)) as BaseUIView; //获取UIViewDataAttribute特性 var attr = (UIViewDataAttribute)typeof(T).GetCustomAttributes(typeof(UIViewDataAttribute), true).FirstOrDefault(); if (attr != null) { GameObject uiGameObject = null; //创建UI对象 uiGameObject = UIUtility.Instance.CreateViewEntity(attr.loadPath); Transform parent = GetParent(attr.findType, attr.param); if (uiGameObject == null) { LWDebug.LogError("没有找到这个UI对象" + attr.loadPath); } if (parent == null) { LWDebug.LogError("没有找到这个UI父节点" + attr.param); } if (parent != null) { uiGameObject.transform.SetParent(parent, false); } //初始化UI uiView.CreateView(uiGameObject); } else { LWDebug.Log("没有找到UIViewDataAttribute这个特性"); } LWDebug.Log("UIManager:" + typeof(T).ToString()); return(uiView); }
/// <summary> /// 根据特性 获取父级 /// </summary> /// <param name="findType"></param> /// <param name="param"></param> /// <returns></returns> private Transform GetParent(FindType findType, string param) { Transform ret = null; if (_uiParentDic.ContainsKey(param)) { ret = _uiParentDic[param]; } else if (findType == FindType.Name) { GameObject gameObject = GameObject.Find(param); if (gameObject == null) { LWDebug.LogError(string.Format("当前没有找到{0}这个GameObject对象", param)); } ret = gameObject.transform; _uiParentDic.Add(param, ret); } else if (findType == FindType.Tag) { GameObject gameObject = GameObject.FindGameObjectWithTag(param); if (gameObject == null) { LWDebug.LogError(string.Format("当前没有找到{0}这个Tag GameObject对象", param)); } ret = gameObject.transform; _uiParentDic.Add(param, ret); } return(ret); }
/// <summary> /// 创建VIEW /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent">父节点,当创建子View的时候为必填</param> /// <returns></returns> public BaseUIView CreateView <T>(Transform parent) { BaseUIView uiView = Activator.CreateInstance(typeof(T)) as BaseUIView; //获取UIViewDataAttribute特性 var attr = (UIViewDataAttribute)typeof(T).GetCustomAttributes(typeof(UIViewDataAttribute), true).FirstOrDefault(); if (attr != null) { GameObject uiGameObject = uiGameObject = parent.Find(attr.loadPath).gameObject; if (uiGameObject == null) { LWDebug.LogError("没有找到这个UI对象" + attr.loadPath); } //初始化UI uiView.CreateView(uiGameObject); } else { LWDebug.Log("没有找到UIViewDataAttribute这个特性"); } LWDebug.Log("UIManager:" + typeof(T).ToString()); return(uiView); }
public void Update() { for (var i = 0; i < _assets.Count; i++) { var item = _assets[i]; if (item.Update() || !item.IsUnused()) { continue; } _unusedAssets.Add(item); _assets.RemoveAt(i); i--; } for (var i = 0; i < _unusedAssets.Count; i++) { var item = _unusedAssets[i]; item.Unload(); LWDebug.Log("Unload->" + item.url); } _unusedAssets.Clear(); Bundles.Update(); }
private void OnCompleted() { LWDebug.Log("下载完成"); // MainManager.Instance.StartProcedure(); // Launch(); //启动热更代码 StartCoroutine(MainManager.Instance.GetManager <HotfixManager>().IE_LoadScript(LWUtility.GlobalConfig.hotfixCodeRunMode)); }
private void OnError(string e) { if (onError != null) { onError(e); } LWDebug.LogError("Android 出现 未知错误 需要将target api 修改为 非最高" + e); state = State.Error; }
/// <summary> /// 注册状态机 /// </summary> /// <param name="fsm">状态机</param> public void RegisterFSM(FSMStateMachine fsm) { if (!_fsms.ContainsKey(fsm.Name)) { _fsms.Add(fsm.Name, fsm); } else { LWDebug.Log("当前已经存在这个FMS " + fsm.Name); } }
/// <summary> /// 根据特性去获取对应的所有type /// </summary> /// <typeparam name="T">特性</typeparam> /// <returns></returns> public List <AttributeTypeData> GetTypeListByAttr <T>() { if (!attrTypeHotfixDic.ContainsKey(typeof(T).FullName)) { LWDebug.LogWarning("当前域下找不到这个包含这个特性的类" + typeof(T).FullName); return(null); } else { return(attrTypeHotfixDic[typeof(T).FullName]); } }
/// <summary> /// 移除已注册的状态机 /// </summary> /// <param name="fsm">状态机</param> public void UnRegisterFSM(FSMStateMachine fsm) { if (_fsms.ContainsKey(fsm.Name)) { _fsms[fsm.Name].ClearFMS(); _fsms.Remove(fsm.Name); } else { LWDebug.Log("不存在这个FMS " + fsm.Name); } }
private AssetRequest Load(string path, Type type, bool async) { if (string.IsNullOrEmpty(path)) { Debug.LogError("invalid path"); return(null); } for (int i = 0, max = _assets.Count; i < max; i++) { var item = _assets[i]; if (!item.url.Equals(path)) { continue; } item.Retain(); return(item); } string assetBundleName; AssetRequest asset; if (GetAssetBundleName(path, out assetBundleName)) { asset = async ? new BundleAssetAsyncRequest(assetBundleName) : new BundleAssetRequest(assetBundleName); } else { if (path.StartsWith("http://", StringComparison.Ordinal) || path.StartsWith("https://", StringComparison.Ordinal) || path.StartsWith("file://", StringComparison.Ordinal) || path.StartsWith("ftp://", StringComparison.Ordinal) || path.StartsWith("jar:file://", StringComparison.Ordinal)) { asset = new WebAssetRequest(); } else { asset = new AssetRequest(); } } asset.url = path; asset.assetType = type; _assets.Add(asset); asset.Load(); asset.Retain(); LWDebug.Log(string.Format("Load->{0}|{1}", path, assetBundleName)); return(asset); }
/// <summary> /// 获取状态 /// </summary> /// <param name="type">状态类型</param> /// <returns>状态实例</returns> public BaseFSMState GetState(Type type) { if (_stateDic.ContainsKey(type)) { return(_stateDic[type]); } else { LWDebug.LogError(""); return(null); // throw new HTFrameworkException(HTFrameworkModule.FSM, "获取状态失败:有限状态机 " + Name + " 不存在状态 " + type.Name + "!"); } }
public async UniTask <int> InitSQLite() { if (!FileTool.ExistsFile("DataBase.db")) { LWDebug.Log("复制数据库"); var request = UnityWebRequest.Get(Application.streamingAssetsPath + "/DataBase.db"); await request.SendWebRequest(); FileTool.WriteByteToFile("DataBase.db", request.downloadHandler.data, Application.persistentDataPath); } db = new DBAccess("URI=file:" + DBPath); return(1); }
public T GetManager <T>() { IManager manager; if (_managerDic.TryGetValue(typeof(T).ToString(), out manager)) { return((T)_managerDic[typeof(T).ToString()]); } else { LWDebug.LogError(typeof(T).ToString() + " 这个Manager 不存在,请先检查是否加入了ManagerClass特性"); return((T)manager); } }
public void OpenDB(string connectionString) { try { dbConnection = new SqliteConnection(connectionString); dbConnection.Open(); LWDebug.Log("Connected to db"); } catch (Exception e) { LWDebug.LogError(e.ToString()); } }
/// <summary> /// 处理消息 /// </summary> /// <param name="type">不传参数的情况下使用</param> public void Dispatcher(string type) { if (!dict.ContainsKey(type)) { LWDebug.LogWarning("找不到" + type + "这个事件"); return; } Message msg = MessagePool.GetMessage(); for (int i = 0; dict.ContainsKey(type) && i < dict[type].Count; i++) { dict[type][i](msg); } MessagePool.AddMessage(msg); }
/// <summary> /// 获取页面html /// </summary> /// <param name="url">请求的地址</param> /// <param name="encoding">编码方式</param> /// <returns></returns> private static string HttpGetPageHtml(string url, string encoding) { string pageHtml = string.Empty; try { using (WebClient MyWebClient = new WebClient()) { Encoding encode = Encoding.GetEncoding(encoding); MyWebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36"); MyWebClient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData = MyWebClient.DownloadData(url); //从指定网站下载数据 pageHtml = encode.GetString(pageData); } } catch (Exception e) { LWDebug.Log(e.StackTrace); } return(pageHtml); }
/// <summary> /// 加载Dll热更脚本 /// </summary> /// <param name="root">路径</param> /// <param name="mode"></param> /// <returns></returns> public IEnumerator IE_LoadScript(HotfixCodeRunMode mode) { string dllPath = ""; if (Application.isEditor) { //这里情况比较复杂,Mobile上基本认为Persistent才支持File操作, dllPath = Application.streamingAssetsPath + "/Hotfix/" + LWUtility.HotfixFileName; } else { //这里情况比较复杂,Mobile上基本认为Persistent才支持File操作, //可寻址目录也只有 StreamingAsset var firstPath = FileTool.CombinePaths(LWUtility.updatePath, LWUtility.HotfixFileName); //LWUtility.updatePath + "/" + LWUtility.HotfixFileName; var secondPath = FileTool.CombinePaths(Application.streamingAssetsPath, LWUtility.AssetBundles, LWUtility.GetPlatform(), LWUtility.HotfixFileName); // Application.streamingAssetsPath + "/" + LWUtility.AssetBundles + "/" + LWUtility.GetPlatform() + "/" + LWUtility.HotfixFileName; if (!File.Exists(firstPath)) { var request = UnityWebRequest.Get(secondPath); LWDebug.Log("firstPath:" + firstPath); LWDebug.Log("secondPath:" + secondPath); yield return(request.SendWebRequest()); if (request.isDone && request.error == null) { LWDebug.Log("request.downloadHandler.data:" + request.downloadHandler.data.Length); LWDebug.Log("拷贝dll成功:" + firstPath); byte[] results = request.downloadHandler.data; FileTool.WriteByteToFile(firstPath, results, ""); } } dllPath = firstPath; } LWDebug.Log("Dll路径:" + dllPath); //反射执行 if (mode == HotfixCodeRunMode.ByReflection) { var bytes = File.ReadAllBytes(dllPath); var mdb = dllPath + ".mdb"; if (File.Exists(mdb)) { var bytes2 = File.ReadAllBytes(mdb); Assembly = Assembly.Load(bytes, bytes2); } else { Assembly = Assembly.Load(bytes); } //Debug.Log("反射模式,开始执行Start"); //var type = Assembly.GetType("StartupBridge_Hotfix"); //var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static); //method.Invoke(null, new object[] { false }); StartupBridge_Hotfix.StartReflection(Assembly); } #if ILRUNTIME //解释执行 else if (mode == HotfixCodeRunMode.ByILRuntime) { //解释执行模式 // ILRuntimeHelper.LoadHotfix(dllPath); // ILRuntimeHelper.AppDomain.Invoke("StartupBridge_Hotfix", "Start", null, new object[] { true }); } #endif else if (mode == HotfixCodeRunMode.ByCode) { LWDebug.Log("内置code模式!", LogColor.green); StartupBridge_Hotfix.StartCode(); //反射调用,防止编译报错 //Assembly assembly = Assembly.GetExecutingAssembly(); //var type = assembly.GetType("StartupBridge_Hotfix"); //var method = type.GetMethod("Start", BindingFlags.Public | BindingFlags.Static); //method.Invoke(null, new object[] { false }); } }
private static void Update(Message msg) { LWDebug.Log("Update"); }
private void OnError(string obj) { LWDebug.Log(obj); // MainManager.Instance.StartProcedure(); StartCoroutine(MainManager.Instance.GetManager <HotfixManager>().IE_LoadScript(LWUtility.GlobalConfig.hotfixCodeRunMode)); }
void LogSql(string sqlStr) { LWDebug.Log(sqlStr); }
/** * public void Initialize(Action onSuccess, Action<string> onError) * { * * if (string.IsNullOrEmpty(LWUtility.dataPath)) LWUtility.dataPath = Application.streamingAssetsPath; * * LWDebug.Log(string.Format("Init->assetBundleMode: {0} | dataPath :{1}| connServer :{2}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath, LWUtility.GlobalConfig.connServer), LogColor.green); * * if (LWUtility.GlobalConfig.assetBundleMode) * { * updatePath = LWUtility.updatePath; * var platform = LWUtility.GetPlatform(); * //默认资源路径 * var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) + * Path.DirectorySeparatorChar; * Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL; * * Bundles.Initialize(path, platform, () => * { * var asset = LoadAsync(LWUtility.AssetsManifestAsset, typeof(Manifest)); * asset.completed += obj => * { * var manifest = obj.asset as Manifest; * if (manifest == null) * { * if (onError != null) onError("manifest == null"); * return; * } * * if (string.IsNullOrEmpty(LWUtility.downloadURL)) //将下载地址放在全局配置文件中 * LWUtility.downloadURL = manifest.downloadURL; * Bundles.activeVariants = manifest.activeVariants; * _bundles = manifest.bundles; * var dirs = manifest.dirs; * _bundleAssets = new Dictionary<string, int>(manifest.assets.Length); * for (int i = 0, max = manifest.assets.Length; i < max; i++) * { * var item = manifest.assets[i]; * _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle; * } * * if (onSuccess != null) * onSuccess(); * obj.Release(); * }; * }, onError); * } * else * { * if (onSuccess != null) * onSuccess(); * } * } * */ public async UniTask <AssetsManagerRequest> InitializeAsync() { AssetsManagerRequest assetsManagerRequest = new AssetsManagerRequest { isSuccess = true }; if (string.IsNullOrEmpty(LWUtility.dataPath)) { LWUtility.dataPath = Application.streamingAssetsPath; } LWDebug.Log(string.Format("Init->assetBundleMode {0} | dataPath {1}", LWUtility.GlobalConfig.assetBundleMode, LWUtility.dataPath), LogColor.green); //判断当前是否为AB模式 if (LWUtility.GlobalConfig.assetBundleMode) { updatePath = LWUtility.updatePath; var platform = LWUtility.GetPlatform(); //默认资源路径 var path = Path.Combine(LWUtility.dataPath, Path.Combine(LWUtility.AssetBundles, platform)) + Path.DirectorySeparatorChar; Bundles.OverrideBaseDownloadingUrl += Bundles_overrideBaseDownloadingURL; //初始化Bundles BundleRequest bundleRequest = await Bundles.Initialize(path, platform); //Bundle加载出错 if (bundleRequest.error != null) { assetsManagerRequest.isSuccess = false; assetsManagerRequest.error = bundleRequest.error; bundleRequest.Release(); bundleRequest = null; return(assetsManagerRequest); } else { //加载资源的Manifest文件 var assetRequest = await LoadAsyncTask <Manifest>(LWUtility.AssetsManifestAsset); var manifest = assetRequest.asset as Manifest; if (manifest == null) { assetsManagerRequest.isSuccess = false; assetsManagerRequest.error = "manifest == null"; return(assetsManagerRequest); } //设置资源的下载地址,在编辑器下会读取当前Assets下的Manifest。 if (string.IsNullOrEmpty(LWUtility.downloadURL)) { LWUtility.downloadURL = manifest.downloadURL; } Bundles.activeVariants = manifest.activeVariants; _bundles = manifest.bundles; var dirs = manifest.dirs; _bundleAssets = new Dictionary <string, int>(manifest.assets.Length); for (int i = 0, max = manifest.assets.Length; i < max; i++) { var item = manifest.assets[i]; _bundleAssets[string.Format("{0}/{1}", dirs[item.dir], item.name)] = item.bundle; } assetRequest.Release(); bundleRequest.Release(); bundleRequest = null; return(assetsManagerRequest); } } else { return(assetsManagerRequest); } }
private static void LateUpdate(Message msg) { LWDebug.Log("LateUpdate"); //iManager.LateUpdate(); }