Anyone out there using uWebKit?
I’m trying to implement uWebKit (to display a webpage) in the GUI of my app on iOS.
The example WebGUI scene builds and works fine on my device. Also, in my scene, if I operate in Play Mode using the Unity Remote, the WebView works fine and operates as expected.
However, when I build my scene to my device, the WebView won’t show. I have copy and pasted the example code exactly. I have tried using OnWebGUI within an if / then statement with a flag. I have tried it outside the if / then (but still in the OnGUI function) and used UWKView.Show(bool) to enable and disable. Again, this works if I modify the example scene to this method in play mode and on the device. In my scene it works in play mode as well. But if I build to the device, it doesn’t show.
I am incorporating other textures on the GUI using DrawTexture (they animate in and out of the screen, and work fine), but I don’t see why that would affect it. (Doesn’t affect it in Play Mode. And it’s not somehow hiding behind a texture, since even if I disable them it still won’t show.) I am also using the Vuforia AR plugin, but in a separate scene using AR it still works fine on the device. Also works fine with AR in Play Mode.
I am sure I am doing something incorrectly, but I can’t narrow it down since it only fails on the device. No errors in Unity or Xcode. Any ideas? My code is in JS, since I’m not too comfortable with C#…and I’m not much of a coder, so apologies if it’s sloppy.
Thanks in advance.
#pragma strict
var header : Texture;
var backgroundTexture : Texture;
var GUIEnabled : boolean = false;
var webEnabled : boolean = false;
var imageTargetToControl : GameObject;
private var View : UWKView;
private var X = 0;
private var Y = 0;
private var Transparency = 100.0f;
private var URL = "http://www.google.com";
private var screenHeight : int;
private var screenWidth : int;
private var webWidth : int;
private var webHeight : int;
private var headerStartHeight : int;
private var headerEndHeight : int;
private var backgroundLocation : Rect;
private var backgroundOffScreen : Rect;
private var backgroundOnScreen : Rect;
private var headerLocation : Rect;
private var headerOffScreen : Rect;
private var headerOnScreen : Rect;
private var GUImoverate = 0.5f;
var completion = 0.00f;
var animateOut = false;
var animateIn = false;
function Start () {
screenHeight = Screen.height;
screenWidth = Screen.width;
webWidth = Screen.width;
webHeight = Screen.height-100;
backgroundOffScreen = Rect(0,screenHeight,screenWidth,screenHeight);
backgroundOnScreen = Rect(0,0,screenWidth,screenHeight);
backgroundLocation = backgroundOffScreen;
headerStartHeight = screenHeight*2-100;
headerOffScreen = Rect(0,headerStartHeight,screenWidth,100);
headerOnScreen = Rect(0,webHeight,screenWidth,100);
headerLocation = headerOffScreen;
//Create WebView
View = UWKCore.CreateView("BasicWebGUI", URL, webWidth, webHeight);
Debug.Log(View);
}
function Update () {
//Determine touch
for(var curTouch in Input.touches){
if(curTouch.phase == TouchPhase.Began){
//there's been a tap this frame - see if the user tapped us
var ray = Camera.main.ScreenPointToRay(curTouch.position);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, Mathf.Infinity)) //the touch was over our collider - perform the drag
if(hit.transform == transform)
Tapped(curTouch);
}
}
}
function OnGUI () {
if (GUIEnabled) {
//Draw BG texture
GUI.DrawTexture(backgroundLocation, backgroundTexture, ScaleMode.StretchToFill);
//Draw bottom bar
GUI.DrawTexture(headerLocation, header, ScaleMode.StretchToFill);
//Close button, and set flags accordingly
if (GUI.Button (Rect (10,screenHeight-85,150,75), "Close")) {
if (imageTargetToControl!=null) {imageTargetToControl.SetActiveRecursively(true);}
animateOut = true;
animateIn = false;
}
}
//Draw webview
View.OnWebGUI(X, Y, webWidth, webHeight);
View.Show(GUIEnabled);
//Move GUI in or out of screen
if (animateIn) {
if (completion < 1) {
completion += Time.deltaTime * GUImoverate;
} else { animateIn = false; }
backgroundLocation = Rect(backgroundLocation.x, Mathf.SmoothStep(backgroundOffScreen.y, backgroundOnScreen.y, completion), backgroundLocation.width, backgroundLocation.height);
headerLocation = Rect(headerLocation.x, Mathf.SmoothStep(headerOffScreen.y, headerOnScreen.y, completion), headerLocation.width, headerLocation.height);
}
if (animateOut) {
if (completion > 0) {
completion -= Time.deltaTime * GUImoverate;
} else {
animateOut = false;
GUIEnabled = false;
}
backgroundLocation = Rect(backgroundLocation.x, Mathf.SmoothStep(backgroundOffScreen.y, backgroundOnScreen.y, completion), backgroundLocation.width, backgroundLocation.height);
headerLocation = Rect(headerLocation.x, Mathf.SmoothStep(headerOffScreen.y, headerOnScreen.y, completion), headerLocation.width, headerLocation.height);
}
}
function Tapped(theTouch : Touch) {
//Set flags and deactivate image target
GUIEnabled = true;
animateIn = true;
if (imageTargetToControl!=null) {imageTargetToControl.SetActiveRecursively(false);}
}