// Update is called once per frame void Update() { if (!ViveControllerEnabled) { return; } RaycastHit hit = ViveControllerInput.Instance.raycastHit; if (hit.transform == null || hit.collider.gameObject != gameObject) { return; } int x = (int)(hit.textureCoord.x * (float)webView.MaxWidth); int y = webView.MaxHeight - (int)(hit.textureCoord.y * (float)webView.MaxHeight); if (x != lastX || y != lastY) { UWKPlugin.UWK_MsgMouseMove(webView.ID, x, y); lastX = x; lastY = y; } /* TODO: scroll */ }
/// <summary> /// Set the size of view, must be >= 64 and < max width and height /// </summary> public void SetSize(int nwidth, int nheight) { width = Mathf.Clamp(nwidth, 64, MaxWidth); height = Mathf.Clamp(nheight, 64, MaxHeight); UWKPlugin.UWK_MsgSetSize(ID, width, height); }
/// <summary> /// Internal View Creation /// </summary> public static uint CreateView(UWKWebView view, int maxWidth, int maxHeight, string url, IntPtr nativeTexture) { uint id = UWKPlugin.UWK_CreateView(maxWidth, maxHeight, url, nativeTexture); viewLookup[id] = view; return(id); }
/// <summary> /// Main initialization of web core /// </summary> public static void Init() { // if we're already initialized, return immediately if (sInstance != null) { return; } // we want to run in the background Application.runInBackground = true; // check for IME and enable it if necessary string lang = Application.systemLanguage.ToString(); if (lang == "Chinese" || lang == "Japanese" || lang == "Korean") { IMEEnabled = true; } // initialize the native plugin UWKPlugin.Initialize(); // add ourselves to a new game object GameObject go = new GameObject("UWKCore"); UnityEngine.Object.DontDestroyOnLoad(go); UWKCore core = go.AddComponent <UWKCore> (); // we're all ready to go sInstance = core; }
void OnDestroy() { // Core is coming down, close up shop and clean up GL.IssuePluginEvent(renderEventShutdown); UWKPlugin.UWK_Shutdown(); viewLookup = new Dictionary <uint, UWKWebView>(); }
/// <summary> /// Page is focusing a text entry area in IME mode /// </summary> public void IMEFocusIn(ref UWKMessage msg) { IMEActive = true; IMEInputRect = new Rect(msg.iParams[0], msg.iParams[1], msg.iParams[2], msg.iParams[3]); IMEInputType = UWKPlugin.GetMessageString(ref msg, 0); IMEText = UWKPlugin.GetMessageString(ref msg, 1); }
/// <summary> /// Sets the current width and height of the UWKWebView /// </summary> public void SetCurrentSize(int width, int height) { if (currentWidth == width && currentHeight == height) { return; } if (width > MaxWidth) { width = MaxWidth; } if (height > MaxHeight) { height = MaxHeight; } if (width < 32) { width = 32; } if (height < 32) { height = 32; } CurrentWidth = width; CurrentHeight = height; currentWidth = width; currentHeight = height; UWKPlugin.UWK_MsgSetCurrentSize(ID, width, height); }
/// <summary> /// Draws the text IME for Chinese, Japanese, Korean languages /// </summary> public void DrawTextIME(int x, int y) { if (!IMEActive) { return; } GUI.SetNextControlName("UWK_IMETextField"); Rect t = new Rect(x + IMEInputRect.x, y + IMEInputRect.y, IMEInputRect.width, IMEInputRect.height); // GUI.TextField && GUI.PasswordField not returning the IME character with the _ under it string currentIME = ""; if (IMEInputType != "password") { currentIME = GUI.TextField(t, IMEText); } else { currentIME = GUI.PasswordField(t, IMEText, "*" [0]); } if (currentIME != IMEText) { IMEText = currentIME; UWKPlugin.SetIMEText(ID, IMEText); } GUI.FocusControl("UWK_IMETextField"); }
public void LoadHTML(string html, string url = "http://localcontent/") { if (html == null || html.Length == 0) { return; } UWKPlugin.UWK_MsgLoadHTML(ID, html, url); }
/// <summary> /// Internal View Destruction /// </summary> public static void DestroyView(UWKWebView view) { if (viewLookup.ContainsKey(view.ID)) { viewLookup.Remove(view.ID); } UWKPlugin.UWK_DestroyView(view.ID); }
private IEnumerator CallPluginAtEndOfFrames() { while (true) { yield return(new WaitForEndOfFrame()); GL.IssuePluginEvent(UWKPlugin.UWK_GetRenderEventFunc(), 1); } }
/// <summary> /// Navigate the view to the specified URL (http://, file://, etc) /// </summary> public void LoadURL(string url) { if (url == null || url.Length == 0) { return; } UWKPlugin.UWK_MsgLoadURL(ID, url); }
/// <summary> /// Evaluates Javascript on the page /// Example with return value: EvaluateJavascript("document.title", (value) => { Debug.Log(value); }); /// </summary> public void EvaluateJavascript(string javascript, JSEvalDelegate callback = null) { if (callback != null) { UWKPlugin.EvaluateJavascript(ID, javascript, (id, value) => { callback(value); }); } else { UWKPlugin.EvaluateJavascript(ID, javascript); } }
/// <summary> /// Inject a Unity keyboard event into the WebView /// </summary> public void InjectKeyEvent(Event keyEvent) { UnityKeyEvent uevent = new UnityKeyEvent(); uevent.Type = keyEvent.type == EventType.KeyDown ? 1u : 0u; uevent.KeyCode = (uint)keyEvent.keyCode; uevent.Character = (uint)keyEvent.character; // Do not forward newline if (uevent.Character == 10) { return; } // encode modifiers uevent.Modifiers = 0; if (keyEvent.command) { uevent.Modifiers |= (uint)UnityKeyModifiers.CommandWin; } if (keyEvent.alt) { uevent.Modifiers |= (uint)UnityKeyModifiers.Alt; } if (keyEvent.control) { uevent.Modifiers |= (uint)UnityKeyModifiers.Control; } if (keyEvent.shift) { uevent.Modifiers |= (uint)UnityKeyModifiers.Shift; } if (keyEvent.numeric) { uevent.Modifiers |= (uint)UnityKeyModifiers.Numeric; } if (keyEvent.functionKey) { uevent.Modifiers |= (uint)UnityKeyModifiers.FunctionKey; } if (keyEvent.capsLock) { uevent.Modifiers |= (uint)UnityKeyModifiers.CapsLock; } UWKPlugin.UWK_InjectKeyEvent(ID, ref uevent); }
/// <summary> /// Process a Unity keyboard event /// </summary> public void ProcessKeyboard(Event keyEvent) { if (inputDisabled) { return; } UnityKeyEvent uevent = new UnityKeyEvent(); uevent.Type = keyEvent.type == EventType.KeyDown ? 1u : 0u; uevent.KeyCode = (uint)keyEvent.keyCode; uevent.Character = (uint)keyEvent.character; // encode modifiers uevent.Modifiers = 0; if (keyEvent.command) { uevent.Modifiers |= (uint)UnityKeyModifiers.CommandWin; } if (keyEvent.alt) { uevent.Modifiers |= (uint)UnityKeyModifiers.Alt; } if (keyEvent.control) { uevent.Modifiers |= (uint)UnityKeyModifiers.Control; } if (keyEvent.shift) { uevent.Modifiers |= (uint)UnityKeyModifiers.Shift; } if (keyEvent.numeric) { uevent.Modifiers |= (uint)UnityKeyModifiers.Numeric; } if (keyEvent.functionKey) { uevent.Modifiers |= (uint)UnityKeyModifiers.FunctionKey; } if (keyEvent.capsLock) { uevent.Modifiers |= (uint)UnityKeyModifiers.CapsLock; } UWKPlugin.UWK_PostUnityKeyEvent(ID, ref uevent); }
/// <summary> /// Evaluates Javascript on the page /// Example with return value: EvaluateJavascript("document.title", (success, value) => { Debug.Log(value); }); /// </summary> public void EvaluateJavascript(string javascript, JSEvalDelegate callback = null) { if (callback == null) { ExecuteJavascript(javascript); return; } evalCallbacks[evalIDCounter] = callback; UWKPlugin.UWK_MsgEvalJavaScript(ID, evalIDCounter, javascript); evalIDCounter++; }
/// <summary> /// Process the mouse given mousePos coordinates /// </summary> public void ProcessMouse(Vector3 mousePos) { if (inputDisabled) { return; } //mousePos.y = Screen.height - mousePos.y; if ((int)mousePos.x != lastMouseX || (int)mousePos.y != lastMouseY) { UWKPlugin.UWK_MsgMouseMove(ID, (int)mousePos.x, (int)mousePos.y); lastMouseX = (int)mousePos.x; lastMouseY = (int)mousePos.y; } float scroll = Input.GetAxis("Mouse ScrollWheel"); if (scroll != 0.0f) { #if UNITY_STANDALONE_WIN scroll *= 15.0f; #else scroll *= 1.2f; #endif scroll *= ScrollSensitivity; UWKPlugin.UWK_MsgMouseScroll(ID, lastMouseX, lastMouseY, scroll); } for (int i = 0; i < 3; i++) { if (Input.GetMouseButtonDown(i)) { if (!mouseStates[i]) { mouseStates[i] = true; UWKPlugin.UWK_MsgMouseButtonDown(ID, (int)mousePos.x, (int)mousePos.y, i); } } if (Input.GetMouseButtonUp(i)) { if (mouseStates[i]) { mouseStates[i] = false; UWKPlugin.UWK_MsgMouseButtonUp(ID, (int)mousePos.x, (int)mousePos.y, i); } } } }
void Update() { #if UNITY_EDITOR if (EditorApplication.isCompiling) { Debug.Log("Unity is recompiling scripts, play session ended."); EditorApplication.ExecuteMenuItem("Edit/Play"); return; } #endif #if UNITY_4_3 lastUpdate += Time.deltaTime; #else lastUpdate += Time.unscaledDeltaTime; #endif // throttle if (lastUpdate > .033f) { lastUpdate = 0; UWKPlugin.UWK_Update(); } }
public static void SetGlobalProperty(string globalVarName, string propertyName, object value) { if (value is bool) { UWKPlugin.UWK_SetGlobalBoolProperty(globalVarName, propertyName, (bool)value); } else if (value is int) { UWKPlugin.UWK_SetGlobalNumberProperty(globalVarName, propertyName, (double)((int)value)); } else if (value is float) { UWKPlugin.UWK_SetGlobalNumberProperty(globalVarName, propertyName, (double)((float)value)); } else if (value is double) { UWKPlugin.UWK_SetGlobalNumberProperty(globalVarName, propertyName, (double)value); } else if (value is string) { UWKPlugin.UWK_SetGlobalStringProperty(globalVarName, propertyName, (string)value); } }
/// <summary> /// Process a Unity keyboard event /// </summary> public void ProcessKeyboard(Event keyEvent) { if (inputDisabled) { return; } UnityKeyEvent uevent = new UnityKeyEvent(); uevent.Type = keyEvent.type == EventType.KeyDown ? 1u : 0u; uevent.KeyCode = (uint)keyEvent.keyCode; uevent.Character = (uint)keyEvent.character; // Fix mac deployment Unity key handling bug #if !UNITY_EDITOR #if UNITY_STANDALONE_OSX if (keyEvent.command && (keyEvent.keyCode == KeyCode.V || keyEvent.keyCode == KeyCode.A || keyEvent.keyCode == KeyCode.C)) { if (keyEvent.type != EventType.KeyDown) { return; } uevent.Type = 1u; uevent.KeyCode = (uint)keyEvent.keyCode; uevent.Modifiers |= (uint)UnityKeyModifiers.CommandWin; if (keyEvent.keyCode == KeyCode.V) { uevent.Character = (uint)'v'; } if (keyEvent.keyCode == KeyCode.A) { uevent.Character = (uint)'a'; } if (keyEvent.keyCode == KeyCode.C) { uevent.Character = (uint)'c'; } UWKPlugin.UWK_PostUnityKeyEvent(ID, ref uevent); uevent.Type = 0u; UWKPlugin.UWK_PostUnityKeyEvent(ID, ref uevent); return; } #endif #endif // encode modifiers uevent.Modifiers = 0; if (keyEvent.command) { uevent.Modifiers |= (uint)UnityKeyModifiers.CommandWin; } if (keyEvent.alt) { uevent.Modifiers |= (uint)UnityKeyModifiers.Alt; } if (keyEvent.control) { uevent.Modifiers |= (uint)UnityKeyModifiers.Control; } if (keyEvent.shift) { uevent.Modifiers |= (uint)UnityKeyModifiers.Shift; } if (keyEvent.numeric) { uevent.Modifiers |= (uint)UnityKeyModifiers.Numeric; } if (keyEvent.functionKey) { uevent.Modifiers |= (uint)UnityKeyModifiers.FunctionKey; } if (keyEvent.capsLock) { uevent.Modifiers |= (uint)UnityKeyModifiers.CapsLock; } UWKPlugin.UWK_PostUnityKeyEvent(ID, ref uevent); }
/// <summary> /// Sends a Javascript message to the page /// </summary> public void SendJSMessage(string msgName) { var json = "{}"; UWKPlugin.SendJSMessage(ID, msgName, json); }
/// <summary> /// Sends a Javascript message to the page /// </summary> public void SendJSMessage(string msgName, Dictionary <string, object> msgValues) { var json = UWKJson.Serialize(msgValues); UWKPlugin.SendJSMessage(ID, msgName, json); }
/// <summary> /// Closes the Web Inspector window Associated with this View /// </summary> public void CloseInspector() { UWKPlugin.UWK_MsgViewCloseInspector(ID); }
/// <summary> /// Loads the specified HTML string directly in the view, can be used for generating web content on the fly /// </summary> public void LoadHTML(string HTML, string baseURL = "") { UWKPlugin.LoadHTML(ID, HTML, baseURL); }
/// <summary> /// Sets the user agent the browser reports, setting the agent to "" /// will use the default uWebKit agent /// </summary> public void SetUserAgent(string agent = "") { UWKPlugin.UWK_MsgSetUserAgent(ID, agent); }
/// <summary> /// Navigates forward or back in the page history /// </summary> public void Navigate(Navigation n) { UWKPlugin.UWK_MsgNavigate(ID, (int)n); }
/// <summary> /// Opens a platform Web Inspector Window /// </summary> public void ShowInspector() { UWKPlugin.UWK_MsgViewShowInspector(ID); }
/// <summary> /// Reloads the current page contents /// </summary> public void Reload() { UWKPlugin.UWK_MsgViewReload(ID); }
/// <summary> /// Sets the framerate that the view is rendered at in the web rendering process /// Default is 30fps, to set 60fps you would call view.SetFrameRate(60); /// Please note that higher fps settings will increase CPU load /// </summary> public void SetFrameRate(int framerate) { UWKPlugin.UWK_MsgSetFrameRate(ID, framerate); }
/// <summary> /// Stops the current page load /// </summary> public void Stop() { UWKPlugin.UWK_MsgViewStop(ID); }