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
        }
        public void Init()
        {
#if !UNITY_EDITOR
            bool newVersion = PlayerPrefs.GetFloat("CLIENT_CODE_VERSION", -1) != CodeVersion;
#if UNITY_ANDROID
            int nativeVersionCode = GoogleObbPath.GetApkVerCode();
#elif UNITY_IPHONE
            int nativeVersionCode = IOSVersionCode.GetIOSVersionCode();
#else
            int nativeVersionCode = 0;
#endif

            if (PlayerPrefs.GetInt("NATIVE_VERSION_CODE", -1) != nativeVersionCode)
            {
                newVersion = true;
            }

            Debugger.Log("newVersion : " + newVersion, true);
            if (newVersion)
            {
                if (!GameClient.Instance.BuildSettings.MiniBuild)
                {
                    if (Directory.Exists(_dataPath))
                    {
                        Directory.Delete(_dataPath, true);
                    }
                    Directory.CreateDirectory(_dataPath);

                    CopyStreamingFile("ResourceList.ab", _dataPath + "ResourceList.ab");
                }
                else
                {
                    if (!File.Exists(_dataPath + "ResourceList.ab"))
                    {
                        if (Directory.Exists(_dataPath))
                        {
                            Directory.Delete(_dataPath, true);
                        }
                        Directory.CreateDirectory(_dataPath);

                        CopyStreamingFile("ResourceList.ab", _dataPath + "ResourceList.ab");
                    }
                    else
                    {
#if UNITY_ANDROID
                        ResourceDatas newDatas = LoadResourceDatas(GetStreamingFile("ResourceList.ab"));
#else
                        ResourceDatas newDatas = LoadResourceDatas(_streamingPath + "ResourceList.ab");
#endif
                        if (newDatas != null)
                        {
                            ResourceDatas datas = LoadResourceDatas(_dataPath + "ResourceList.ab");
                            var           e     = newDatas.Resources.GetEnumerator();
                            while (e.MoveNext())
                            {
                                string filename = _dataPath + GetResourceFileName(e.Current.Key);
                                if (File.Exists(filename))
                                {
                                    File.Delete(filename);
                                }

                                if (datas != null)
                                {
                                    if (!datas.Resources.ContainsKey(e.Current.Key))
                                    {
                                        datas.Resources.Add(e.Current.Key, e.Current.Value);
                                    }
                                    else
                                    {
                                        datas.Resources[e.Current.Key] = e.Current.Value;
                                    }
                                }
                            }

                            if (datas != null)
                            {
                                SaveResourceDatas(_dataPath + "ResourceList.ab", datas);
                            }
                        }
                    }
                }

                PlayerPrefs.SetFloat("CLIENT_CODE_VERSION", CodeVersion);
                PlayerPrefs.SetInt("NATIVE_VERSION_CODE", nativeVersionCode);
                PlayerPrefs.Save();
            }
#endif

            LoadResourceList();
        }