Skip to content

Commit

Permalink
added _WebViewPlugin_SetCurrentInstance() to set the instance pointer…
Browse files Browse the repository at this point in the history
…, because GL.IssuePluginEvent() cannot pass a 64-bit integer (note: the logic works only for one instance).
  • Loading branch information
KojiNakamaru committed Aug 31, 2015
1 parent 04eb603 commit 37a65aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 10 additions & 2 deletions plugins/Mac/Sources/WebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ - (void)render
void _WebViewPlugin_Update(void *instance, int x, int y, float deltaY,
BOOL buttonDown, BOOL buttonPress, BOOL buttonRelease,
BOOL keyPress, unsigned char keyCode, const char *keyChars, int textureId);
void _WebViewPlugin_SetCurrentInstance(void *instance);
void UnityRenderEvent(int eventID);
}

Expand Down Expand Up @@ -330,11 +331,18 @@ void _WebViewPlugin_Update(void *instance, int x, int y, float deltaY,
keyCode:keyCode keyChars:keyChars textureId:textureId];
}

static void *_instance;

void _WebViewPlugin_SetCurrentInstance(void *instance)
{
_instance = instance;
}

void UnityRenderEvent(int eventID)
{
@autoreleasepool {
if ([pool containsObject:[NSValue valueWithPointer:(void *)eventID]]) {
WebViewPlugin *webViewPlugin = (WebViewPlugin *)eventID;
if ([pool containsObject:[NSValue valueWithPointer:(void *)_instance]]) {
WebViewPlugin *webViewPlugin = (WebViewPlugin *)_instance;
[webViewPlugin render];
}
}
Expand Down
11 changes: 9 additions & 2 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ private static extern void _WebViewPlugin_EvaluateJS(
private static extern void _WebViewPlugin_Update(IntPtr instance,
int x, int y, float deltaY, bool down, bool press, bool release,
bool keyPress, short keyCode, string keyChars, int textureId);
[DllImport("WebView")]
private static extern void _WebViewPlugin_SetCurrentInstance(IntPtr instance);
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern IntPtr _WebViewPlugin_Init(string gameObject);
Expand Down Expand Up @@ -154,16 +156,20 @@ void OnDestroy()
if (webView == IntPtr.Zero)
return;
_WebViewPlugin_Destroy(webView);
webView = IntPtr.Zero;
#elif UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_WebViewPlugin_Destroy(webView);
webView = IntPtr.Zero;
#elif UNITY_ANDROID
if (webView == null)
return;
webView.Call("Destroy");
webView = null;
#elif UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.destroy", name);
webView = null;
#endif
}

Expand Down Expand Up @@ -287,8 +293,9 @@ void OnGUI()
_WebViewPlugin_Update(webView,
(int)(pos.x - rect.x), (int)(pos.y - rect.y), deltaY,
down, press, release, keyPress, keyCode, keyChars,
texture.GetNativeTextureID());
GL.IssuePluginEvent((int)webView);
(int)texture.GetNativeTexturePtr());
_WebViewPlugin_SetCurrentInstance(webView);
GL.IssuePluginEvent(-1);
Matrix4x4 m = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(new Vector3(0, Screen.height, 0),
Quaternion.identity, new Vector3(1, -1, 1));
Expand Down

0 comments on commit 37a65aa

Please sign in to comment.