Example #1
0
    //根据不同平台获取相应的Stream
    public static Stream ReadStreamAssetFileByStream(string dir, string fileName, int offset = 0)
    {
        var path = GetStreamAssetFilePath(dir, fileName);

        if (!CheckStreamExistsFile(path))
        {
            return(null);
        }
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        var result = File.OpenRead(path);
        if (offset != 0)
        {
            result.Seek(offset, SeekOrigin.Begin);
        }
        return(result);
#elif UNITY_ANDROID
#if OBB
        var result = FileMapSystem.Obb.AndroidFileUtils_ObbMode.OpenRead(path);
        if (offset != 0)
        {
            result.Seek(offset, SeekOrigin.Begin);
        }
        return(result);
#else
        return(AndroidFileUtils.OpenFileStream(path, offset));
#endif
#else
        var result = File.OpenRead(path);
        if (offset != 0)
        {
            result.Seek(offset, SeekOrigin.Begin);
        }
        return(result);
#endif
    }
Example #2
0
    public static string[] GetStreamAssetFileList(string dir)
    {
        var path = GetStreamAssetFilePath(dir, "");

#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        var filePath  = Directory.GetFiles(path);
        var fileNames = new string[filePath.Length];
        for (int i = 0; i < filePath.Length; i++)
        {
            fileNames[i] = System.IO.Path.GetFileName(filePath[i]);
        }
        return(fileNames);
#elif UNITY_ANDROID
#if OBB
        return(FileMapSystem.Obb.AndroidFileUtils_ObbMode.GetAllFileNames(path));
#else
        return(AndroidFileUtils.GetAndroidAssetFileList(path));
#endif
#else
        var filePath  = Directory.GetFiles(path);
        var fileNames = new string[filePath.Length];
        for (int i = 0; i < filePath.Length; i++)
        {
            fileNames[i] = System.IO.Path.GetFileName(filePath[i]);
        }
        return(fileNames);
#endif
    }
 void Start()
 {
             #if UNITY_ANDROID
     AndroidFileUtils.Unpack8iAssets();
     LoadNextScene();
             #else
     LoadNextScene();
             #endif
 }
Example #4
0
    //根据不同平台获取相应的字节数据
    public static byte[] ReadStreamAssetFileAllBytes(string dir, string fileName, int offset, int len)
    {
        var path = GetStreamAssetFilePath(dir, fileName);

        if (!CheckStreamExistsFile(path))
        {
            return(null);
        }

        //return AndroidFileUtils.ReadFile(path);
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        using (var result = File.OpenRead(path))
        {
            var bs = new byte[len];
            if (offset != 0)
            {
                result.Seek(offset, SeekOrigin.Begin);
            }
            result.Read(bs, 0, len);
            return(bs);
        }
#elif UNITY_ANDROID
#if OBB
        var result = FileMapSystem.Obb.AndroidFileUtils_ObbMode.OpenRead(path);
        if (offset != 0)
        {
            result.Seek(offset, SeekOrigin.Begin);
        }
        if (len == -1)
        {
            len = (int)(result.Length - offset);
        }
        byte[] buffer = new byte[len];
        result.Read(buffer, 0, len);
        return(buffer);
#else
        return(AndroidFileUtils.ReadFile(path, offset, len));
#endif
#else
        using (var result = File.OpenRead(path))
        {
            var bs = new byte[len];
            if (offset != 0)
            {
                result.Seek(offset, SeekOrigin.Begin);
            }
            result.Read(bs, 0, len);
            return(bs);
        }
#endif
    }
Example #5
0
    public static bool CheckStreamExistsFile(string path)
    {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        return(File.Exists(path));
#elif UNITY_ANDROID
#if OBB
        return(FileMapSystem.Obb.AndroidFileUtils_ObbMode.CheckStreamExistsFile(path));
#else
        return(AndroidFileUtils.CheckExistsInAndroidAsset(path));
#endif
#else
        return(File.Exists(path));
#endif
    }
Example #6
0
    //根据不同平台读取字符串数据
    public static string GetStreamStringAllPlatform(string path)
    {
        if (!CheckStreamExistsFile(path))
        {
            return("");
        }
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        return(File.ReadAllText(path));
#elif UNITY_ANDROID
        return(AndroidFileUtils.ReadTextFile(path));
#else
        return(File.ReadAllText(path));
#endif
    }
Example #7
0
    public static void InitForMainThread()
    {
        //初始化Application路径
        var d = DataPath;
        var s = StreamingAssetsPath;
        var p = PersistenPath;

#if UNITY_ANDROID && !UNITY_EDITOR
#if OBB
        FileMapSystem.Obb.AndroidFileUtils_ObbMode.Init();
#else
        AndroidFileUtils.Init();
#endif
#endif
    }
Example #8
0
        string GetDataLocation()
        {
            string dataFolder = "";

            if (Application.isEditor)
            {
#if UNITY_EDITOR
                if (data != null)
                {
                    string projectAssetPath = Application.dataPath;
                    projectAssetPath = projectAssetPath.Substring(0, projectAssetPath.Length - 6);

                    dataFolder = projectAssetPath + AssetDatabase.GetAssetPath(data);
                }
#endif
            }
            else if (Application.platform == RuntimePlatform.Android)
            {
                string buildDataFolder = AndroidFileUtils.GetExternalPublicDirectory("8i/" + uniqueID);

                if (Directory.Exists(buildDataFolder))
                {
                    dataFolder = buildDataFolder;
                }
            }
            else if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                string buildDataFolder = Application.dataPath + "/8i/" + uniqueID + "/";

                if (Directory.Exists(buildDataFolder) || File.Exists(buildDataFolder))
                {
                    dataFolder = buildDataFolder;
                }
            }
            else
            {
                string buildDataFolder = Application.dataPath + "/../8i/" + uniqueID;
                dataFolder = buildDataFolder;
            }

            return(dataFolder);
        }
Example #9
0
    //根据不同平台获取相应的字节数据
    public static byte[] ReadStreamAssetFileAllBytes(string dir, string fileName)
    {
        var path = GetStreamAssetFilePath(dir, fileName);

        if (!CheckStreamExistsFile(path))
        {
            return(null);
        }
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        return(File.ReadAllBytes(path));
#elif UNITY_ANDROID
#if OBB
        return(FileMapSystem.Obb.AndroidFileUtils_ObbMode.ReadAllBytes(path));
#else
        return(AndroidFileUtils.ReadFile(path));
#endif
#else
        return(File.ReadAllBytes(path));
#endif
    }
        public static string GetBuildDataPath()
        {
            string path = string.Empty;

            switch (Application.platform)
            {
            case RuntimePlatform.WindowsPlayer:
            case RuntimePlatform.OSXPlayer:
            case RuntimePlatform.LinuxPlayer:
            case RuntimePlatform.IPhonePlayer:
                path = Application.dataPath + Path.DirectorySeparatorChar + Uniforms.buildDataPath + Path.DirectorySeparatorChar;
                break;

            case RuntimePlatform.Android:
                path = AndroidFileUtils.GetInternalStorageDirectory() + Path.DirectorySeparatorChar + Uniforms.buildDataPath + Path.DirectorySeparatorChar;
                break;

            default:
                break;
            }

            return(path);
        }