Esempio n. 1
0
        public void AddNewReplayParentEntity(ReplayParentObject replayObject, int parentIndex)
        {
            TinyReplayEntity newEntity = this.CreateNewTinyReplayEntity(replayObject.entityType);

            newEntity.InitReplayEntity(replayObject.gameObject, replayObject.prefabName, parentIndex);
            this.allEntity.Add(newEntity);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        private void LoadEntityDataBeforeReplay()
        {
            Debug.Log("@animation entity count is " + this.mProgressController.allEntity.Count);
            List <TinyReplayEntity> allEntity = this.mProgressController.allEntity;
            StringBuilder           sb        = null;

            GameObject         templateObject = null;
            ReplayParentObject parentScript   = null;

            for (int i = 0; i < allEntity.Count; i++)
            {
                TinyReplayEntity replayEntity = allEntity[i];
                sb = new StringBuilder();
                sb.AppendFormat("@entity information: prefab name is {0} entityIndex is {1}.", allEntity[i].mTemplateName, allEntity[i].entityIndex);
                Debug.Log(sb.ToString());

                // add TinyReplayEntity to progressController.
                this.mProgressController.allEntityDic[replayEntity.entityIndex] = replayEntity;

                if (replayEntity.entityIndex % 10000 == 0)
                {
                    GameObject loadedPrefab = Resources.Load <GameObject>("AnimationPrefab/" + replayEntity.mTemplateName);

                    // load the prefab and disable some script. like MovePosition, ChangeRotation etc.
                    // we just set the target state Properties use saved file.
                    // and you can disable/enable or just destory these unused control scripts.

                    // 删除对象的控制文件,以为在播放阶段,直接通过保存的对象信息更新对象位置缩放等属性信息
                    // 如果在文件中存储了一些控制命令,比如播放xx动画,可以解析该命令直接通过脚本控制对象执行动画操作
                    // 保证对象控制逻辑和同步逻辑不冲突.
                    // 有些情况下比如角色的动作过于复杂,也可以保留动作控制脚本,在Record的时候记录当前动画状态,到达TimePos时间点过后,直接按照当前的
                    // 动画状态播放角色动画
                    // 必须保证同步文件和控制脚本控制的对象不发生冲突.

                    if (loadedPrefab != null)
                    {
                        templateObject = GameObject.Instantiate(loadedPrefab) as GameObject;

                        // Delete some control script attached to the prefab template, such as UIDragObject etc.
                        UIDragObject[] disableScript = templateObject.GetComponentsInChildren <UIDragObject>();
                        for (int disIndex = 0; disIndex < disableScript.Length; disIndex++)
                        {
                            // or just destory the script you want to disable.
                            // we use UIDragObject script to drag object in recording, when replaying the animation we don't want
                            // the charater can be draged , so we destory or disable the UIDragObject script when replaying.
                            // that's why we add some control logic in these function.
                            // 在录制动画过程中用到了Drag脚本控制,但是在播放的过程不希望当前的角色能够Drag所以直接的删除或者disable相应的控制脚本
                            disableScript[disIndex].enabled = false;
                        }

                        parentScript = templateObject.GetComponent <ReplayParentObject>();
                        templateObject.SetActive(true);
                        if (parentScript != null)
                        {
                            parentScript.InitReplayParentObject(replayEntity.entityIndex);
                        }

                        // add to animation stage.
                        templateObject.transform.parent        = AnimationStage.StageRoot.transform;
                        templateObject.transform.localScale    = Vector3.one;
                        templateObject.transform.localPosition = Vector3.zero;
                        templateObject.transform.rotation      = Quaternion.identity;
                        // synchronize first time postiton state.
                        replayEntity.PrepareForReplay(templateObject);
                    }
                    else
                    {
                        Debug.LogError("load prefab is null.");
                    }
                }
                else
                {
                    // for the child.
                    if (parentScript == null)
                    {
                        Debug.LogError("@parent script is null.");
                    }
                    ReplayObject replayObject = parentScript.GetReplayObject(replayEntity.entityIndex);
                    if (replayObject == null)
                    {
                        Debug.LogError("replay object null:" + replayEntity.entityIndex);
                    }
                    Debug.Log("@ replay object name is " + replayObject.name);
                    replayEntity.PrepareForReplay(replayObject.gameObject);
                }
            }
        }