Ejemplo n.º 1
0
        private void InitRecordProgress()
        {
            if (this.mProgressController == null)
            {
                this.mProgressController = new TinyReplayProgress();
            }
            this.mProgressController.ResetReplayProgress();

            // init the replay progress.
            this.mProgressController.mPerRecordInterval = this.mPerRecordInterval;
            this.mProgressController.audioURL           = "HelloWorld.mp3";

            // reset the replay progress controller.
            GameObject[] allReplayObjs = GameObject.FindGameObjectsWithTag("RepalyObjectParent");
            for (int i = 0; i < allReplayObjs.Length; i++)
            {
                ReplayParentObject replayParent = allReplayObjs[i].GetComponent <ReplayParentObject>();
                if (replayParent == null)
                {
                    Debug.LogError(" replay parent not have ReplayParentObject script.");
                    continue;
                }
                int parentIndex = TinyReplayManager.GetInstance.CurEntityParentBeginIndex;
                replayParent.InitReplayParentObject(parentIndex);
                this.mProgressController.AddNewReplayParentEntity(replayParent, parentIndex);
                TinyReplayManager.GetInstance.CurEntityParentBeginIndex = (parentIndex + 10000);

                Debug.Log("next replay parent index is " + TinyReplayManager.GetInstance.CurEntityParentBeginIndex);
                foreach (var replayChildObject in replayParent.allReplayObjects)
                {
                    this.mProgressController.AddNewReplayEntity(replayChildObject.Value);
                }

                // save the first time pos entity state.
                this.mProgressController.InsertEntityNewState(this.mCurTimePos);
            }
        }
        IEnumerator _LoadReplayDataFromFile()
        {
            string fileName = TinyReplaySystemDefine.GetStrReplayProcessFilePath();
            Debug.Log("@load file name is " + fileName);
            Debug.Log("@start load time:" + Time.realtimeSinceStartup);

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            // load process data.
            FileInfo fileInfor = new FileInfo(fileName);
            if (fileInfor.Exists)
            {
                using (StreamReader sr = fileInfor.OpenText())
                {
                    string jsonProgress = sr.ReadToEnd();
                    this.mProgressController = Newtonsoft.Json.JsonConvert.DeserializeObject<TinyReplayProgress>(jsonProgress, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Objects });
                    this.mPerReplayInterval = this.mProgressController.mPerRecordInterval;
                }
            }
            else
            {
                Debug.LogError("replay file is not exist, please check it.");
                yield break;
            }

            // set the min line data count.
            if (this.mPerReplayInterval <= 0.0f)
            {
                this.mPerReplayInterval = 0.033f;
                Debug.LogError("@per replay interval is less than 0.0f.");
            }

            int perSecondCount = Mathf.RoundToInt(1f / this.mPerReplayInterval);
            int entityCount = this.mProgressController.allEntity.Count;
            this.mMinLoadLineDataCount = perSecondCount * 2 * entityCount;
            this.mStartReplayTimePos = Mathf.Min(this.mMinLoadLineDataCount * 4, this.mProgressController.mMaxTimePosition * entityCount);
            this.mFirstTimePosLineDataCount = entityCount;
            this.mFirstUpdateOver = false;
            this.mIsReplaying = false;
            this.mIsStartReplay = false;
            Debug.Log("@per second count is " + perSecondCount);
            Debug.Log("@min load line data count is " + this.mMinLoadLineDataCount);
            Debug.Log("@start replay animation timepos is " + this.mStartReplayTimePos);
            Debug.Log("@first time pos line data count is " + this.mFirstTimePosLineDataCount);
            // init the animation entity.
            // 加载角色模板,下载本地贴图,全部完成开始播放动画.
            // 第一帧缩略图,至于最高层,当所有的角色加载完毕并且第一帧得到了更新,删除当前的缩略图开始动画
            this.LoadEntityDataBeforeReplay();

            fileName = TinyReplaySystemDefine.GetStrEntityStateSaveFilePath();
            fileInfor = new FileInfo(fileName);
            string lineData = string.Empty;
            int dataCount = 0;
            if (fileInfor.Exists)
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    while ((lineData = sr.ReadLine()) != null)
                    {
                        dataCount++;
                        this.PrasingStateData(lineData, dataCount);
                        if (dataCount >= this.mFirstTimePosLineDataCount && !this.mFirstUpdateOver)
                        {
                            Debug.Log("@update the first timePos state.");
                            this.mFirstUpdateOver = true;
                            // init the first timePos.
                            for (int i = 0; i < entityCount; i++)
                                this.mProgressController.allEntity[i].SynchronizeEntity(0);
                        }
                        this.CheckToReplayAnimation(dataCount);
                        // lbLineIndex.text = dataCount.ToString();
                        // per 2 second data count.
                        if (dataCount % this.mMinLoadLineDataCount == 0)
                        {
                            yield return new WaitForEndOfFrame();
                        }
                    }
                }
            }
            else
            {
                Debug.LogError("replay progress data file is not exist.");
                yield break;
            }

            stopwatch.Stop();
            TimeSpan timeSpan = stopwatch.Elapsed;
            double takeTime = timeSpan.TotalSeconds;
            double takeTime2 = timeSpan.TotalMilliseconds;

            //打印程序运行的时间
            Debug.Log("@LoadRecordFile__________take time is " + takeTime + " current Time is " + takeTime2);
            Debug.Log("@end load time:" + Time.realtimeSinceStartup);
            yield return 0;
        }
