Ejemplo n.º 1
0
    /// 取得数据存放目录

    /*
     * public static string DataPath {
     * get {
     *  string game = Const.AppName.ToLower();
     *  string dataPath = Application.dataPath;
     *
     *  if (Application.platform == RuntimePlatform.IPhonePlayer) {
     *      string path = Path.GetDirectoryName(Path.GetDirectoryName(dataPath));
     *      return Path.Combine(path, "Documents/" + game + "/");
     *  } else if (Application.platform == RuntimePlatform.Android) {
     *      return "/sdcard/" + game + "/";
     *  }
     *  if (Const.DebugMode) {
     *      string target = string.Empty;
     *      if (Application.platform == RuntimePlatform.OSXEditor ||
     *          Application.platform == RuntimePlatform.IPhonePlayer ||
     *          Application.platform == RuntimePlatform.OSXEditor) {
     *          target = "iphone";
     *      } else {
     *          target = "android";
     *      }
     *      return dataPath + "/StreamingAssets/" + target + "/";
     *  }
     *  return "c:/" + game + "/";
     * }
     * }
     */

    public static byte[] ReadFile(string path)
    {
        byte[] str = null;
#if UNITY_IPHONE
        // 文档中说:WWW.isDone不能用循环的,需要用coroutines,此处的用法不合适,待修改  (lijian 20151021)
        path = path.Replace("file://", "");
#endif

#if  UNITY_EDITOR || UNITY_STANDALONE_WIN               //只在windows下起作用
        bool bUseFile = (EntryPoint.Instance.DebugSettingParams.LocalData && path.Contains("GameRes/Data")) ||
                        (EntryPoint.Instance.DebugSettingParams.LocalLua && path.Contains("GameRes/Lua"));

        if (bUseFile)
        {
            if (File.Exists(path))
            {
                try
                {
                    str = File.ReadAllBytes(path);
                }
                catch (Exception e)
                {
                    str = null;
                    Common.HobaDebuger.LogError("failed to read File with path: " + path + ": " + e);
                }
            }
            else
            {
                Common.HobaDebuger.Log("file: " + path + " File does not exist");
            }
        }
        else            //FileImage
#endif
        {
            if (FileImage.IsExist(path))
            {
                try
                {
                    str = FileImage.ReadAllBytes(path);
                }
                catch (Exception e)
                {
                    str = null;
                    Common.HobaDebuger.LogWarning("failed to read FileImage with path: " + path + ": " + e);
                }
            }
            else
            {
                Common.HobaDebuger.Log("file: " + path + " FileImage does not exist");
            }
        }

        return(str);
    }