Пример #1
0
 public SpartaSequentialAnimation(FinishedDelegate onFinishedCallback)
 {
     State                 = SpartaAnimationState.Stopped;
     animations            = new SpartaList <SpartaAbstractAnimation>();
     currentAnimationIndex = -1;
     Finished              = onFinishedCallback;
 }
Пример #2
0
 /// <summary>
 /// ステージ情報の読み込み。
 /// </summary>
 /// <param name="id">読み込むステージのID。</param>
 /// <param name="func">取得したステージ情報を受け取るデリゲート。</param>
 /// <returns>処理結果。</returns>
 /// <exception cref="IOException">読み込み失敗時。</exception>
 public IEnumerator FindStage(int id, FinishedDelegate <Stage> func)
 {
     yield return(this.Get(
                      "/stages/" + id,
                      (www) => func(JsonUtility.FromJson <Stage>(www.text)),
                      (www) => { throw new NotifiableException("STAGE_UNAVAILABLE", id); }));
 }
Пример #3
0
        /// <summary>
        /// ステージ開始状況の通知。
        /// </summary>
        /// <param name="stageId">開始したステージのID。</param>
        /// <param name="func">取得したプレイログを受け取るデリゲート。</param>
        /// <returns>処理結果。</returns>
        /// <exception cref="IOException">保存失敗時。</exception>
        public IEnumerator SaveStageStart(int stageId, FinishedDelegate <Playlog> func)
        {
            var param = new StartParam {
                stageId = stageId
            };

            yield return(this.Post(
                             "/games/start",
                             JsonUtility.ToJson(param),
                             (www) => func(JsonUtility.FromJson <Playlog>(www.text)),
                             (www) =>
            {
                // アクセス不可や削除の場合404が返るのでnullを戻す
                // ※ 値が設定されていない場合も環境の問題か判別できないのでとりあえず同じエラーを返す
                int status = this.GetHttpStatus(www);
                if (status == 404 || status == 0)
                {
                    throw new NotifiableException("STAGE_UNAVAILABLE", stageId);
                }
                else
                {
                    throw new IOException(this.MakeErrorMessage(www));
                }
            }));
        }
        public BlockTimedIterator(BlockDelegate aFunctionToRunOnBlocks, List <AbstractBlock> aBlocks, float aTimeBetweenIterations, FinishedDelegate aFinnishFunction = null)
        {
            myFunctionToRun           = aFunctionToRunOnBlocks;
            myBlocks                  = aBlocks;
            myFramesBetweenIterations = aTimeBetweenIterations;
            myCurrentCooldown         = myFramesBetweenIterations;
            myFunctionToFinnish       = aFinnishFunction;

            myCurrentIndex = 0;
        }
Пример #5
0
        /// <summary>
        /// GET APIコール。
        /// </summary>
        /// <param name="path">APIのパス。</param>
        /// <param name="success">成功時に実行する処理。</param>
        /// <param name="error">失敗時に実行する処理。</param>
        /// <returns>子ルーチンの実行状態。</returns>
        public IEnumerator Get(string path, FinishedDelegate <WWW> success = null, FinishedDelegate <WWW> error = null)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            this.MergeHeaders(headers);

            yield return(this.DoRequestWithRetry(
                             () => new WWW(this.ApiRoot + path, null, headers),
                             success,
                             error,
                             "GET " + this.ApiRoot + path));
        }
Пример #6
0
        /// <summary>
        /// POST APIコール。
        /// </summary>
        /// <param name="path">APIのパス。</param>
        /// <param name="json">POSTで渡すJSON文字列。</param>
        /// <param name="success">成功時に実行する処理。</param>
        /// <param name="error">失敗時に実行する処理。</param>
        /// <returns>子ルーチンの実行状態。</returns>
        public IEnumerator Post(string path, string json, FinishedDelegate <WWW> success = null, FinishedDelegate <WWW> error = null)
        {
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers["Content-Type"] = "application/json";
            this.MergeHeaders(headers);

            var formData = System.Text.Encoding.UTF8.GetBytes(json);

            yield return(this.DoRequestWithRetry(
                             () => new WWW(this.ApiRoot + path, formData, headers),
                             success,
                             error,
                             "POST " + this.ApiRoot + path + " " + json));
        }
