public void RenderOnGUI() { GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height)); GUILayout.Label("Variables:"); GUILayout.Label("m_Init: " + m_Init); GUILayout.Label("m_HHTMLBrowser: " + m_HHTMLBrowser); GUILayout.EndArea(); if (m_Texture) { GUI.DrawTexture(m_Rect, m_Texture); } if (!m_Init) { GUILayout.Label("SteamHTMLSurface.Init() returned false"); return; } if (GUILayout.Button("CreateBrowser(\"SpaceWars Test\", null)")) { RemoveBrowser(); // Remove an old browser if it exists. SteamAPICall_t handle = SteamHTMLSurface.CreateBrowser("SpaceWars Test", null); m_HTML_BrowserReadyResult.Set(handle); print("SteamHTMLSurface.CreateBrowser(\"SpaceWars Test\", null) - " + handle); } if (GUILayout.Button("RemoveBrowser(m_HHTMLBrowser)")) { RemoveBrowser(); } m_URL = GUILayout.TextField(m_URL); if (GUILayout.Button("LoadURL(m_HHTMLBrowser, m_URL, null)")) { SteamHTMLSurface.LoadURL(m_HHTMLBrowser, m_URL, null); print("SteamHTMLSurface.LoadURL(m_HHTMLBrowser," + m_URL + ", null)"); } if (GUILayout.Button("SetSize(m_HHTMLBrowser, m_Width, m_Height)")) { m_Width = (uint)Screen.width - WidthOffset; m_Height = (uint)Screen.height - HeightOffset; m_Rect = new Rect(WidthOffset, m_Height + HeightOffset, m_Width, -m_Height); // This flips the viewport since Unity renders textures upside down. m_Texture = null; SteamHTMLSurface.SetSize(m_HHTMLBrowser, m_Width, m_Height); print("SteamHTMLSurface.SetSize(m_HHTMLBrowser, " + m_Width + ", " + m_Height + ")"); } if (GUILayout.Button("StopLoad(m_HHTMLBrowser)")) { SteamHTMLSurface.StopLoad(m_HHTMLBrowser); print("SteamHTMLSurface.StopLoad(m_HHTMLBrowser)"); } if (GUILayout.Button("Reload(m_HHTMLBrowser)")) { SteamHTMLSurface.Reload(m_HHTMLBrowser); print("SteamHTMLSurface.Reload(m_HHTMLBrowser)"); } GUI.enabled = m_CanGoBack; if (GUILayout.Button("GoBack(m_HHTMLBrowser)")) { SteamHTMLSurface.GoBack(m_HHTMLBrowser); print("SteamHTMLSurface.GoBack(m_HHTMLBrowser)"); } GUI.enabled = m_CanGoForward; if (GUILayout.Button("GoForward(m_HHTMLBrowser)")) { SteamHTMLSurface.GoForward(m_HHTMLBrowser); print("SteamHTMLSurface.GoForward(m_HHTMLBrowser)"); } GUI.enabled = true; if (GUILayout.Button("AddHeader(m_HHTMLBrowser, \"From\", \"[email protected]\")")) { SteamHTMLSurface.AddHeader(m_HHTMLBrowser, "From", "*****@*****.**"); print("SteamHTMLSurface.AddHeader(m_HHTMLBrowser, \"From\", \"[email protected]\")"); } if (GUILayout.Button("ExecuteJavascript(m_HHTMLBrowser, \"window.alert('Test');\")")) { SteamHTMLSurface.ExecuteJavascript(m_HHTMLBrowser, "window.alert('Test');"); print("SteamHTMLSurface.ExecuteJavascript(m_HHTMLBrowser, \"window.alert('Test');\")"); } if (GUILayout.Button("SetKeyFocus(m_HHTMLBrowser, " + !m_SetKeyFocus + ")")) { SteamHTMLSurface.SetKeyFocus(m_HHTMLBrowser, !m_SetKeyFocus); m_SetKeyFocus = !m_SetKeyFocus; print("SteamHTMLSurface.SetKeyFocus(m_HHTMLBrowser, " + !m_SetKeyFocus + ")"); } if (GUILayout.Button("ViewSource(m_HHTMLBrowser)")) { SteamHTMLSurface.ViewSource(m_HHTMLBrowser); print("SteamHTMLSurface.ViewSource(m_HHTMLBrowser)"); } if (GUILayout.Button("CopyToClipboard(m_HHTMLBrowser)")) { SteamHTMLSurface.CopyToClipboard(m_HHTMLBrowser); print("SteamHTMLSurface.CopyToClipboard(m_HHTMLBrowser)"); } if (GUILayout.Button("PasteFromClipboard(m_HHTMLBrowser)")) { SteamHTMLSurface.PasteFromClipboard(m_HHTMLBrowser); print("SteamHTMLSurface.PasteFromClipboard(m_HHTMLBrowser)"); } m_Find = GUILayout.TextField(m_Find); if (GUILayout.Button("Find(m_HHTMLBrowser, m_Find, m_CurrentlyInFind, false)")) { SteamHTMLSurface.Find(m_HHTMLBrowser, m_Find, m_CurrentlyInFind, bReverse: false); print("SteamHTMLSurface.Find(m_HHTMLBrowser," + m_Find + ", " + m_CurrentlyInFind + ", false)"); m_CurrentlyInFind = true; } if (GUILayout.Button("StopFind(m_HHTMLBrowser)")) { SteamHTMLSurface.StopFind(m_HHTMLBrowser); print("SteamHTMLSurface.StopFind(m_HHTMLBrowser)"); m_CurrentlyInFind = false; } if (GUILayout.Button("GetLinkAtPosition(m_HHTMLBrowser, 500, 120)")) { SteamHTMLSurface.GetLinkAtPosition(m_HHTMLBrowser, 500 - WidthOffset, 120 - HeightOffset); print("SteamHTMLSurface.GetLinkAtPosition(m_HHTMLBrowser, 500, 120)"); } // Use with http://html-kit.com/tools/cookietester/ if (GUILayout.Button("SetCookie(\"html-kit.com\", \"testcookiekey\", \"testcookievalue\")")) { SteamHTMLSurface.SetCookie("html-kit.com", "testcookiekey", "testcookievalue"); print("SteamHTMLSurface.SetCookie(\"html-kit.com\", \"testcookiekey\", \"testcookievalue\")"); } m_ScaleFactor = GUILayout.HorizontalScrollbar(m_ScaleFactor, 0.25f, 0f, 2f); if (GUILayout.Button("SetPageScaleFactor(m_HHTMLBrowser, " + m_ScaleFactor + ", 0, 0)")) { SteamHTMLSurface.SetPageScaleFactor(m_HHTMLBrowser, m_ScaleFactor, 0, 0); print("SteamHTMLSurface.SetPageScaleFactor(m_HHTMLBrowser, " + m_ScaleFactor + ", 0, 0)"); } if (m_HHTMLBrowser == HHTMLBrowser.Invalid) { return; } // We set the moust position before checking for mouse presses just incase the mouse moved in the same OnGUI frame as a mouse press. Event e = Event.current; if (e.mousePosition != m_LastMousePos) { if ((e.mousePosition.x >= WidthOffset && e.mousePosition.x <= m_Width + WidthOffset) && (e.mousePosition.y >= HeightOffset && e.mousePosition.y <= m_Height + HeightOffset)) { m_LastMousePos = e.mousePosition; SteamHTMLSurface.MouseMove(m_HHTMLBrowser, (int)(e.mousePosition.x - WidthOffset), (int)(e.mousePosition.y - HeightOffset)); } } //virtual void MouseDoubleClick( HHTMLBrowser unBrowserHandle, EHTMLMouseButton eMouseButton ) = 0; //TODO switch (e.type) { case EventType.MouseDown: SteamHTMLSurface.MouseDown(m_HHTMLBrowser, (EHTMLMouseButton)e.button); break; case EventType.MouseUp: SteamHTMLSurface.MouseUp(m_HHTMLBrowser, (EHTMLMouseButton)e.button); break; case EventType.ScrollWheel: SteamHTMLSurface.MouseWheel(m_HHTMLBrowser, (int)(-e.delta.y * 100)); break; case EventType.KeyDown: //print("KeyDown: " + e.keyCode + " - " + (int)e.character + " - " + e.character); EHTMLKeyModifiers modifiers = EHTMLKeyModifiers.k_eHTMLKeyModifier_None; if (e.alt) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_AltDown; } if (e.shift) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_ShiftDown; } if (e.control) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_CtrlDown; } if (e.keyCode != KeyCode.None) { SteamHTMLSurface.KeyDown(m_HHTMLBrowser, (uint)e.keyCode, modifiers); } if (e.character != 0) { SteamHTMLSurface.KeyChar(m_HHTMLBrowser, (uint)e.character, modifiers); } if (e.keyCode == KeyCode.DownArrow) { m_VeritcalScrollCurrent = System.Math.Min(m_VeritcalScrollCurrent + 100, m_VerticalScrollMax); SteamHTMLSurface.SetVerticalScroll(m_HHTMLBrowser, m_VeritcalScrollCurrent); } else if (e.keyCode == KeyCode.UpArrow) { if (m_VeritcalScrollCurrent - 100 > m_VeritcalScrollCurrent) // Underflow { m_VeritcalScrollCurrent = 0; } else { m_VeritcalScrollCurrent -= 100; } SteamHTMLSurface.SetVerticalScroll(m_HHTMLBrowser, m_VeritcalScrollCurrent); } else if (e.keyCode == KeyCode.RightArrow) { m_HorizontalScrollCurrent = System.Math.Min(m_HorizontalScrollCurrent + 100, m_HorizontalScrollMax); SteamHTMLSurface.SetHorizontalScroll(m_HHTMLBrowser, m_HorizontalScrollCurrent); } else if (e.keyCode == KeyCode.LeftArrow) { if (m_HorizontalScrollCurrent - 100 > m_HorizontalScrollCurrent) // Underflow { m_HorizontalScrollCurrent = 0; } else { m_HorizontalScrollCurrent -= 100; } SteamHTMLSurface.SetHorizontalScroll(m_HHTMLBrowser, m_HorizontalScrollCurrent); } break; case EventType.KeyUp: //print("KeyUp: " + e.keyCode + " - " + (int)e.character + " - " + e.character); modifiers = EHTMLKeyModifiers.k_eHTMLKeyModifier_None; if (e.alt) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_AltDown; } if (e.shift) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_ShiftDown; } if (e.control) { modifiers = modifiers | EHTMLKeyModifiers.k_eHTMLKeyModifier_CtrlDown; } if (e.keyCode != KeyCode.None) { SteamHTMLSurface.KeyUp(m_HHTMLBrowser, (uint)e.keyCode, modifiers); } break; } }