Exemplo n.º 1
0
        /// <summary>
        /// a与b进行碰撞检测
        /// </summary>
        /// <param name="aObj"></param>
        /// <param name="aPos"></param>
        /// <param name="bObj"></param>
        /// <param name="bPos"></param>
        /// <returns></returns>
        public static ColliderContent Collide(ColliderObject aObj, Vector3 aPos, ColliderObject bObj, Vector3 bPos)
        {
            if (aObj == null || bObj == null)
            {
                return(null);
            }

            if (aObj.m_shapes == null || bObj.m_shapes == null)
            {
                return(null);
            }

            {
                aObj.center = aPos;
                bObj.center = bPos;

                ColliderContent result = new ColliderContent();
                result.collisions?.Clear();
                bool isCollided = false;
                foreach (var aShape in aObj.m_shapes)
                {
                    foreach (var bShape in bObj.m_shapes)
                    {
                        if (aShape.Check(bShape))
                        {
                            result.collisions = result.collisions ?? new Dictionary <ColliderObject, List <ColliderShape> >();
                            if (!result.collisions.ContainsKey(bObj))
                            {
                                result.collisions[bObj] = new List <ColliderShape>();
                            }
                            result.collisions[bObj].Add(bShape);

                            isCollided = true;
                        }
                    }
                }

                if (isCollided)
                {
                    result.owner = aObj;
                    return(result);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        //碰撞检测
        public bool Collide(ColliderObject bObj, Vector3 bPos)
        {
            ColliderObject aObj = this;

            if (aObj == null || bObj == null)
            {
                return(false);
            }

            if (aObj.m_shapes == null || bObj.m_shapes == null)
            {
                return(false);
            }

            bool isCollide = false;

            {
                bObj.center = bPos;

                foreach (var aShape in aObj.m_shapes)
                {
                    foreach (var bShape in bObj.m_shapes)
                    {
                        if (aShape.Check(bShape))
                        {
                            m_result.collisions = m_result.collisions ?? new Dictionary <ColliderObject, List <ColliderShape> >();
                            if (!m_result.collisions.ContainsKey(bObj))
                            {
                                m_result.collisions[bObj] = new List <ColliderShape>();
                            }
                            m_result.collisions[bObj].Add(bShape);
                            isCollide = true;
                        }
                    }
                }
            }

            return(isCollide);
        }
Exemplo n.º 3
0
 public void Clear()
 {
     owner = null;
     collisions?.Clear();
 }