Пример #7
0
        public void Do(string progressText, int?maximumOrNullForMarquee, FinishedDelegate methodCalledAfterFinish)
        {
            IsBusy = true;

            ShowProgressForm(progressText, maximumOrNullForMarquee);

            StartDoInThread();

            HideProgressForm();

            IsBusy = false;
            if (methodCalledAfterFinish != null)
            {
                methodCalledAfterFinish(new UIJobResult(UIJobResult.eUIJobResult.OK));
            }
        }
Пример #8
0
        /// <summary>
        /// ステージ一覧の読み込み。
        /// </summary>
        /// <param name="func">取得したステージ情報リストを受け取るデリゲート。</param>
        /// <returns>処理結果。</returns>
        /// <exception cref="IOException">読み込み失敗時。</exception>
        public IEnumerator FindStages(FinishedDelegate <IList <Stage> > func)
        {
            yield return(this.Get(
                             "/stages",
                             (www) =>
            {
                var obj = JsonMapper.ToObject(www.text);
                IList <Stage> stages = new List <Stage>();
                for (int i = 0; i < obj.Count; i++)
                {
                    stages.Add(JsonUtility.FromJson <Stage>(obj[i].ToJson()));
                }

                func(stages);
            }));
        }
Пример #9
0
        /// <summary>
        /// ブロック一覧の読み込み。
        /// </summary>
        /// <param name="func">取得したブロック情報リストを受け取るデリゲート。</param>
        /// <returns>処理結果。</returns>
        /// <exception cref="IOException">読み込み失敗時。</exception>
        public IEnumerator FindBlocks(FinishedDelegate <IDictionary <string, Block> > func)
        {
            yield return(this.Get(
                             "/blocks",
                             (www) =>
            {
                var obj = JsonMapper.ToObject(www.text);
                IDictionary <string, Block> blocks = new Dictionary <string, Block>();
                for (int i = 0; i < obj.Count; i++)
                {
                    Block block = JsonUtility.FromJson <Block>(obj[i].ToJson());
                    blocks.Add(block.Key, block);
                }

                func(blocks);
            }));
        }
Пример #10
0
        public SpartaPropertyAnimation(object instance, string propertyName, object from, object to, TimeSpan time, EasingCurve.EasingCurveType easingCurve, FinishedDelegate callback)
        {
            this.instance         = instance;
            this.propertyName     = propertyName;
            this.propertyInstance = instance.GetType().GetProperty(propertyName);
            this.property         = propertyInstance.GetValue(instance, null);

            this.From = from;
            this.To   = to;

            this.Duration    = time;
            this.easingCurve = new EasingCurve(easingCurve);

            Finished = callback;

            State = SpartaAnimationState.Stopped;
        }
Пример #11
0
        /// <summary>
        /// リクエストをリトライ付きで実行する。
        /// </summary>
        /// <param name="request">実行するリクエスト処理。複数回実行される。</param>
        /// <param name="success">成功時に実行する処理。</param>
        /// <param name="error">失敗時に実行する処理。</param>
        /// <param name="log">デバッグログメッセージ。空の場合は出力しない。</param>
        /// <returns>子ルーチンの実行状態。</returns>
        private IEnumerator DoRequestWithRetry(
            DoRequestDelgate request,
            FinishedDelegate <WWW> success,
            FinishedDelegate <WWW> error,
            string log = "")
        {
            // エラーの場合に、既定回数リトライする
            string s = log;
            int    i = 1;
            WWW    www;

            do
            {
                if (!string.IsNullOrEmpty(log))
                {
                    Debug.Log(s);
                }

                www = request();
                yield return(www);

                // 正常ならOK
                if (string.IsNullOrEmpty(www.error))
                {
                    break;
                }

                // エラーであっても4xx系はリトライしても無駄なはずなので終了
                int status = this.GetHttpStatus(www);
                if (status >= 400 && status < 500)
                {
                    break;
                }

                // 次回リトライの準備
                if (i <= this.Retry)
                {
                    s = log + " (Retry:" + i + ")";
                    yield return(new WaitForSeconds(this.Wait / 1000f));
                }
            }while (i++ <= this.Retry);

            this.InvokeFinishedDelegate(www, success, error);
        }
