tk2dUIItem RaycastForUIItem(Vector2 screenPos) { int cameraCount = sortedCameras.Count; for (int i = 0; i < cameraCount; ++i) { tk2dUICamera currCamera = sortedCameras[i]; if (currCamera.RaycastType == tk2dUICamera.tk2dRaycastType.Physics3D) { #if !STRIP_PHYSICS_3D ray = currCamera.HostCamera.ScreenPointToRay(screenPos); if (Physics.Raycast(ray, out hit, currCamera.HostCamera.farClipPlane - currCamera.HostCamera.nearClipPlane, currCamera.FilteredMask)) { return(hit.collider.GetComponent <tk2dUIItem>()); } #endif } else if (currCamera.RaycastType == tk2dUICamera.tk2dRaycastType.Physics2D) { #if !(UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2) #if !STRIP_PHYSICS_2D Collider2D collider = Physics2D.OverlapPoint(currCamera.HostCamera.ScreenToWorldPoint(screenPos), currCamera.FilteredMask); if (collider != null) { return(collider.GetComponent <tk2dUIItem>()); } #endif #else Debug.LogError("Physics2D only supported in Unity 4.3 and above"); #endif } } return(null); }
public void Init() { if (UICamera == null) { UICamera = transform.GetComponent <tk2dUICamera> (); } }
void HookUpLegacyCamera(Camera cam) { if (cam.GetComponent <tk2dUICamera>() == null) { // Handle registration properly tk2dUICamera newUICam = cam.gameObject.AddComponent <tk2dUICamera>(); newUICam.AssignRaycastLayerMask(raycastLayerMask); } }
tk2dUIItem RaycastForUIItem(Vector2 screenPos) { int cameraCount = sortedCameras.Count; for (int i = 0; i < cameraCount; ++i) { tk2dUICamera currCamera = sortedCameras[i]; ray = currCamera.HostCamera.ScreenPointToRay(screenPos); if (Physics.Raycast(ray, out hit, currCamera.HostCamera.farClipPlane, currCamera.FilteredMask)) { return(hit.collider.GetComponent <tk2dUIItem>()); } } return(null); }
public Camera GetUICameraForControl(GameObject go) { int layer = 1 << go.layer; int cameraCount = allCameras.Count; for (int i = 0; i < cameraCount; ++i) { tk2dUICamera camera = allCameras[i]; if ((camera.FilteredMask & layer) != 0) { return(camera.HostCamera); } } Debug.LogError("Unable to find UI camera for " + go.name); return(null); }
void SortCameras() { sortedCameras.Clear(); int cameraCount = allCameras.Count; for (int i = 0; i < cameraCount; ++i) { tk2dUICamera camera = allCameras[i]; if (camera != null) { sortedCameras.Add(camera); } } // Largest depth gets priority sortedCameras.Sort((a, b) => b.GetComponent <Camera>().depth.CompareTo(a.GetComponent <Camera>().depth)); }
void Start() { if (uiCamera != null && uiCamera.GetComponent <tk2dUICamera>() == null) { Debug.Log("It is no longer necessary to hook up a camera to the tk2dUIManager. You can simply attach a tk2dUICamera script to the cameras that interact with UI."); // Handle registration properly tk2dUICamera cam = uiCamera.gameObject.AddComponent <tk2dUICamera>(); cam.AssignRaycastLayerMask(raycastLayerMask); uiCamera = null; } if (allCameras.Count == 0) { Debug.LogError("Unable to find any tk2dUICameras, and no cameras are connected to the tk2dUIManager. You will not be able to interact with the UI."); } }
public static void UnregisterCamera(tk2dUICamera cam) { allCameras.Remove(cam); }
public static void RegisterCamera(tk2dUICamera cam) { allCameras.Add(cam); }