// 一个模板函数,用来加载放在Assets\StreamingAssets\Data目录下的json配置 public static List <T> LoadJsonConfigs <T>(string configPath) { List <T> configItems = null; #if UNITY_STANDALONE || UNITY_IPHONE configPath = Application.streamingAssetsPath + "/" + configPath; if (false == File.Exists(configPath)) { Debug.Log("DialogManage::LoadDialogs File Not Exists! " + configPath); return(null); } StreamReader sr = new StreamReader(configPath); JsonSerializer serializer = new JsonSerializer(); List <T> nodes = (List <T>)serializer.Deserialize(new JsonTextReader(sr), typeof(List <T>)); configItems = nodes; sr.Dispose(); #elif UNITY_ANDROID string strJson = AndroidAssetLoadSDK.LoadTextFile(configPath); List <T> nodes = JsonConvert.DeserializeObject <List <T> >(strJson); configItems = nodes; #endif return(configItems); }
public static byte[] CustomLoader(ref string filepath) { string scriptPath = string.Empty; filepath = filepath.Replace(".", "/") + ".lua"; scriptPath = "LuaScripts/" + filepath; #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode || AssetBundleConfig.IsSimulateMode_UseLuaScripts) { scriptPath = Path.Combine(Application.dataPath, luaScriptsFolder); scriptPath = Path.Combine(scriptPath, filepath); //Logger.Log("Load lua script : " + scriptPath); return(UtilityGame.SafeReadAllBytes(scriptPath)); } #endif //优先读取可写目录文件 string realPath = FileUtil.GetWritePath(scriptPath); if (File.Exists(realPath)) { return(UtilityGame.SafeReadAllBytes(realPath)); } #if UNITY_ANDROID && !UNITY_EDITOR byte[] bytes = AndroidAssetLoadSDK.LoadFile(scriptPath); if (bytes != null) { return(bytes); } #else //优先读取可写目录文件 realPath = FileUtil.GetReadOnlyPath(scriptPath); if (File.Exists(realPath)) { return(UtilityGame.SafeReadAllBytes(realPath)); } #endif Logger.LogError($"Lua File Not Found:({scriptPath})"); // scriptPath = string.Format("{0}/{1}.bytes", luaAssetbundleAssetName, filepath); // string assetbundleName = null; // string assetName = null; // bool status = AssetBundleManager.Instance.MapAssetPath(scriptPath, out assetbundleName, out assetName); // if (!status) // { // Logger.LogError("MapAssetPath failed : " + scriptPath); // return null; // } // var asset = AssetBundleManager.Instance.GetAssetCache(assetName) as TextAsset; // if (asset != null) // { // //Logger.Log("Load lua script : " + scriptPath); // return asset.bytes; // } // Logger.LogError("Load lua script failed : " + scriptPath + ", You should preload lua assetbundle first!!!"); return(null); }