Пример #12
0
 /// <summary>
 /// ユーザー情報の読み込み。
 /// </summary>
 /// <param name="func">取得したユーザー情報を受け取るデリゲート。</param>
 /// <returns>処理結果。</returns>
 /// <exception cref="IOException">読み込み失敗時。</exception>
 public IEnumerator FindUser(FinishedDelegate <User> func)
 {
     yield return(this.Get(
                      "/users/me",
                      (www) => func(JsonUtility.FromJson <User>(www.text)),
                      (www) =>
     {
         // 未認証の場合401が返るのでnullを戻す
         // ※ 値が設定されていない場合も環境の問題か判別できないのでとりあえずnullを返す
         int status = this.GetHttpStatus(www);
         if (status == 401 || status == 0)
         {
             func(null);
         }
         else
         {
             throw new IOException(this.MakeErrorMessage(www));
         }
     }));
 }
Пример #13
0
 /// <summary>
 /// APIコールの後処理を実行する。
 /// </summary>
 /// <param name="www">サーバーアクセス結果。</param>
 /// <param name="success">成功時に実行する処理。</param>
 /// <param name="error">失敗時に実行する処理。</param>
 /// <exception cref="IOException"><c>error</c>未設定でエラーの場合。</exception>
 private void InvokeFinishedDelegate(WWW www, FinishedDelegate <WWW> success = null, FinishedDelegate <WWW> error = null)
 {
     // 正常系はデリゲートが渡された場合のみ、異常系はデフォルトでIOExceptionを投げる
     if (string.IsNullOrEmpty(www.error))
     {
         if (success != null)
         {
             success(www);
         }
     }
     else
     {
         if (error != null)
         {
             error(www);
         }
         else
         {
             throw new IOException(this.MakeErrorMessage(www));
         }
     }
 }
