コード例 #1
0
ファイル: ContactClone2D.cs プロジェクト: yuruyigit/TrueSync
 public void Restore(TrueSync.Physics2D.Contact contact)
 {
     contact._type                = this._type;
     contact._toiCount            = this._toiCount;
     contact._toi                 = this._toi;
     contact.Friction             = this.Friction;
     contact.Restitution          = this.Restitution;
     contact.TangentSpeed         = this.TangentSpeed;
     contact.Enabled              = this.Enabled;
     contact.ChildIndexA          = this.ChildIndexA;
     contact.ChildIndexB          = this.ChildIndexB;
     contact.IsTouching           = this.IsTouching;
     contact.IslandFlag           = this.IslandFlag;
     contact.TOIFlag              = this.TOIFlag;
     contact.FilterFlag           = this.FilterFlag;
     contact.FixtureA             = this.FixtureA;
     contact.FixtureB             = this.FixtureB;
     contact.Manifold.LocalNormal = this.Manifold.LocalNormal;
     contact.Manifold.LocalPoint  = this.Manifold.LocalPoint;
     contact.Manifold.PointCount  = this.Manifold.PointCount;
     for (int i = 0; i < this.Manifold.PointCount; i++)
     {
         contact.Manifold.Points[i] = this.Manifold.Points[i];
     }
     contact.Manifold.Type = this.Manifold.Type;
 }
コード例 #2
0
        internal void Update(GameObject otherGO, Physics2D.Contact c)
        {
            if (this.gameObject == null)
            {
                this.gameObject = otherGO;
                this.collider   = this.gameObject.GetComponent <TSCollider2D>();
                this.rigidbody  = this.gameObject.GetComponent <TSRigidBody2D>();
                this.transform  = this.collider.tsTransform;
            }

            if (c != null)
            {
                if (contacts[0] == null)
                {
                    contacts[0] = new TSContactPoint2D();
                }

                TSVector2 normal;
                Physics2D.FixedArray2 <TSVector2> points;

                c.GetWorldManifold(out normal, out points);

                contacts[0].normal = normal;
                contacts[0].point  = points[0];

                this.relativeVelocity = c.CalculateRelativeVelocity();
            }
        }
コード例 #3
0
ファイル: ContactClone2D.cs プロジェクト: yuruyigit/TrueSync
 public void Clone(TrueSync.Physics2D.Contact contact)
 {
     this._type        = contact._type;
     this._toiCount    = contact._toiCount;
     this._toi         = contact._toi;
     this.Friction     = contact.Friction;
     this.Restitution  = contact.Restitution;
     this.TangentSpeed = contact.TangentSpeed;
     this.Enabled      = contact.Enabled;
     this.ChildIndexA  = contact.ChildIndexA;
     this.ChildIndexB  = contact.ChildIndexB;
     this.IsTouching   = contact.IsTouching;
     this.IslandFlag   = contact.IslandFlag;
     this.TOIFlag      = contact.TOIFlag;
     this.FilterFlag   = contact.FilterFlag;
     this.FixtureA     = contact.FixtureA;
     this.FixtureB     = contact.FixtureB;
     this._nodeA.Clone(contact._nodeA);
     this._nodeB.Clone(contact._nodeB);
     this.Manifold.LocalNormal = contact.Manifold.LocalNormal;
     this.Manifold.LocalPoint  = contact.Manifold.LocalPoint;
     this.Manifold.PointCount  = contact.Manifold.PointCount;
     for (int i = 0; i < contact.Manifold.PointCount; i++)
     {
         this.Manifold.Points[i] = contact.Manifold.Points[i];
     }
     this.Manifold.Type = contact.Manifold.Type;
 }
コード例 #4
0
        private void CollisionExit(TrueSync.Physics2D.Contact contact)
        {
            if (contact.FixtureA.IsSensor || contact.FixtureB.IsSensor)
            {
                TriggerExit(contact);
                return;
            }

            CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, null, "OnSyncedCollisionExit");
        }
コード例 #5
0
        private void CollisionExit(Physics2D.Contact i_Contact)
        {
            if (i_Contact.FixtureA.IsSensor || i_Contact.FixtureB.IsSensor)
            {
                TriggerExit(i_Contact);
                return;
            }

            CallSyncedCollisionExit(i_Contact.FixtureA.Body, i_Contact.FixtureB.Body, null);
        }
コード例 #6
0
        private bool CollisionEnter(Physics2D.Contact i_Contact)
        {
            if (i_Contact.FixtureA.IsSensor || i_Contact.FixtureB.IsSensor)
            {
                TriggerEnter(i_Contact);
                return(true);
            }

            CallSyncedCollisionEnter(i_Contact.FixtureA.Body, i_Contact.FixtureB.Body, i_Contact);

            return(true);
        }
