protected void Update() { // Handle mouse input if (!MiddleVR.VRClusterMgr.IsClient()) { if (!m_IgnorePhysicalMouseInput) { Vector2 mouseHit = new Vector2(0, 0); bool hasMouseHit = false; GUITexture guiTexture = gameObject.GetComponent <GUITexture>(); if (m_MouseInteractionsIn2D && guiTexture != null) { // GUITexture mouse input Rect r = guiTexture.GetScreenRect(); if (Input.mousePosition.x >= r.x && Input.mousePosition.x < (r.x + r.width) && Input.mousePosition.y >= r.y && Input.mousePosition.y < (r.y + r.height)) { float x = (Input.mousePosition.x - r.x) / r.width; float y = (Input.mousePosition.y - r.y) / r.height; mouseHit = new Vector2(x, y); hasMouseHit = true; } } else if (m_MouseInteractionsIn3D && gameObject.GetComponent <Renderer>() != null) { // 3D object mouse input mouseHit = GetClosestMouseHit(); if (mouseHit.x != -1 && mouseHit.y != -1) { hasMouseHit = true; } } if (hasMouseHit) { bool isMouseButtonPressed = Input.GetMouseButton(0); if (!m_IsVirtualMouseButtonPressed && isMouseButtonPressed) { SetVirtualMousePosition(mouseHit); SetVirtualMouseButtonPressed(); } else if (m_IsVirtualMouseButtonPressed && !isMouseButtonPressed) { SetVirtualMouseButtonReleased(); SetVirtualMousePosition(mouseHit); } else { SetVirtualMousePosition(mouseHit); } } } m_IgnorePhysicalMouseInput = false; } // Handle texture update if (m_Image.HasChanged()) { using (vrImageFormat format = m_Image.GetImageFormat()) { if ((uint)m_Texture.width != format.GetWidth() || (uint)m_Texture.height != format.GetHeight()) { #if VRWEBVIEW_UNITY_FREE m_PixelsHandle.Free(); #endif m_Texture.Resize((int)format.GetWidth(), (int)format.GetHeight()); m_Texture.Apply(false, false); #if VRWEBVIEW_UNITY_FREE m_PixelsHandle.Free(); m_Pixels = m_Texture.GetPixels32(0); m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned); #else MiddleVR_CancelCopyBufferToTexture(m_NativeTexturePtr); m_NativeTexturePtr = m_Texture.GetNativeTexturePtr(); #endif } if (format.GetWidth() > 0 && format.GetHeight() > 0) { #if VRWEBVIEW_UNITY_FREE m_Image.GetReadBufferData(m_PixelsHandle.AddrOfPinnedObject()); m_Texture.SetPixels32(m_Pixels, 0); m_Texture.Apply(false, false); #else MiddleVR_AsyncCopyBufferToTexture(m_Image.GetReadBuffer(), m_NativeTexturePtr, format.GetWidth(), format.GetHeight()); GL.IssuePluginEvent(MVR_RENDEREVENT_COPYBUFFERSTOTEXTURES); #endif } } } }
protected void Update() { // Handle mouse input if (!MiddleVR.VRClusterMgr.IsClient()) { if (!m_IgnorePhysicalMouseInput) { Vector2 mouseHit = new Vector2(0, 0); bool hasMouseHit = false; if (gameObject.GetComponent <GUITexture>() != null) { // GUITexture mouse input Rect r = gameObject.GetComponent <GUITexture>().GetScreenRect(); if (Input.mousePosition.x >= r.x && Input.mousePosition.x < (r.x + r.width) && Input.mousePosition.y >= r.y && Input.mousePosition.y < (r.y + r.height)) { float x = (Input.mousePosition.x - r.x) / r.width; float y = (Input.mousePosition.y - r.y) / r.height; mouseHit = new Vector2(x, y); hasMouseHit = true; } } else if (gameObject.GetComponent <Renderer>() != null && Application.isEditor) { // 3D object mouse input mouseHit = GetClosestMouseHit(); if (mouseHit.x != -1 && mouseHit.y != -1) { hasMouseHit = true; } } if (hasMouseHit) { bool newMouseButtonState = Input.GetMouseButton(0); if (m_MouseButtonState == false && newMouseButtonState == true) { SetVirtualMousePosition(mouseHit); SetVirtualMouseButtonPressed(); } else if (m_MouseButtonState == true && newMouseButtonState == false) { SetVirtualMouseButtonReleased(); SetVirtualMousePosition(mouseHit); } else { SetVirtualMousePosition(mouseHit); } m_MouseButtonState = newMouseButtonState; } } m_IgnorePhysicalMouseInput = false; } // Handle texture update if (m_Image.HasChanged()) { using (vrImageFormat format = m_Image.GetImageFormat()) { if ((uint)m_Texture.width != format.GetWidth() || (uint)m_Texture.height != format.GetHeight()) { #if VRWEBVIEW_UNITY_FREE m_PixelsHandle.Free(); #endif m_Texture.Resize((int)format.GetWidth(), (int)format.GetHeight()); m_Texture.Apply(false, false); #if VRWEBVIEW_UNITY_FREE m_PixelsHandle.Free(); m_Pixels = m_Texture.GetPixels32(0); m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned); #endif } if (format.GetWidth() > 0 && format.GetHeight() > 0) { #if VRWEBVIEW_UNITY_FREE m_Image.GetReadBufferData(m_PixelsHandle.AddrOfPinnedObject()); m_Texture.SetPixels32(m_Pixels, 0); m_Texture.Apply(false, false); #else MiddleVR_CopyBufferToUnityNativeTexture(m_Image.GetReadBuffer(), m_Texture.GetNativeTexturePtr(), format.GetWidth(), format.GetHeight()); #endif } } } }