using UnityEngine;
using System.Collections;

public class CollisionHelper
{
	
	public static void ignoreCollisionWithTag(GameObject object1, string tag, bool ignore)
	{
		Collider2D[] colliders = object1.GetComponents<Collider2D>();
		
		GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag(tag);
		foreach (GameObject taggedObject in taggedObjects)
		{
			for (int i = 0; i < colliders.Length; i++)
			{
				Physics2D.IgnoreCollision(colliders[i], taggedObject.GetComponent<Collider2D>(), ignore);
			}
		}
	}
	
	public static bool isObjectOffscreen(Transform trans, float forceSize)
	{
		float size = 0f;
		if (forceSize > 0f)
		{
			size = forceSize;
		}
		else if (trans.GetComponent<BoxCollider2D>() != null)
		{
			size = trans.GetComponent<BoxCollider2D>().size.x;
			if (trans.GetComponent<BoxCollider2D>().size.y > trans.GetComponent<BoxCollider2D>().size.x)
				size = trans.GetComponent<BoxCollider2D>().size.y;
			size *= trans.lossyScale.x;
		}
		else if (trans.GetComponent<CircleCollider2D>() != null)
		{
			size = trans.GetComponent<CircleCollider2D>().radius;
			size *= trans.lossyScale.x;
		}
		
		return (trans.position.x > (Camera.main.orthographicSize * 16f / 9f) + size
		        || trans.position.x < (Camera.main.orthographicSize * -16f / 9) - size
		        || trans.position.y > (Camera.main.orthographicSize) + size
		        || trans.position.y < (Camera.main.orthographicSize * -1f) - size);
	}
}
