예제 #1
0
        private IEnumerator checkNetworkConnections()
        {
            mNeedCheckNetWorkConnections = true;
            //检测网络
            string url  = ResourceCommon.getServerPath("checkNetworkConnections.bytes");
            float  star = System.DateTime.Now.Second;

            while (true)
            {
                WWW www = new WWW(checkUrl(ref url));
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    if (www.text == "true")
                    {
                        mNeedCheckNetWorkConnections = false;
                        www.Dispose();
                        break;
                    }
                }
                www.Dispose();
                float end = System.DateTime.Now.Second - star;
                if (end > mCheckNetWorkConnectionsMaxTimes)
                {
                    mNetworkConnections = false;
                }
            }
        }
예제 #2
0
        private void downLoadAssets()
        {
            if (0 == mUpdateAssets.Count)
            {
                StartCoroutine(downLoad(ResourceCommon.getServerPath("Version.bytes"), delegate(WWW serverVersion)
                {
                    //4.覆盖本地version.xml
                    ReplaceLocalRes("Version.bytes", serverVersion.bytes);

                    OnUpdateComplete();
                    mComplete = true;
                }));
                return;
            }

            string file = mUpdateAssets[0];

            mUpdateAssets.RemoveAt(0);
            ++mCurrentDownLoadSize;
            mCurrentDownLoadBytes += mUpdateAssetsSize[0];
            mUpdateAssetsSize.RemoveAt(0);

            StartCoroutine(downLoad(ResourceCommon.getServerPath(file), delegate(WWW w)
            {
                //将下载的资源替换为本地的资源
                ReplaceLocalRes(file, w.bytes);
                downLoadAssets();
            }));
        }
예제 #3
0
        public static IEnumerator _CreateFromMemory(string path, Handle_CreateFromMemory handle)
        {
            int size = 0;
            AssetBundleCreateRequest bundleRequest = AssetBundle.LoadFromMemoryAsync(ResourceCommon.getAssetBundleFileBytes(path, ref size));

            yield return(bundleRequest);

            handle(bundleRequest, size);
        }
        public void Dispose()
        {
            ResourceCommon.Log("Destory " + mPath);

            if (null != mAssetBundle)
            {
                //mAssetBundle.Unload(true);
                mAssetBundle = null;
            }
            mNextLevelAssets.Clear();
            mAsset = null;
        }
예제 #5
0
        //热更新,更新资源
        public void updateResource()
        {
            mLocalPathMD5         = new VersionResourceFile();
            mServerPathMD5        = new VersionResourceFile();
            mUpdateAssets         = new List <string>();
            mUpdateAssetsSize     = new List <int>();
            mAllNeedDownLoadSize  = 0;
            mCurrentDownLoadSize  = 0;
            mAllNeedDownLoadBytes = 0;
            mCurrentDownLoadBytes = 0;
            mComplete             = false;

            mCurrentDownLoadAsset            = "";
            mCurrentDownLoadAssetFailedTimes = 0;
            mMaxRepeatDownLoadTimes          = 5;
            mForceTermination = false;

            mNetworkConnections              = true;
            mNeedCheckNetWorkConnections     = false;
            mCheckNetWorkConnectionsMaxTimes = 10;

            //1.加载本地资源version.xml信息
            StreamReader localReader = ResourcesManager.OpenText("Version");

            parseResourceVersionFile(localReader.ReadToEnd(), ref mLocalPathMD5);
            localReader.Close();

            //2.加载服务器version.xml信息
            StartCoroutine(downLoad(ResourceCommon.getServerPath("Version.bytes"), delegate(WWW resourceVersion)
            {
                parseResourceVersionFile(resourceVersion.text, ref mServerPathMD5);


                if (needUpdate(mLocalPathMD5, mServerPathMD5, mUpdateAssets, mUpdateAssetsSize))
                {
                    Debug.LogError("need update true");

                    mAllNeedDownLoadSize = mUpdateAssets.Count;

                    //4.下载最新资源
                    downLoadAssets();
                }
                else
                {
                    mComplete = true;
                    OnUpdateComplete();
                    Debug.LogError("Complete update");
                }
            }));
        }
예제 #6
0
        private void ReplaceLocalRes(string file, byte[] data)
        {
            string localPath;

            //Andrio跟IOS环境使用沙箱目录
            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                localPath = string.Format("{0}/{1}", Application.persistentDataPath, file);
            }
            //Window下使用assetbunlde资源目录
            else
            {
                localPath = ResourceCommon.assetbundleFilePath + file;
                Debug.LogError("Replace" + localPath);
            }

            ResourceCommon.CheckFolder(ResourceCommon.getPath(localPath));
            FileStream stream = new FileStream(localPath, FileMode.OpenOrCreate);

            stream.Write(data, 0, data.Length);
            stream.Flush();
            stream.Close();
        }