コード例 #7
0
        private bool CollisionEnter(TrueSync.Physics2D.Contact contact)
        {
            if (contact.FixtureA.IsSensor || contact.FixtureB.IsSensor)
            {
                TriggerEnter(contact);

                return(true);
            }

            CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, contact, "OnSyncedCollisionEnter");
            return(true);
        }
        internal void Update(GameObject i_OtherGO, Physics2D.Contact i_Contact)
        {
            gameObject = i_OtherGO;

            if (i_OtherGO != null)
            {
                collider  = i_OtherGO.GetComponent <TSCollider2D>();
                rigidbody = i_OtherGO.GetComponent <TSRigidBody2D>();
                transform = i_OtherGO.GetComponent <TSTransform2D>();
            }
            else
            {
                collider  = null;
                rigidbody = null;
                transform = null;
            }

            if (i_Contact != null)
            {
                if (contacts[0] == null)
                {
                    contacts[0] = new TSContactPoint2D();
                }

                TSVector2 normal;
                Physics2D.FixedArray2 <TSVector2> points;

                i_Contact.GetWorldManifold(out normal, out points);

                contacts[0].normal = normal;
                contacts[0].point  = points[0];

                relativeVelocity = i_Contact.CalculateRelativeVelocity();
            }
            else
            {
                relativeVelocity = TSVector2.zero;

                if (contacts[0] != null)
                {
                    contacts[0].normal = TSVector2.zero;
                    contacts[0].point  = TSVector2.zero;
                }
            }
        }
コード例 #9
0
        private void CollisionDetected(Physics2D.Body body1, Physics2D.Body body2, TrueSync.Physics2D.Contact contact, string callbackName)
        {
            if (!gameObjectMap.ContainsKey(body1) || !gameObjectMap.ContainsKey(body2))
            {
                return;
            }

            GameObject b1 = gameObjectMap[body1];
            GameObject b2 = gameObjectMap[body2];

            if (b1 == null || b2 == null)
            {
                return;
            }

            b1.SendMessage(callbackName, GetCollisionInfo(body1, body2, contact), SendMessageOptions.DontRequireReceiver);
            b2.SendMessage(callbackName, GetCollisionInfo(body2, body1, contact), SendMessageOptions.DontRequireReceiver);

            TrueSyncManager.UpdateCoroutines();
        }
コード例 #10
0
 public void Clone(IWorld iWorld, bool doChecksum)
 {
     TrueSync.Physics2D.World world = (TrueSync.Physics2D.World)iWorld;
     this.Reset();
     if (doChecksum)
     {
         this.checksum = ChecksumExtractor.GetEncodedChecksum();
     }
     this.clonedPhysics.Clear();
     this.index  = 0;
     this.length = world.BodyList.Count;
     while (this.index < this.length)
     {
         Body        body = world.BodyList[this.index];
         BodyClone2D @new = WorldClone2D.poolRigidBodyClone.GetNew();
         @new.Clone(body);
         this.clonedPhysics.Add(body.BodyId, @new);
         this.index++;
     }
     this.contactsClone.Clear();
     this.index  = 0;
     this.length = world.ContactList.Count;
     while (this.index < this.length)
     {
         TrueSync.Physics2D.Contact contact = world.ContactList[this.index];
         ContactClone2D             new2    = WorldClone2D.poolContactClone.GetNew();
         new2.Clone(contact);
         this.contactsClone.Add(new2);
         this.index++;
     }
     this.islandClone.Clone(world.Island);
     this.toiClone.Clone(world._input);
     this.dynamicTreeClone.Clone((DynamicTreeBroadPhase)world.ContactManager.BroadPhase);
     this._worldHasNewFixture = world._worldHasNewFixture;
     this.bodyCounter         = Body._bodyIdCounter;
     this.fixtureCounter      = Fixture._fixtureIdCounter;
 }
コード例 #11
0
 private void TriggerExit(Physics2D.Contact i_Contact)
 {
     CallSyncedTriggerExit(i_Contact.FixtureA.Body, i_Contact.FixtureB.Body, null);
 }
コード例 #12
0
 private void TriggerStay(Physics2D.Contact i_Contact)
 {
     CallSyncedTriggerStay(i_Contact.FixtureA.Body, i_Contact.FixtureB.Body, i_Contact);
 }
コード例 #13
0
        private TSCollision2D GetCollisionInfo(Physics2D.Body body1, Physics2D.Body body2, TrueSync.Physics2D.Contact c)
        {
            if (!collisionInfo.ContainsKey(body1))
            {
                collisionInfo.Add(body1, new Dictionary <Physics2D.Body, TSCollision2D>());
            }

            Dictionary <Physics2D.Body, TSCollision2D> collisionInfoBody1 = collisionInfo[body1];

            TSCollision2D result = null;

            if (collisionInfoBody1.ContainsKey(body2))
            {
                result = collisionInfoBody1[body2];
            }
            else
            {
                result = new TSCollision2D();
                collisionInfoBody1.Add(body2, result);
            }

            result.Update(gameObjectMap[body2], c);

            return(result);
        }
