예제 #1
0
파일: TimeUnit.cs 프로젝트: maoweiming/Game
        public void Restore()
        {
            if (Rigid != null && CreateData != null)
            {
                TimeData data = FrameTimeData.Count > 0 ? FrameTimeData.Peek() : CreateData;
                Rigid.velocity        = data.Velocity;
                Rigid.gravityScale    = data.gravityScale;
                Rigid.angularVelocity = data.angularVelocity;
            }

            ClearUserData();
        }
예제 #2
0
파일: TimeUnit.cs 프로젝트: maoweiming/Game
        protected void Init(bool bCrate)
        {
            Rigid = gameObject.GetComponent <Rigidbody2D>();
            Anim  = gameObject.GetComponent <Animator>();

            FrameTimeData   = new Stack <TimeData>();
            ForwardTimeData = new Stack <TimeData>();
            UserDataTable   = new Dictionary <int, TimeUnitUserData>();

            CreateData = Snapshot(null, TimeController.Instance.CurrentFrame, bCrate);
            FrameTimeData.Push(CreateData);

            TimeController.Instance.AddUnit(this);
        }
예제 #3
0
파일: TimeUnit.cs 프로젝트: maoweiming/Game
        private TimeData Snapshot(TimeData PrevData, int frame, bool bCreate)
        {
            TimeData data = new TimeData();

            data.Frame = frame;

            if (PrevData != null && !gameObject.activeSelf)
            {
                data.State = UnitState.Deaded;
                return(data);
            }

            data.State = bCreate ? UnitState.Create : UnitState.Running;

            // 记录移动方向和距离
            var pos     = transform.position;
            var prevPos = PrevData != null ? PrevData.Position : transform.position;
            var dist    = Vector3.Distance(pos, prevPos);//B - A
            var dir     = (pos - prevPos).normalized;

            data.Direction = dist * dir;
            data.Position  = pos;

            // 物理部分
            if (Rigid != null)
            {
                data.Velocity        = Rigid.velocity;
                data.angularVelocity = Rigid.angularVelocity;
                data.gravityScale    = Rigid.gravityScale;
            }

            // 动画部分
            if (Anim != null)
            {
                if (Anim.runtimeAnimatorController != null)
                {
                    var state = Anim.GetCurrentAnimatorStateInfo(0);
                    data.AnimHash = state.fullPathHash;
                    data.AnimTime = state.normalizedTime;
                }
            }

            // 自主数据
            SaveUserData(frame);

            return(data);
        }