Пример #14
0
        public static void StartDownload(Parameters parameters, Flag doneFlag, StatusDelegate statusFunction, ErrorDelegate errorFunction, FinishedDelegate finishedFunction)
        {
            if (parameters.ResponseFile.Length == 0 && parameters.Url.Length == 0)
            {
                throw new BitTorrentException("需要Response file 或者 Url");
            }

            Parameters = parameters;
            Stream stream = null;

            byte[] response;
            long   length = 0;

            try
            {
                if (parameters.ResponseFile.Length != 0)
                {
                    stream = File.OpenRead(parameters.ResponseFile);
                    length = stream.Length;
                }

                else
                {
                    WebRequest  webRequest  = WebRequest.Create(parameters.Url);
                    WebResponse webResponse = webRequest.GetResponse();
                    stream = webResponse.GetResponseStream();
                    length = webResponse.ContentLength;
                }

                response = new byte[length];
                stream.Read(response, 0, (int)length);
            }

            catch
            {
                throw new BitTorrentException("Problem getting response info");
            }

            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            DictNode rootNode;

            try
            {
                rootNode = BEncodingFactory.Decode(response) as DictNode;
                //BTFormat.CheckMessage(rootNode);
            }
            catch
            {
                throw new BitTorrentException("got bad file");
            }

            DictNode       infoNode = rootNode["info"] as DictNode;
            List <BitFile> files    = new List <BitFile>();
            string         file;
            long           fileLength;

            try
            {
                if (infoNode.ContainsKey("length"))
                {
                    fileLength = (infoNode["length"] as IntNode).Value;
                    BytesNode nameNode = (infoNode["name"] as BytesNode);
                    if (nameNode == null)
                    {
                        return;
                    }
                    file = @"k:\torrent\" + nameNode.StringText;
                    Make(file, false);
                    files.Add(new BitFile(file, fileLength));
                }

                else
                {
                    fileLength = 0L;
                    ListNode filesNode = infoNode["files"] as ListNode;
                    foreach (BEncodedNode handler in filesNode)
                    {
                        DictNode fileNode = infoNode["files"] as DictNode;
                        fileLength += (fileNode["length"] as IntNode).Value;
                    }
                    //访问文件夹
                    BytesNode nameNode = infoNode["name"] as BytesNode;
                    if (nameNode == null)
                    {
                        return;
                    }
                    file = @"C:\torrent\" + nameNode.StringText;
                    // if this path exists, and no files from the info dict exist, we assume it's a new download and
                    // the user wants to create a new directory with the default name
                    bool existed = false;
                    if (Directory.Exists(file))
                    {
                        foreach (BEncodedNode handler in filesNode)
                        {
                            DictNode fileNode = handler as DictNode;
                            ListNode pathNode = fileNode["path"] as ListNode;
                            if (File.Exists(Path.Combine(file, (pathNode[0] as BytesNode).StringText)))
                            {
                                existed = true;
                                break;
                            }
                        }

                        if (!existed)
                        {
                            file = Path.Combine(file, (infoNode["name"] as BytesNode).StringText);
                        }
                    }
                    Make(file, true);

                    // alert the UI to any possible change in path
                    //TODO: if (pathFunc != null)
                    // pathFunc(file)

                    foreach (BEncodedNode handler in filesNode)
                    {
                        DictNode fileNode = handler as DictNode;
                        ListNode pathNode = fileNode["path"] as ListNode;
                        string   n        = file;
                        foreach (BEncodedNode stringHandler in pathNode)
                        {
                            n = Path.Combine(n, (stringHandler as BytesNode).StringText);
                        }
                        files.Add(new BitFile(n, (fileNode["length"] as IntNode).Value));
                        Make(n, false);
                    }
                }
            }
            catch
            {
                throw new BitTorrentException("Couldn't allocate directory...");
            }

            Flag           finishFlag     = new Flag();
            FinishedHelper finishedHelper = new FinishedHelper();

            finishedHelper.ErrorFunction    = errorFunction;
            finishedHelper.FinishedFunction = finishedFunction;
            finishedHelper.DoneFlag         = finishFlag;

            string sID = DateTime.Now.ToLongDateString() + "www.wallywood.co.uk";

            byte[] myID = Globals.GetSha1Hash(Encoding.ASCII.GetBytes(sID));//Globals.Sha1.ComputeHash(Encoding.Default.GetBytes(sID));

            byte[]        piece  = (infoNode["pieces"] as BytesNode).ByteArray;
            List <byte[]> pieces = new List <byte[]>();

            for (int i = 0; i < piece.Length; i += 20)
            {
                byte[] temp = new byte[20];
                Buffer.BlockCopy(piece, i, temp, 0, 20);
                pieces.Add(temp);
            }

            Storage _storage = null;

            try
            {
                try
                {
                    //_storage = new Storage(files, parameters.AllocatePause, statusFunction);
                    finishedHelper.Storage = _storage;
                }
                catch (Exception ex)
                {
                    errorFunction("trouble accessing files - " + ex.Message);
                }
                IntNode pieceLengthNode = infoNode["piece length"] as IntNode;
                StorageWrapper = new StorageWrapper(_storage, parameters.DownloadSliceSize, pieces, (int)pieceLengthNode.Value,
                                                    finishedHelper.Finished, finishedHelper.Failed, statusFunction, finishFlag, parameters.CheckHashes,
                                                    finishedHelper.DataFlunked);
            }
            // Catch ValueError
            // failed("bad data")
            // catch IO Error
            catch (Exception ex)
            {
                finishedHelper.Failed("Problem - " + ex.Message);
            }

            if (finishFlag.IsSet)
            {
                return;
            }

            RawServer rawServer = new RawServer(finishFlag, parameters.TimeoutCheckInterval, parameters.Timeout, false);

            if (parameters.MaxPort < parameters.MinPort)
            {
                int temp = parameters.MinPort;
                parameters.MinPort = parameters.MaxPort;
                parameters.MaxPort = parameters.MinPort;
            }

            ushort listenPort;

            for (listenPort = parameters.MinPort; listenPort <= parameters.MaxPort; listenPort++)
            {
                try
                {
                    rawServer.Bind(listenPort, parameters.Bind, false);
                    break;
                }
                catch (SocketException)
                {
                    //TODO: Error Code
                }
            }

            //TODO: Check whether nothing bound
            Choker = new Choker(parameters.MaxUploads, rawServer.AddTask, finishFlag);
            Measure     uploadMeasure   = new Measure(parameters.MaxRatePeriod, parameters.UploadRateFudge);
            Measure     downloadMeasure = new Measure(parameters.MaxRatePeriod);
            RateMeasure rateMeasure     = new RateMeasure(StorageWrapper.LeftLength);
            Downloader  downloader      =
                new NormalDownloader(StorageWrapper, new PiecePicker(pieces.Count), parameters.RequestBackLog,
                                     parameters.MaxRatePeriod, pieces.Count, downloadMeasure, parameters.SnubTime,
                                     rateMeasure.DataCameIn);

            Connecter connecter =
                new Connecter(downloader, Choker, pieces.Count, StorageWrapper.IsEverythingPending, uploadMeasure,
                              parameters.MaxUploadRate << 10, rawServer.AddTask);

            byte[] infoHash = Globals.GetSha1Hash(BEncodingFactory.ByteArrayEncode(infoNode));//Globals.Sha1.ComputeHash(BEncodingFactory.ByteArrayEncode(infoNode));

            Encrypter encrypter = new Encrypter(connecter, rawServer, myID, parameters.MaxMessageLength, rawServer.AddTask,
                                                parameters.KeepAliveInterval, infoHash, parameters.MaxInitiate);
            //ReRequester reRequester =
            //    new ReRequester((rootNode["announce"] as BytesNode).StringText, parameters.RerequestInterval,
            //                    rawServer.AddTask, connecter.GetConnectionsCount, parameters.MinPeers,
            //                    encrypter.StartConnect, rawServer.AddExternalTask,
            //                    StorageWrapper.GetLeftLength, uploadMeasure.GetTotalLength, downloadMeasure.GetTotalLength,
            //                    listenPort, parameters.IP,
            //                    myID, infoHash, parameters.HttpTimeout, null, parameters.MaxInitiate, finishFlag);

            DownloaderFeedback downloaderFeedback =
                new DownloaderFeedback(Choker, rawServer.AddTask, statusFunction, uploadMeasure.GetUpdatedRate,
                                       downloadMeasure.GetUpdatedRate, rateMeasure.GetTimeLeft, rateMeasure.GetLeftTime,
                                       fileLength, finishFlag, parameters.DisplayInterval,
                                       parameters.Spew);

            statusFunction("connection to peers", -1, -1, -1, -1);
            //TODO: finishedHelper.errorfunc

            finishedHelper.FinishFlag = finishFlag;
            //finishedHelper.ReRequester = reRequester;
            finishedHelper.RateMeasure = rateMeasure;

            //reRequester.d(0);
            rawServer.ListenForever(encrypter);
            //reRequester.Announce(2, null);
        }
