private void Update() { if (testMode == TestMode.CustomInput) { #if UNITY_EDITOR_WIN || ((UNITY_STANDALONE_WIN || UNITY_WSA) && !UNITY_EDITOR) int state = 0; int key = 0; if (InputTools.GetMouseState(ref state, ref key)) { Vector2 position = new Vector2(); Rect target = new Rect(0, 0, webView.GetActualWidth(), webView.GetActualHeight()); position.x = Input.mousePosition.x * (target.width / Screen.width); position.y = (Screen.height - margine - Input.mousePosition.y) * (target.height / (Screen.height - margine)); if (target.Contains(position)) { webView.InputEvent(state, key, (int)position.x, (int)position.y); } } #else Debug.LogWarning("Texturing feature is only supported on Win32/WSA/Windows Editor."); #endif } }
private void Update() { #if UNITY_EDITOR_WIN || ((UNITY_STANDALONE_WIN || UNITY_WSA) && !UNITY_EDITOR) int state = 0; int key = 0; if (InputTools.GetMouseState(ref state, ref key)) { RaycastHit hit; if (!Physics.Raycast(viewCamera.ScreenPointToRay(Input.mousePosition), out hit)) { Debug.Log("There was an input outside the webview area."); return; } Renderer renderer = hit.transform.GetComponent <Renderer>(); MeshCollider meshCollider = hit.collider as MeshCollider; if (renderer == null || renderer.sharedMaterial == null || renderer.sharedMaterial.mainTexture == null || meshCollider == null) { Debug.LogWarning("There are no Renderer or Texture or MeshCollider."); return; } Texture2D texture = renderer.material.mainTexture as Texture2D; Vector2 pixelUV = hit.textureCoord; pixelUV.x *= texture.width; pixelUV.y *= texture.height; pixelUV.y = texture.height - pixelUV.y; // NOTE: WSA does not support input processing YET. // To be honest, I couldn't find a way to programmatically pass the mouse event and keyboard input to the webview on WSA. // And I think there is a way to implement this obviously. Because I'm not used to developing Windows Store App. // So, I would be very happy if someone could tell me how. webView.InputEvent(state, key, (int)pixelUV.x, (int)pixelUV.y); } #else Debug.LogWarning("Texturing feature is only supported on Win32/WSA/Windows Editor."); #endif }