Esempio n. 1
0
 public void CheckCollision(List <ICollider> colliderList)
 {
     foreach (ICollider collider in colliderList)
     {
         foreach (ICollider colliderWith in colliderList)
         {
             if (collider != null && colliderWith != null)
             {
                 if (collider != colliderWith)
                 {
                     if (collider is RectangleCollider)
                     {
                         RectangleCollider rectangleCollider = (RectangleCollider)collider;
                         if (colliderWith is RectangleCollider)
                         {
                             RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith;
                             //if (rectangleCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength())
                             //{
                             if (rectangleCollider.IsCollided(rectangleColliderWith))
                             {
                                 rectangleCollider.Parent.CollisionHappened = true;
                                 rectangleCollider.Parent.CollidedWith      = rectangleColliderWith;
                             }
                             //}
                         }
                         else if (colliderWith is SphereCollider)
                         {
                             SphereCollider sphereColliderWith = (SphereCollider)colliderWith;
                             //if (rectangleCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength())
                             //{
                             if (rectangleCollider.IsCollided(sphereColliderWith))
                             {
                                 rectangleCollider.Parent.CollisionHappened = true;
                                 rectangleCollider.Parent.CollidedWith      = sphereColliderWith;
                             }
                             //}
                         }
                     }
                     else if (collider is SphereCollider)
                     {
                         SphereCollider sphereCollider = (SphereCollider)collider;
                         if (colliderWith is RectangleCollider)
                         {
                             RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith;
                             //if (sphereCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4))
                             //{
                             if (sphereCollider.IsCollided(rectangleColliderWith))
                             {
                                 sphereCollider.Parent.CollisionHappened = true;
                                 sphereCollider.Parent.CollidedWith      = rectangleColliderWith;
                             }
                             //}
                         }
                         else if (colliderWith is SphereCollider)
                         {
                             SphereCollider sphereColliderWith = (SphereCollider)colliderWith;
                             //if (sphereCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4))
                             //{
                             if (sphereCollider.IsCollided(sphereColliderWith))
                             {
                                 sphereCollider.Parent.CollisionHappened = true;
                                 sphereCollider.Parent.CollidedWith      = sphereColliderWith;
                             }
                             //}
                         }
                     }
                 }
             }
         }
     }
 }
        public void CheckCollision(List <ICollider> colliderList)
        {
            List <ICollider> test = new List <ICollider>();

            foreach (ICollider item in colliderList)
            {
                if (item != null)
                {
                    test.Add(item);
                    //MyConsole.Out(((Component)item).Parent.ObjectName);
                }
            }

            for (int i = 0; i < test.Count; i++)
            {
                ICollider collider = test[i];
                for (int k = 0; k < test.Count; k++)
                {
                    ICollider colliderWith = test[k];
                    if (i != k)
                    {
                        if (collider is RectangleCollider)
                        {
                            RectangleCollider rectangleCollider = (RectangleCollider)collider;
                            if (colliderWith is RectangleCollider)
                            {
                                RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith;
                                //if (rectangleCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength())
                                //{
                                if (rectangleCollider.IsCollided(rectangleColliderWith))
                                {
                                    //rectangleCollider.Parent.CollisionHappened = true;
                                    //rectangleCollider.Parent.CollidedWith = rectangleColliderWith;
                                }
                                //}
                            }
                            if (colliderWith is SphereCollider)
                            {
                                SphereCollider sphereColliderWith = (SphereCollider)colliderWith;
                                //if (rectangleCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (rectangleCollider.Size * 2).GetLength())
                                //{
                                if (rectangleCollider.IsCollided(sphereColliderWith))
                                {
                                    //rectangleCollider.Parent.CollisionHappened = true;
                                    //rectangleCollider.Parent.CollidedWith = sphereColliderWith;
                                }
                                //}
                            }
                        }
                        if (collider is SphereCollider)
                        {
                            SphereCollider sphereCollider = (SphereCollider)collider;
                            if (colliderWith is RectangleCollider)
                            {
                                RectangleCollider rectangleColliderWith = (RectangleCollider)colliderWith;
                                //if (sphereCollider.Parent.transform.Position.GetDistance(rectangleColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4))
                                //{
                                if (sphereCollider.IsCollided(rectangleColliderWith))
                                {
                                    //sphereCollider.Parent.CollisionHappened = true;
                                    //sphereCollider.Parent.CollidedWith = rectangleColliderWith;
                                }
                                //}
                            }
                            if (colliderWith is SphereCollider)
                            {
                                SphereCollider sphereColliderWith = (SphereCollider)colliderWith;
                                //if (sphereCollider.Parent.transform.Position.GetDistance(sphereColliderWith.Parent.transform.Position) < (sphereCollider.Radius * 4))
                                //{
                                if (sphereCollider.IsCollided(sphereColliderWith))
                                {
                                    //sphereCollider.Parent.CollisionHappened = true;
                                    //sphereCollider.Parent.CollidedWith = sphereColliderWith;
                                }
                                //}
                            }
                        }
                    }
                }
            }
        }