Пример #15
0
 /// <summary>
 /// wait.
 /// </summary>
 /// <returns>The wait.</returns>
 /// <param name="secondes">Secondes.</param>
 /// <param name="callback">Callback.</param>
 public IEnumerator CWait(float secondes, FinishedDelegate callback)
 {
     yield return new WaitForSeconds (secondes);
     callback ();
 }
Пример #16
0
 public SimCapiTimer(float duration, FinishedDelegate finishedDelegate)
 {
     _duration         = duration;
     _enabled          = false;
     _finishedDelegate = finishedDelegate;
 }
        /// <summary>
        /// Downloads the asset bundle.
        /// </summary>
        /// <returns>The asset bundle.</returns>
        /// <param name="url">URL.</param>
        /// <param name="version">Version.</param>
        /// <param name="finished">Finished.</param>
        public IEnumerator DownloadAssetBundle(string url, int version, FinishedDelegate finished)
        {
            string keyName = url + version.ToString ();
            if (dictionaryAssetBundleRef.ContainsKey (keyName)) {
                yield return null;
            } else {
                while (!Caching.ready) {
                    yield return null;
                }

                using (WWW www = WWW.LoadFromCacheOrDownload (url, version)) {
                    while (!www.isDone) {
                        progress = www.progress;
                        yield return null;
                    }
                    if (www.error != null) {
            //                        HDebug.LogError (www.error);
                    } else {
                        AssetBundleRef assetBundleRef = new AssetBundleRef (url, version);
                        assetBundleRef.assetBundle = www.assetBundle;
                        dictionaryAssetBundleRef.Add (keyName, assetBundleRef);

                        yield return null;
                    }

                    if (finished != null) {
                        finished (www);
                    }

                    progress = 1f;
                    www.Dispose ();
                }
            }
        }
