/// <summary>Attempts to find the element from the set WorldUI; if there is no WorldUI, the main UI is used. /// This search uses the triangle of the hit to figure out exactly which element was clicked.</summary> /// <param name="hit">The hit in 3D that must be resolved to an element.</param> public void FindElement(RaycastHit hit) { // Which triangle was hit, and as a result, which element did it come from? // If the element is found, apply it to our result; otherwise assume unsuccessful hit. Renderman renderer = null; if (OnWorldUI != null) { renderer = OnWorldUI.Renderer; } else { renderer = UI.GetRenderer(); } if (renderer == null) { return; } Transform transform = hit.transform; // Which batch? Will only be from the non-pooled ones: UIBatch current = renderer.FirstBatch; while (current != null) { if (current.Mesh.OutputTransform == transform) { // Got it! break; } current = current.BatchAfter; } if (current == null) { return; } // Current is the batch the hit was on. Next, resolve to the MeshBlock and finally to the element that made it. }
/// <summary>Called on a pool if a camera was requested. /// This call occurs when something on the main UI is being rendered ontop of an inline camera.</summary> public bool CheckCameraRequired() { if (!CameraRequested) { return(false); } // Clear the request: CameraRequested = false; // A camera is required! // Get the main UI renderer: Renderman renderer = UI.GetRenderer(); // We must create a UICamera (or pull one from the pool): UICamera camera = GetPooledCamera(); if (camera == null) { // Create one: camera = new UICamera(renderer); } // Add it to the main set: AddCamera(camera); // Next, set the current depth: camera.SetDepth(AllocatedDepth); // Finally, we must now make sure any batches are parented to this new camera. // We do this by setting it to the root of the renderer: renderer.Node = camera.Gameobject; return(true); }