Exemplo n.º 1
0
        // CTOR

        public Physics2DWorldManager()
        {
            m_GameObjectMap = new Dictionary <IBody, GameObject>();
            m_RigidBodies   = new List <TSRigidBody2D>();

            m_CollisionCache = new TSCollision2D();
        }
        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);
        }
        // TrueSyncBehaviour's interface

        public override void OnSyncedTriggerStay(TSCollision2D i_Collision)
        {
            base.OnSyncedCollisionStay(i_Collision);

            GameObject otherGo = i_Collision.gameObject;

            if (otherGo == null)
            {
                return;
            }

            bool valid = ValidateGameObject(otherGo);

            if (!valid)
            {
                return;
            }

            if (m_Running)
            {
                FP deltaTime = TrueSyncManager.deltaTimeMain;

                TSRigidBody2D rigidbody = otherGo.GetComponent <TSRigidBody2D>();
                if (rigidbody != null)
                {
                    // Drag

                    TSVector2 currentVelocity = rigidbody.velocity;
                    currentVelocity   *= FP.One / (FP.One + (deltaTime * m_Drag));
                    rigidbody.velocity = currentVelocity;

                    // Force

                    FP angle = MathFP.ClampAngle(m_ForceAngle, FP.Zero, 360f);

                    TSVector2 forceDirection = TSVector2.right;
                    forceDirection = forceDirection.Rotate(angle);

                    rigidbody.AddForce(forceDirection * m_ForceMagnitude);
                }
            }
        }
Exemplo n.º 4
0
 /**
  * @brief Callback called when trigger2d exit.
  **/
 public virtual void OnSyncedTriggerExit2D(TSCollision2D other)
 {
 }
Exemplo n.º 5
0
 /**
  * @brief Callback called when collision2d exit.
  **/
 public virtual void OnSyncedCollisionExit2D(TSCollision2D other)
 {
 }
Exemplo n.º 6
0
 /**
  * @brief Callback called when collision2d stay.
  **/
 public virtual void OnSyncedCollisionStay2D(TSCollision2D other)
 {
 }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
 /**
  * @brief OnSyncedTriggerExit.
  **/
 public virtual void OnSyncedTriggerExit(TSCollision2D i_Collision)
 {
 }
Exemplo n.º 9
0
 /**
  * @brief OnSyncedCollisionExit.
  **/
 public virtual void OnSyncedCollisionExit(TSCollision2D i_Collision)
 {
 }
Exemplo n.º 10
0
 /**
  * @brief OnSyncedCollisionStay.
  **/
 public virtual void OnSyncedCollisionStay(TSCollision2D i_Collision)
 {
 }