Ejemplo n.º 3
0
        IEnumerator _LoadReplayDataFromFile()
        {
            string fileName = TinyReplaySystemDefine.GetStrReplayProcessFilePath();

            Debug.Log("@load file name is " + fileName);
            Debug.Log("@start load time:" + Time.realtimeSinceStartup);

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();

            // load process data.
            FileInfo fileInfor = new FileInfo(fileName);

            if (fileInfor.Exists)
            {
                using (StreamReader sr = fileInfor.OpenText())
                {
                    string jsonProgress = sr.ReadToEnd();
                    this.mProgressController = Newtonsoft.Json.JsonConvert.DeserializeObject <TinyReplayProgress>(jsonProgress, new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.Objects
                    });
                    this.mPerReplayInterval = this.mProgressController.mPerRecordInterval;
                }
            }
            else
            {
                Debug.LogError("replay file is not exist, please check it.");
                yield break;
            }

            // set the min line data count.
            if (this.mPerReplayInterval <= 0.0f)
            {
                this.mPerReplayInterval = 0.033f;
                Debug.LogError("@per replay interval is less than 0.0f.");
            }

            int perSecondCount = Mathf.RoundToInt(1f / this.mPerReplayInterval);
            int entityCount    = this.mProgressController.allEntity.Count;

            this.mMinLoadLineDataCount      = perSecondCount * 2 * entityCount;
            this.mStartReplayTimePos        = Mathf.Min(this.mMinLoadLineDataCount * 4, this.mProgressController.mMaxTimePosition * entityCount);
            this.mFirstTimePosLineDataCount = entityCount;
            this.mFirstUpdateOver           = false;
            this.mIsReplaying   = false;
            this.mIsStartReplay = false;
            Debug.Log("@per second count is " + perSecondCount);
            Debug.Log("@min load line data count is " + this.mMinLoadLineDataCount);
            Debug.Log("@start replay animation timepos is " + this.mStartReplayTimePos);
            Debug.Log("@first time pos line data count is " + this.mFirstTimePosLineDataCount);
            // init the animation entity.
            // 加载角色模板,下载本地贴图,全部完成开始播放动画.
            // 第一帧缩略图,至于最高层,当所有的角色加载完毕并且第一帧得到了更新,删除当前的缩略图开始动画
            this.LoadEntityDataBeforeReplay();

            fileName  = TinyReplaySystemDefine.GetStrEntityStateSaveFilePath();
            fileInfor = new FileInfo(fileName);
            string lineData  = string.Empty;
            int    dataCount = 0;

            if (fileInfor.Exists)
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    while ((lineData = sr.ReadLine()) != null)
                    {
                        dataCount++;
                        this.PrasingStateData(lineData, dataCount);
                        if (dataCount >= this.mFirstTimePosLineDataCount && !this.mFirstUpdateOver)
                        {
                            Debug.Log("@update the first timePos state.");
                            this.mFirstUpdateOver = true;
                            // init the first timePos.
                            for (int i = 0; i < entityCount; i++)
                            {
                                this.mProgressController.allEntity[i].SynchronizeEntity(0);
                            }
                        }
                        this.CheckToReplayAnimation(dataCount);
                        // lbLineIndex.text = dataCount.ToString();
                        // per 2 second data count.
                        if (dataCount % this.mMinLoadLineDataCount == 0)
                        {
                            yield return(new WaitForEndOfFrame());
                        }
                    }
                }
            }
            else
            {
                Debug.LogError("replay progress data file is not exist.");
                yield break;
            }

            stopwatch.Stop();
            TimeSpan timeSpan  = stopwatch.Elapsed;
            double   takeTime  = timeSpan.TotalSeconds;
            double   takeTime2 = timeSpan.TotalMilliseconds;

            //打印程序运行的时间
            Debug.Log("@LoadRecordFile__________take time is " + takeTime + " current Time is " + takeTime2);
            Debug.Log("@end load time:" + Time.realtimeSinceStartup);
            yield return(0);
        }