public void AddKeyInColliderDictionary(GameObject source, GameObject target, bool isCollider)
    {
        foreach (ColliderPair cp in m_ColliderDictionary.Keys)
        {
            if (source == cp.Source_ && target == cp.Target_)
            {
                if (!isCollider) //碰撞结束,从列表中拿掉
                {
                    m_ColliderDictionary.Remove (cp);
                } else
                {
                    m_ColliderDictionary[cp] = isCollider;
                }

                return;
            }
        }

        if (isCollider) //保存正在碰撞的
        {
            ColliderPair colliderPair = new ColliderPair ();
            colliderPair.Source_ = source;
            colliderPair.Target_ = target;
            m_ColliderDictionary [colliderPair] = isCollider;
        }
    }
Exemple #2
0
    public static void IgnoreCollision(Collider collider1, Collider collider2)
    {
        ColliderPair pair = new ColliderPair(collider1, collider2);

        if (ignoredCollisions.ContainsKey(pair))
        {
            ignoredCollisions[pair]++;
        }
        else
        {
            Physics.IgnoreCollision(pair.col1, pair.col2, true);
            ignoredCollisions.Add(pair, 1);
        }
    }
Exemple #3
0
    public static void RestoreCollision(Collider collider1, Collider collider2)
    {
        ColliderPair pair = new ColliderPair(collider1, collider2);

        if (ignoredCollisions.ContainsKey(pair))
        {
            if (ignoredCollisions[pair] <= 1)
            {
                Physics.IgnoreCollision(pair.col1, pair.col2, false);
                ignoredCollisions.Remove(pair);
            }
            else
            {
                ignoredCollisions[pair]--;
            }
        }
    }
Exemple #4
0
    override public List <ColliderPair> ComputePairs()
    {
        m_pairs.Clear();

        // outer loop
        for (var i = 0; i < m_aabbs.Count; i++)
        {
            // inner loop
            var jStart = i;
            for (var j = ++jStart; j < m_aabbs.Count; ++j)
            {
                var aabbA     = m_aabbs[i];
                var aabbB     = m_aabbs[j];
                var colliderA = aabbA.Collider();
                var colliderB = aabbB.Collider();
                var bodyA     = colliderA.Body();
                var bodyB     = colliderB.Body();

                // skip same-body collision
                if (bodyA == bodyB)
                {
                    continue;
                }

                // add collider pair
                if (aabbA.Collides(aabbB))
                {
                    var pair = new ColliderPair {
                        a = aabbA.Collider(),
                        b = aabbB.Collider()
                    };
                    m_pairs.Add(pair);
                }
            }     // end of inner loop
        }         // end of outer loop

        return(m_pairs);
    }