public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); luaScriptPathObj = EditorGUILayout.ObjectField("luaScriptPathObj", luaScriptPathObj, typeof(Object), false); string pathTemp = AssetDatabase.GetAssetPath(luaScriptPathObj); if (pathTemp.Contains(LuaRootPath)) { if (pathTemp.EndsWith(".lua")) { string pathOff = pathTemp.Replace(LuaRootPath, ""); luaScriptPath.stringValue = pathOff; EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); } else { GLog.Error("File must EndsWith lua... filter suggest:" + target.name); } } else { GLog.Error("File must in:" + LuaRootPath + "... filter suggest:" + target.name); } }
void Awake() { if (!string.IsNullOrEmpty(luaScriptPath)) { scriptEnv = LuaManager.Instance.luaEnv.NewTable(); LuaTable meta = LuaManager.Instance.luaEnv.NewTable(); meta.Set("__index", LuaManager.Instance.luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); LuaManager.Instance.luaEnv.DoString(LuaManager.Instance.DoLoad(luaScriptPath), luaScriptPath, scriptEnv); Action luaAwake = scriptEnv.Get <Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } } else { GLog.Error("luaScriptPath is null :" + gameObject.name); } }
public static void SendEvent(string eventName, params object[] param) { if (eventName == GameEventType.GameFlow) { GameFlow gf = (GameFlow)(param[0]); GLog.Log("GameFlow:" + (int)gf + " : " + gf.ToString(), Color.yellow); } List <System.Action <object[]> > evtList; if (eventDic.TryGetValue(eventName, out evtList)) { System.Action <object[]>[] evts = evtList.ToArray(); foreach (System.Action <object[]> evt in evts) { if (evt != null) { try { evt(param); } catch (Exception ex) { GLog.Error(ex.Message + "\n" + ex.StackTrace); } } } } }
private static void SetABName(List <string> files, bool setName = true) { GLog.Log("BuildAssets Count " + files.Count, true); for (int i = 0; i < files.Count; i++) { string filePath = files[i]; string assetPath = filePath.Substring(Application.dataPath.Length - "assets".Length); AssetImporter ai = AssetImporter.GetAtPath(assetPath); GemaEditor.ShowProgress(i, files.Count, "SetAssetLabels", ai.assetPath); string abName = AanalyzeAssetLabels(assetPath); GLog.Log(string.Format("No.{0} abName:{1} assetPath:{2}", i + 1, abName, assetPath), true); if (setName) { ai.assetBundleName = abName; ai.assetBundleVariant = "ab"; } else { ai.assetBundleName = null; //ai.assetBundleVariant = null; } string fileName = Path.GetFileName(ai.assetPath); fileName = fileName.Split('.')[0]; string importerName = ai.GetType().ToString().Split('.')[1]; string typename = importerName.Substring(0, importerName.Length - 8); List <string> listAsset; if (!typeAssets.TryGetValue(typename, out listAsset)) { listAsset = new List <string>(); typeAssets.Add(typename, listAsset); } if (listAsset.IndexOf(fileName) != -1) { GLog.Error("Repeat name " + fileName + " type " + typename, true); return; } listAsset.Add(fileName); ABConfigInfo abConfigInfo = abConfig.GetInfoByAB(abName); if (abConfigInfo == null) { abConfigInfo = new ABConfigInfo(); abConfig.AddInfo(abConfigInfo); resourceCount++; abConfigInfo.id = resourceCount; abConfigInfo.ab = abName; abConfigInfo.type = typename; } abConfigInfo.names.Add(fileName); } EditorUtility.ClearProgressBar(); }
IEnumerator LoadAsyncImpl <T>(string abName, string assetName, System.Action <T> finishLoad) where T : UnityEngine.Object { #if UNITY_EDITOR if (!bundleLoadMode)//编辑器下的非Bundle加载模式 { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abName, assetName); T target = null; if (assetPaths.Length > 0) { target = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]); } yield return(null); if (finishLoad != null) { finishLoad(target); } yield break; } #endif yield return(StartCoroutine(LoadAssetBundle(abName))); AssetBundleInfo abInfo = null; if (assetBundleInfoDic.TryGetValue(abName, out abInfo)) { AssetBundleRequest abRequest = abInfo.ab.LoadAssetAsync <T>(assetName); //abRequest.priority; while (!abRequest.isDone) { yield return(null); } T res = abRequest.asset as T; if (res == null) { GLog.Warning("assetName :" + assetName + " not find"); } finishLoad(res); abInfo.TakeAsset(assetName); } else { GLog.Error(abName + " is not find~"); } }
IEnumerator OnLoadFile(string url, DownloadProgress downloadProgress) { UnityWebRequest uwr = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET); MyDownloadHandler myDownloadHandler = new MyDownloadHandler(preAllocatedBuffer, downloadProgress); uwr.downloadHandler = myDownloadHandler; yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { GLog.Error(uwr.error); if (downloadProgress != null) { downloadProgress(0, null, false); } } }
private static void OnCreateSetting <T>() where T : ScriptableObject { ScriptableObject setting = ScriptableObject.CreateInstance <T>(); if (setting == null) { GLog.Error("Setting ScriptableObject is not fund:" + typeof(T).ToString()); return; } string settingPath = string.Format("Assets/Resources/{0}.asset", typeof(T).ToString()); var tExist = File.Exists(settingPath); if (!tExist) { AssetDatabase.CreateAsset(setting, settingPath); } }
/// <summary> /// 从接收到数据开始每帧调用直至结束 /// </summary> /// <param name="data"></param> /// <param name="dataLength"></param> /// <returns>ture 继续 false 终止</returns> protected override bool ReceiveData(byte[] data, int dataLength) { //base.ReceiveData(data, dataLength); if (data == null || data.Length < 1) { GLog.Error("MyDownloadHandler :: ReceiveData - received a null/empty buffer"); if (downloadProgress != null) { downloadProgress(dataLength, data, false); } return(false); } loadedLength += dataLength; if (downloadProgress != null) { downloadProgress(dataLength, data, false); } return(true); }
IEnumerator OnLoadText(string url, Action <string> finishLoad) { UnityWebRequest uwr = new UnityWebRequest(url); uwr.downloadHandler = new DownloadHandlerBuffer(); yield return(uwr.SendWebRequest()); if (uwr.isNetworkError || uwr.isHttpError) { GLog.Error(uwr.error); } else { if (finishLoad != null) { finishLoad(uwr.downloadHandler.text); } } }
private void LoadRemotePatchFiles() { GameEvent.SendEvent(GameEventType.GameFlow, GameFlow.PatchFileRemoteLoad); remotePatchFiles = new PatchFiles(); string remotePatchFilesPath = PathUtil.RemotePatchFilesPath(); GLog.Log("remotePatchFilesPath " + remotePatchFilesPath); if (File.Exists(remotePatchFilesPath)) { HttpManager.Instance.LoadText(remotePatchFilesPath, (res) => { remotePatchFiles.Load(res); CompareLocalAndRemotePatchFiles(); }); } else { GLog.Error(string.Format("{0} is null", remotePatchFilesPath), true); } }
public static bool EnsureDirectory(string path) { try { path.Replace("\\", "/"); if (path.Contains(".")) { path = path.Substring(0, path.LastIndexOf("/") + 1); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return(true); } catch (Exception e) { GLog.Error(e.ToString()); } return(false); }
public void GetGameObject(string fileName, System.Action <GameObject> callBack) { LoadAsync <GameObject>(fileName, (res) => { if (res == null) { GLog.Error("error file name : " + fileName); return; } GameObject obj; ObjectPool <GameObject> pool; if (gameObjectDic.TryGetValue(fileName, out pool)) { if (pool.template == null) { //UI内存路线:模板 对象池 引用 3 pool.template = res; pool.keepTime = ObjectPool <GameObject> .ReferenceTime; } } else { pool = new ObjectPool <GameObject>(res); pool.keepTime = ObjectPool <GameObject> .ReferenceTime; gameObjectDic[fileName] = pool; } //UI内存路线:模板 对象池 引用 4 obj = pool.Request(); obj.GetOrCreate <ResPath>().resPath = fileName; obj.SetActive(true); if (callBack != null) { callBack(obj); } }); }
private void HandlePatch() { GameEvent.SendEvent(GameEventType.GameFlow, GameFlow.PatchFileLocalLoad); localPatchFiles = new PatchFiles(); string localPatchFilesPath = PathUtil.LocalPatchFilesPath(); if (File.Exists(localPatchFilesPath)) { GLog.Log("localPatchFilesPath " + localPatchFilesPath); HttpManager.Instance.LoadText(localPatchFilesPath, (res) => { localPatchFiles.Load(res); LoadRemotePatchFiles(); }); } else { string streamingPatchFilesPath = PathUtil.StreamingPatchFilesPath(); if (File.Exists(streamingPatchFilesPath)) { GLog.Log("localPatchFilesPath " + streamingPatchFilesPath); HttpManager.Instance.LoadText(streamingPatchFilesPath, (res) => { File.WriteAllText(localPatchFilesPath, res); localPatchFiles.Load(res); LoadRemotePatchFiles(); }); } else { GLog.Error(string.Format("{0} is not find", streamingPatchFilesPath), true); } } }