コード例 #1
0
        public void BeginSimulation(uint tick)
        {
            lastIndex = MomentumIndexForTick(tick);
            if (!lastIndex.valid)
            {
                lastIndex = TrailIndex.zero;
            }

            if (currentIndex != lastIndex)
            {
                ClearContacts();
                ApplyMomentum(this[lastIndex]);
            }

            if (lastIndex.segment < momentums.Count - 1)
            {
                momentums.RemoveRange(
                    lastIndex.segment + 1,
                    momentums.Count - (lastIndex.segment + 1));
            }

            int nextMomI = lastIndex.momentum + 1;

            while (nextMomI < momentums[lastIndex.segment].Length &&
                   momentums[lastIndex.segment][nextMomI] != null)
            {
                Momentum2D.Release(momentums[lastIndex.segment][nextMomI++]);
                momentums[lastIndex.segment][nextMomI++] = null;
            }
        }
コード例 #2
0
 void Start()
 {
     body         = GetComponent <Rigidbody2D>();
     momentums    = new List <Momentum2D[]>(1);
     currentIndex = lastIndex = TrailIndex.zero;
     Momentum2D[] segment = new Momentum2D[segmentSize];
     segment[0] = ExtractMomentum((uint)(Time.fixedTime / Time.fixedDeltaTime));
     momentums.Add(segment);
 }
コード例 #3
0
        public void SendContactEvents(uint tick)
        {
            Momentum2D momentum = MomentumForTick(tick);

            if (CollisionEnterEvent != null && momentum.collisionsEnter != null)
            {
                foreach (Collision2D collision in momentum.collisionsEnter)
                {
                    CollisionEnterEvent(tick, collision);
                }
            }

            if (CollisionStayEvent != null && momentum.collisionsStay != null)
            {
                foreach (Collision2D collision in momentum.collisionsStay)
                {
                    CollisionStayEvent(tick, collision);
                }
            }

            if (CollisionExitEvent != null && momentum.collisionsExit != null)
            {
                foreach (Collision2D collision in momentum.collisionsExit)
                {
                    CollisionExitEvent(tick, collision);
                }
            }

            if (TriggerEnterEvent != null && momentum.triggersEnter != null)
            {
                foreach (Collider2D collision in momentum.triggersEnter)
                {
                    TriggerEnterEvent(tick, collision);
                }
            }

            if (TriggerStayEvent != null && momentum.triggersStay != null)
            {
                foreach (Collider2D collision in momentum.triggersStay)
                {
                    TriggerStayEvent(tick, collision);
                }
            }

            if (TriggerExitEvent != null && momentum.triggersExit != null)
            {
                foreach (Collider2D collision in momentum.triggersExit)
                {
                    TriggerExitEvent(tick, collision);
                }
            }
        }
コード例 #4
0
 Momentum2D ExtractMomentum(uint tick)
 {
     return(Momentum2D.GetMomentum(
                tick,
                transform.position,
                transform.rotation,
                body.velocity,
                body.angularVelocity,
                body.IsSleeping(),
                collisionsEnter, collisionsStay, collisionsExit,
                triggersEnter, triggersStay, triggersExit
                ));
 }
コード例 #5
0
 void ApplyMomentum(Momentum2D momentum)
 {
     transform.SetPositionAndRotation(
         momentum.position,
         momentum.rotation
         );
     body.velocity        = momentum.velocity;
     body.angularVelocity = momentum.angularVelocity;
     if (body.IsSleeping() && !momentum.sleeping)
     {
         body.WakeUp();
     }
     else if (body.IsAwake() && momentum.sleeping)
     {
         body.Sleep();
     }
 }
コード例 #6
0
        public bool GoToTime(uint tick, uint keepTick = 0)
        {
            TrailIndex i = MomentumIndexForTick(tick);

            bool success = GoToIndex(i);

            uint pastTick = Math.Max(tick - keepTick, 0);
            int  pastSegI = 0;

            while (pastSegI + 1 <= i.segment &&
                   momentums[pastSegI + 1][0].tick <= pastTick)
            {
                pastSegI++;
            }

            if (pastSegI > 0)
            {
                currentIndex = new TrailIndex(
                    currentIndex.segment - pastSegI,
                    currentIndex.momentum
                    );
                lastIndex = new TrailIndex(
                    lastIndex.segment - pastSegI,
                    lastIndex.momentum
                    );

                if (!Momentum2D.IsPoolFull())
                {
                    for (int segI = 0; segI < pastSegI; segI++)
                    {
                        Momentum2D.Release(momentums[segI]);
                        if (Momentum2D.IsPoolFull())
                        {
                            break;
                        }
                    }
                }

                momentums.RemoveRange(0, pastSegI);
            }


            return(success);
        }