Пример #18
0
    static public IEnumerator Evaluate(RenderTexture TextureA, RenderTexture TextureB, FinishedDelegate Delegate)
    {
        Texture2D backgroundRead = new Texture2D(TextureA.width, TextureA.height);
        Texture2D foregroundRead = new Texture2D(TextureB.width, TextureB.height);

        RenderTexture.active = TextureA;
        backgroundRead.ReadPixels(new Rect(0, 0, TextureA.width, TextureA.height), 0, 0);
        backgroundRead.Apply();

        RenderTexture.active = TextureB;
        foregroundRead.ReadPixels(new Rect(0, 0, TextureB.width, TextureB.height), 0, 0);
        foregroundRead.Apply();

        string log     = "";
        string colours = "";

        int target   = 0;
        int overlap  = 0;
        int overdraw = 0;

        for (int x = 0; x < TextureA.width; ++x)
        {
            for (int y = 0; y < TextureA.height; ++y)
            {
                Color ColourA = backgroundRead.GetPixel(x, y);
                Color ColourB = foregroundRead.GetPixel(x, y);

                bool isBackground = ColourA.r > 0.5f;
                bool isForeground = ColourB.g > 0.5f;

                if (isBackground)
                {
                    ++target;
                }
                if (isBackground == true && isForeground == true)
                {
                    ++overlap;
                }
                if (isBackground == false && isForeground == true)
                {
                    ++overdraw;
                }

                colours += "b: " + ColourA + "\t f: " + ColourB + "\n";
            }
            yield return(null);
        }

        log += "t: " + target + "\t op: " + overlap + "\t ow: " + overdraw;

        Debug.Log(log);
        Debug.Log(colours);

        yield return(null);
    }
Пример #19
0
 /// <summary>
 /// Wait the specified duration and callback.
 /// </summary>
 /// <param name="duration">Duration.</param>
 /// <param name="callback">Callback.</param>
 public void Wait(float duration, FinishedDelegate callback)
 {
     this.StartCoroutine (CWait (duration, callback));
 }
Пример #20
0
 public SpartaAnimationGroup(FinishedDelegate callback)
 {
     animationsList        = new SpartaList <SpartaAbstractAnimation>();
     activeAnimationsCount = 0;
     Finished = callback;
 }
Пример #21
0
 public SpartaPauseAnimation(TimeSpan duration, FinishedDelegate callback)
 {
     this.Duration = duration;
     this.Finished = callback;
 }
Пример #22
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_orginalStorage">storage对象</param>
        /// <param name="requestSize">子片断长度</param>
        /// <param name="hashes">文件片断摘要信息</param>
        /// <param name="pieceLength">片断长度</param>
        /// <param name="finishedFunc">在下载完成的时候设置的事件</param>
        /// <param name="failedFunc">在下载失败的时候设置的事件</param>
        /// <param name="statusFunc">状态函数</param>
        /// <param name="flag"></param>
        /// <param name="checkHashes"></param>
        /// <param name="dataFlunkedFunc">用来检查片断的完整性的函数</param>
        public StorageWrapper(Storage storage, int requestSize, List <byte[]> hashes, int pieceLength, FinishedDelegate finishedFunc,
                              FailedDelegate failedFunc, StatusDelegate statusFunc, Flag flag, bool checkHashes, DataFlunkedDelegate dataFlunkedFunc)
        {
            this.checkHashes         = checkHashes;
            this._storage            = storage;
            this.requestSize         = requestSize;
            this.hashes              = hashes;
            this.pieceLength         = pieceLength;
            this.dataFlunkedFunction = dataFlunkedFunc;
            this.totalLength         = 0;//storage.SumLength;
            this.leftLength          = this.totalLength;


            //检验是否需要接收数据的长度符合标准
            CheckTotalLength();

            this.finishedFunction = finishedFunc;
            this.failedFunction   = failedFunc;
            numActive             = new int[hashes.Count];

            int hashesLength = hashes.Count;

            //初始化inactiveRequests链表
            InitialInactiveRequests(hashesLength);

            have = new bool[hashesLength];

            //如果校验和的长度为0,则结束
            if (hashesLength == 0)
            {
                if (finishedFunc != null)
                {
                    finishedFunc();
                }
                return;
            }

            //该片是否检查了完整性
            isChecked = false;

            int i;

            //如果磁盘上已经存在下载的文件,则校验磁盘上的文件
            if (true)//_storage.IsExisted)
            {
                //显示检查文件信息
                if (statusFunc != null)
                {
                    statusFunc("正在检查存在的文件", -1, -1, 0, -1);
                }

                for (i = 0; i < hashesLength; i++)
                {
                    CheckSingle(i, true);
                    if (flag.IsSet)
                    {
                        return;
                    }

                    //显示检查文件信息
                    if (statusFunc != null)
                    {
                        statusFunc(string.Empty, -1, -1, ((double)(i + 1) / (double)hashesLength), -1);
                    }
                }
            }

            //如果磁盘上没有文件,则新建文件
            else
            {
                for (i = 0; i < hashesLength; i++)
                {
                    CheckSingle(i, false);
                }
            }

            isChecked = true;
        }
