static public bool PtInCollider( Collider col, Collider excludeCol, Ray ray, bool all=false) { bool ret = false; if( true == all) { RaycastHit hit = new RaycastHit(); ret = col.Raycast( ray, out hit, 500.0f); } else { IComparer comp = new DepthComparer(); RaycastHit[] hits = Physics.RaycastAll( ray); if( 0 == hits.Length) return false; Array.Sort( hits, comp); int index = 0; if( excludeCol == hits[0].collider) index = 1; ret = ( col == hits[ index].collider) ? true : false; } return ret; }
static public bool PtInCollider( Camera cam, Collider col, Vector2 pt, bool all=false) { bool ret = false; if( true == all) { Ray ray = cam.ScreenPointToRay( new Vector3( pt.x, pt.y, 0.0f)); RaycastHit hit = new RaycastHit(); ret = col.Raycast( ray, out hit, 500.0f); } else { IComparer comp = new DepthComparer(); Ray ray = cam.ScreenPointToRay( new Vector3( pt.x, pt.y, 0.0f)); RaycastHit[] hits = Physics.RaycastAll( ray); if( 0 == hits.Length) return false; Array.Sort( hits, comp); ret = ( col == hits[0].collider) ? true : false; } return ret; }