Created
July 2, 2014 22:38
-
-
Save JoshEngebretson/ecfb57977252ee97f981 to your computer and use it in GitHub Desktop.
WebGUI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UWK; | |
public class WebGUI : MonoBehaviour | |
{ | |
// The position of the gui on the screen | |
public Vector2 Position; | |
// Whether the GUI accepts mouse/keyboard input | |
public bool HasFocus = true; | |
void OnGUI() | |
{ | |
// get the attached view component | |
UWKWebView view = gameObject.GetComponent<UWKWebView>(); | |
// if we have a view attached and it is visible | |
if (view != null && view.Visible()) | |
{ | |
// draw it | |
Rect r = new Rect (Position.x, Position.y, view.CurrentWidth, view.CurrentHeight); | |
GUI.DrawTexture (r, view.WebTexture); | |
// if we have focus, handle input | |
if (HasFocus) | |
{ | |
// get the mouse coordinate | |
Vector3 mousePos = Input.mousePosition; | |
mousePos.y = Screen.height - mousePos.y; | |
// translate based on position | |
mousePos.x -= Position.x; | |
mousePos.y -= Position.y; | |
view.ProcessMouse(mousePos); | |
// process keyboard | |
if (Event.current.isKey) | |
view.ProcessKeyboard(Event.current); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment