AssetBundle LoadAssetBundleFile(string assetFile, bool isStreaming)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (isStreaming)
            {
                string path = Application.dataPath + "!assets/" + _streamingPath + assetFile;
                if (ObbAssetLoad.ExistsFile(_streamingPath + assetFile))
                {
                    path = GoogleObbPath.GetMainObbPath() + "/" + _streamingPath + assetFile;
                }

                AssetBundle ab = null;
                try
                {
                    ab = AssetBundle.LoadFromFile(path);
                }
                catch (System.Exception ex)
                {
                    Debugger.LogException(ex);
                }
                if (ab != null)
                {
                    return(ab);
                }
                Debugger.LogError("Read StreamingAssets : " + assetFile + " fail!");
            }
#endif
            if (File.Exists(assetFile))
            {
                AssetBundle ab = null;
                try
                {
                    ab = AssetBundle.LoadFromFile(assetFile);
                }
                catch (System.Exception ex)
                {
                    Debugger.LogException(ex);
                }
                if (ab == null)
                {
                    Debugger.LogError("The file : " + assetFile + " error!!");
                    try
                    {
                        File.Delete(assetFile);
                        PlayerPrefs.SetInt("CHECK_RESOURCE", 0);
                    }
                    catch (Exception ex)
                    {
                        Debugger.LogException(ex);
                    }
                }
                return(ab);
            }
            PlayerPrefs.SetInt("CHECK_RESOURCE", 0);
            Debugger.LogError("The file : " + assetFile + " not exist!!");
            return(null);
        }
Пример #2
0
    public static void Init()
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        if (ApkFile == null)
        {
            ApkFile = new AssetZip();
            ApkFile.Init(GoogleObbPath.GetMainObbPath());
        }
#endif
    }
        public ResourceManager()
        {
#if UNITY_EDITOR
            _dataPath = _optionalPath = _streamingPath = Application.dataPath + "/../../Builds/ExportResources/Windows/";
#elif UNITY_STANDALONE_WIN
#if ILRUNTIME_DEBUG
            if (File.Exists(Application.dataPath + "/DebugPath.txt"))
            {
                string[] lines = File.ReadAllLines(Application.dataPath + "/DebugPath.txt");
                _dataPath        = _optionalPath = _streamingPath = Application.dataPath + lines[0];
                IsILRuntimeDebug = true;
            }
            else
            {
#endif
            _dataPath      = Application.streamingAssetsPath + "/files/";
            _optionalPath  = Application.streamingAssetsPath + "/optional/";
            _streamingPath = Application.streamingAssetsPath + "/GameResources/";
#if ILRUNTIME_DEBUG
        }
#endif
#elif UNITY_ANDROID
            _dataPath      = Application.persistentDataPath + "/files/";
            _optionalPath  = Application.persistentDataPath + "/optional/";
            _streamingPath = "GameResources/";
#elif UNITY_IPHONE
            _dataPath      = Application.persistentDataPath + "/files/";
            _optionalPath  = Application.persistentDataPath + "/optional/";
            _streamingPath = Application.streamingAssetsPath + "/GameResources/";
#else
            throw new Exception("Not supported platform!");
#endif
            Debugger.Log("dataPath : " + _dataPath, true);
            Debugger.Log("optionalPath : " + _optionalPath, true);
            Debugger.Log("streamingPath : " + _streamingPath, true);
#if UNITY_ANDROID && !UNITY_EDITOR
            Debugger.Log("obbPath : " + GoogleObbPath.GetMainObbPath(), true);
#endif
        }