Exemplo n.º 1
0
        public void RemoveBody(IBody iBody)
        {
            world.RemoveBody((TrueSync.Physics2D.Body)iBody);
            world.ProcessRemovedBodies();

            gameObjectMap.Remove(iBody);
            behavioursMap.Remove(iBody);

            // TODO: remove iBody from collisioninfo
        }
        private static object OverlapGeneric(Physics2D.Shape i_Shape, TSVector2 i_Position, Physics2D.BodySpecialSensor i_SensorType, int i_Mask)
        {
            Physics2D.World world = (Physics2D.World)PhysicsManager.GetWorld();

            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world);
            body.CreateFixture(i_Shape);

            body.BodyType = Physics2D.BodyType.Static;

            body.CollisionCategories = Physics2D.Category.All; // Category.All is used for sweep test objects.
            body.CollidesWith        = (Physics2D.Category)i_Mask;

            body.CollisionGroup = 0;

            body.IsSensor          = true;
            body.SpecialSensor     = i_SensorType;
            body.SpecialSensorMask = (int)Physics2D.Category.All;

            body.Position = i_Position;

            world.RemoveBody(body);
            world.ProcessRemovedBodies();

            if (body._specialSensorResults.Count > 0)
            {
                if (i_SensorType == Physics2D.BodySpecialSensor.ActiveOnce)
                {
                    return(PhysicsManager.GetGameObject(body._specialSensorResults[0]).GetComponent <TSCollider2D>());
                }
                else
                {
                    TSCollider2D[] result = new TSCollider2D[body._specialSensorResults.Count];
                    for (int i = 0; i < body._specialSensorResults.Count; i++)
                    {
                        result[i] = PhysicsManager.GetGameObject(body._specialSensorResults[i]).GetComponent <TSCollider2D>();
                    }

                    return(result);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        private static object OverlapGeneric(Physics2D.Shape shape, TSVector2 position, Physics2D.BodySpecialSensor sensorType, int layerMask)
        {
            Physics2D.World world = (Physics2D.World)Physics2DWorldManager.instance.GetWorld();

            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world);
            body.CreateFixture(shape);

            body.BodyType     = Physics2D.BodyType.Static;
            body.IsSensor     = true;
            body.CollidesWith = Physics2D.Category.All;

            body.SpecialSensor     = sensorType;
            body.SpecialSensorMask = layerMask;
            body.Position          = position;

            world.RemoveBody(body);
            world.ProcessRemovedBodies();

            if (body._specialSensorResults.Count > 0)
            {
                if (sensorType == Physics2D.BodySpecialSensor.ActiveOnce)
                {
                    return(Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[0]).GetComponent <TSCollider2D>());
                }
                else
                {
                    TSCollider2D[] result = new TSCollider2D[body._specialSensorResults.Count];
                    for (int i = 0; i < body._specialSensorResults.Count; i++)
                    {
                        result[i] = Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[i]).GetComponent <TSCollider2D>();
                    }

                    return(result);
                }
            }

            return(null);
        }
Exemplo n.º 4
0
 public void RemoveBody(IBody i_Body)
 {
     m_World.RemoveBody((Physics2D.Body)i_Body);
     m_World.ProcessRemovedBodies();
 }
 public void RemoveBody(IBody iBody)
 {
     world.RemoveBody((TrueSync.Physics2D.Body)iBody);
     world.ProcessRemovedBodies();
 }
Exemplo n.º 6
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;
 }