コード例 #14
0
 private void TriggerExit(TrueSync.Physics2D.Contact contact)
 {
     CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, null, "OnSyncedTriggerExit");
 }
コード例 #15
0
        private void CollisionDetected(Physics2D.Body body1, Physics2D.Body body2, TrueSync.Physics2D.Contact contact, string callbackName)
        {
            if (!gameObjectMap.ContainsKey(body1) || !gameObjectMap.ContainsKey(body2))
            {
                return;
            }

            GameObject b1 = gameObjectMap[body1];
            GameObject b2 = gameObjectMap[body2];

            if (b1 == null || b2 == null)
            {
                return;
            }

            HashList <TrueSyncBehaviour> b1Behaviours = behavioursMap[body1];

            for (int i = 0, count = b1Behaviours.Count; i < count; i++)
            {
                TSCollision2D collision = GetCollisionInfo(body1, body2, contact);
                if (String.Equals(callbackName, "OnSyncedCollisionEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionEnter2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionStay2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedCollisionExit2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerEnter2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerStay2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b1Behaviours[i].OnSyncedTriggerExit2D(collision);
                }
            }

            HashList <TrueSyncBehaviour> b2Behaviours = behavioursMap[body2];

            for (int i = 0, count = b2Behaviours.Count; i < count; i++)
            {
                TSCollision2D collision = GetCollisionInfo(body2, body1, contact);
                if (String.Equals(callbackName, "OnSyncedCollisionEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionEnter2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionStay2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedCollisionExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedCollisionExit2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerEnter", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerEnter2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerStay", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerStay2D(collision);
                }
                else if (String.Equals(callbackName, "OnSyncedTriggerExit", StringComparison.InvariantCultureIgnoreCase))
                {
                    b2Behaviours[i].OnSyncedTriggerExit2D(collision);
                }
            }

            TrueSyncManager.UpdateCoroutines();
        }
コード例 #16
0
        private void CallSyncedTriggerExit(Physics2D.Body i_Body1, Physics2D.Body i_Body2, Physics2D.Contact i_Contact)
        {
            GameObject b1;

            m_GameObjectMap.TryGetValue(i_Body1, out b1);

            GameObject b2;

            m_GameObjectMap.TryGetValue(i_Body2, out b2);

            if (b1 == null || b2 == null)
            {
                return;
            }

            // Notify b1.

            {
                TrueSyncBehaviour[] trueSyncBehaviours = b1.GetComponentsInChildren <TrueSyncBehaviour>();
                if (trueSyncBehaviours != null)
                {
                    for (int index = 0; index < trueSyncBehaviours.Length; ++index)
                    {
                        TrueSyncBehaviour behaviour = trueSyncBehaviours[index];
                        behaviour.OnSyncedTriggerExit(FillCollisionInfo(b2, i_Contact));
                    }
                }
            }

            // Notify b2.

            {
                TrueSyncBehaviour[] trueSyncBehaviours = b2.GetComponentsInChildren <TrueSyncBehaviour>();
                if (trueSyncBehaviours != null)
                {
                    for (int index = 0; index < trueSyncBehaviours.Length; ++index)
                    {
                        TrueSyncBehaviour behaviour = trueSyncBehaviours[index];
                        behaviour.OnSyncedTriggerExit(FillCollisionInfo(b1, i_Contact));
                    }
                }
            }

            // Clear cache.

            ClearCollisionCache();
        }
コード例 #17
0
 public void Restore(IWorld iWorld)
 {
     TrueSync.Physics2D.World world = (TrueSync.Physics2D.World)iWorld;
     this.bodiesToRemove.Clear();
     this.index  = 0;
     this.length = world.BodyList.Count;
     while (this.index < this.length)
     {
         Body body = world.BodyList[this.index];
         bool flag = !this.clonedPhysics.ContainsKey(body.BodyId);
         if (flag)
         {
             this.bodiesToRemove.Add(body);
         }
         this.index++;
     }
     this.index  = 0;
     this.length = this.bodiesToRemove.Count;
     while (this.index < this.length)
     {
         Body body2 = this.bodiesToRemove[this.index];
         world.RemoveBody(body2);
         this.index++;
     }
     world.ProcessRemovedBodies();
     this.index  = 0;
     this.length = world.BodyList.Count;
     while (this.index < this.length)
     {
         Body body3 = world.BodyList[this.index];
         bool flag2 = this.clonedPhysics.ContainsKey(body3.BodyId);
         if (flag2)
         {
             BodyClone2D bodyClone2D = this.clonedPhysics[body3.BodyId];
             bodyClone2D.Restore(body3);
         }
         this.index++;
     }
     this.index  = 0;
     this.length = world.ContactList.Count;
     while (this.index < this.length)
     {
         TrueSync.Physics2D.Contact item = world.ContactList[this.index];
         world._contactPool.Enqueue(item);
         this.index++;
     }
     world.ContactList.Clear();
     this.contactDic.Clear();
     this.index  = 0;
     this.length = this.contactsClone.Count;
     while (this.index < this.length)
     {
         ContactClone2D             contactClone2D = this.contactsClone[this.index];
         bool                       flag3          = world._contactPool.Count > 0;
         TrueSync.Physics2D.Contact contact;
         if (flag3)
         {
             contact = world._contactPool.Dequeue();
         }
         else
         {
             contact = new TrueSync.Physics2D.Contact();
         }
         contactClone2D.Restore(contact);
         this.contactDic.Add(contact.Key, contact);
         world.ContactList.Add(contact);
         this.index++;
     }
     this.contactEdgeDic.Clear();
     this.index  = 0;
     this.length = this.contactsClone.Count;
     while (this.index < this.length)
     {
         ContactClone2D contactClone2D2 = this.contactsClone[this.index];
         this.contactDic[contactClone2D2.Key]._nodeA = contactClone2D2._nodeA.Restore(false, this.contactDic, this.contactEdgeDic);
         this.contactDic[contactClone2D2.Key]._nodeB = contactClone2D2._nodeB.Restore(false, this.contactDic, this.contactEdgeDic);
         this.index++;
     }
     this.index  = 0;
     this.length = this.contactsClone.Count;
     while (this.index < this.length)
     {
         ContactClone2D contactClone2D3 = this.contactsClone[this.index];
         this.contactDic[contactClone2D3.Key]._nodeA = contactClone2D3._nodeA.Restore(true, this.contactDic, this.contactEdgeDic);
         this.contactDic[contactClone2D3.Key]._nodeB = contactClone2D3._nodeB.Restore(true, this.contactDic, this.contactEdgeDic);
         this.index++;
     }
     this.index  = 0;
     this.length = world.BodyList.Count;
     while (this.index < this.length)
     {
         Body body4 = world.BodyList[this.index];
         bool flag4 = this.clonedPhysics.ContainsKey(body4.BodyId);
         if (flag4)
         {
             BodyClone2D bodyClone2D2 = this.clonedPhysics[body4.BodyId];
             bool        flag5        = bodyClone2D2.contactEdgeClone != null;
             if (flag5)
             {
                 bodyClone2D2.contactEdgeClone.Restore(false, this.contactDic, this.contactEdgeDic);
             }
             else
             {
                 body4.ContactList = null;
             }
         }
         this.index++;
     }
     this.index  = 0;
     this.length = world.BodyList.Count;
     while (this.index < this.length)
     {
         Body body5 = world.BodyList[this.index];
         bool flag6 = this.clonedPhysics.ContainsKey(body5.BodyId);
         if (flag6)
         {
             BodyClone2D bodyClone2D3 = this.clonedPhysics[body5.BodyId];
             bool        flag7        = bodyClone2D3.contactEdgeClone != null;
             if (flag7)
             {
                 body5.ContactList = bodyClone2D3.contactEdgeClone.Restore(true, this.contactDic, this.contactEdgeDic);
             }
         }
         this.index++;
     }
     this.islandClone.Restore(world.Island, this.contactDic);
     this.toiClone.Restore(world._input);
     TreeNode <FixtureProxy>[] nodes = ((DynamicTreeBroadPhase)world.ContactManager.BroadPhase)._tree._nodes;
     this.index  = 0;
     this.length = nodes.Length;
     while (this.index < this.length)
     {
         TreeNode <FixtureProxy> obj = nodes[this.index];
         WorldClone2D.poolTreeFixtureProxy.GiveBack(obj);
         this.index++;
     }
     this.dynamicTreeClone.Restore((DynamicTreeBroadPhase)world.ContactManager.BroadPhase);
     world._worldHasNewFixture = this._worldHasNewFixture;
     Body._bodyIdCounter       = this.bodyCounter;
     Fixture._fixtureIdCounter = this.fixtureCounter;
 }
コード例 #18
0
 private TSCollision2D FillCollisionInfo(GameObject i_Go, Physics2D.Contact i_Contact)
 {
     m_CollisionCache.Update(i_Go, i_Contact);
     return(m_CollisionCache);
 }
コード例 #19
0
 private void TriggerStay(TrueSync.Physics2D.Contact contact)
 {
     CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, contact, "OnSyncedTriggerStay");
 }