Пример #23
0
        /// <summary>
        /// wait.
        /// </summary>
        /// <returns>The wait.</returns>
        /// <param name="secondes">Secondes.</param>
        /// <param name="callback">Callback.</param>
        public IEnumerator CWait(float secondes, FinishedDelegate callback)
        {
            yield return(new WaitForSeconds(secondes));

            callback();
        }
Пример #24
0
 protected SpartaAbstractAnimation()
 {
     State            = SpartaAnimationState.Stopped;
     Duration         = TimeSpan.Zero;
     InternalFinished = OnFinished;
 }
Пример #25
0
 /// <summary>
 /// Wait the specified duration and callback.
 /// </summary>
 /// <param name="duration">Duration.</param>
 /// <param name="callback">Callback.</param>
 public void Wait(float duration, FinishedDelegate callback)
 {
     this.StartCoroutine(CWait(duration, callback));
 }
Пример #26
0
 public override void Dispose()
 {
     Finished         = null;
     InternalFinished = null;
     base.Dispose();
 }
Пример #27
0
        /// <summary>
        /// Downloads the asset bundle.
        /// </summary>
        /// <returns>The asset bundle.</returns>
        /// <param name="url">URL.</param>
        /// <param name="version">Version.</param>
        /// <param name="finished">Finished.</param>
        public IEnumerator DownloadAssetBundle(string url, int version, FinishedDelegate finished)
        {
            string keyName = url + version.ToString();

            if (dictionaryAssetBundleRef.ContainsKey(keyName))
            {
                if (finished != null)
                {
                    finished(null);
                }

                yield return(null);
            }
            else
            {
                while (!Caching.ready)
                {
                    yield return(null);
                }

#if UNITY_5_4_OR_NEWER
                uint v = Convert.ToUInt32(version);
                using (UnityWebRequest www = UnityWebRequest.GetAssetBundle(url, v, 0)) {
                    yield return(www.Send());

                    while (!www.isDone)
                    {
                        progress = www.downloadProgress;
                        yield return(null);
                    }

                    if (!www.isError)
                    {
                        AssetBundleRef assetBundleRef = new AssetBundleRef(url, version);
                        assetBundleRef.assetBundle = DownloadHandlerAssetBundle.GetContent(www);
                        dictionaryAssetBundleRef.Add(keyName, assetBundleRef);

                        yield return(null);
                    }

                    if (finished != null)
                    {
                        finished(www);
                    }

                    progress = 1f;
                }
#else
                using (WWW www = WWW.LoadFromCacheOrDownload(url, version)) {
                    while (!www.isDone)
                    {
                        progress = www.progress;
                        yield return(null);
                    }

                    if (www.error == null)
                    {
                        AssetBundleRef assetBundleRef = new AssetBundleRef(url, version);
                        assetBundleRef.assetBundle = www.assetBundle;
                        dictionaryAssetBundleRef.Add(keyName, assetBundleRef);

                        yield return(null);
                    }

                    if (finished != null)
                    {
                        finished(www);
                    }

                    progress = 1f;
                    www.Dispose();
                }
#endif
            }
        }