コード例 #1
0
        private void SaveFile()
        {
            Debug.Log("@start time " + Time.realtimeSinceStartup);
            string fileName = TinyReplaySystemDefine.GetStrReplayProcessFilePath();

            Debug.Log("@save file to:" + fileName);

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            // **** write all file just save string text to file.
            string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(this.mProgressController, Formatting.None, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Objects
            });
            FileInfo fileInfor = new FileInfo(fileName);

            using (StreamWriter sw = fileInfor.CreateText())
            {
                sw.Write(jsonStr);
            }

            Debug.Log("@end time " + Time.realtimeSinceStartup);

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

            Debug.Log("@Test save record file take time is " + takeTime + " current Time is " + takeTime2);

            // Debug information.
            string debugMsg = string.Format("Record over. save file:{0}.", fileName);

            TinyReplayManager.GetInstance.OnRecordOver(debugMsg);
        }
コード例 #2
0
        public void StartRecording()
        {
            string fileName = TinyReplaySystemDefine.GetStrEntityStateSaveFilePath();
            // open file for entity state to write.
            FileInfo fileInfor = new FileInfo(fileName);

            mStreamWriter = fileInfor.CreateText();

            this.mIsRecording       = true;
            this.mIsStartRecording  = true;
            this.mTimeElapsed       = 0.0f;
            this.mPerRecordInterval = 0.033f;
            this.mCurTimePos        = 0;
            this.mStartRecordTime   = Time.realtimeSinceStartup;
            this.InitRecordProgress();

            Debug.Log("@start recording." + Time.realtimeSinceStartup);
            // spriteDone.color = Color.gray;

            // Debug information.
            string debugMsg = string.Format("Recording...PerSecondInterval:{0}, MaxTimePos:{1}.", this.mPerRecordInterval, this.mMaxTimePosition);

            TinyReplayManager.GetInstance.OnRecordBegin(debugMsg);
        }
コード例 #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);
        }