Watch Star Fork

qipaworld / QPUnityFramework

加入码云
与超过 300 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
暂无描述
一键复制 编辑 原始数据 按行查看 历史
WebViewObject.cs 23.83 KB qipaworld 提交于 2018-02-27 21:49 . 修复float 转int 不精确bug
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
/*
* Copyright (C) 2011 Keijiro Takahashi
* Copyright (C) 2012 GREE, Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
using System.IO;
using System.Text.RegularExpressions;
#endif
using Callback = System.Action<string>;
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
public class UnitySendMessageDispatcher
{
public static void Dispatch(string name, string method, string message)
{
GameObject obj = GameObject.Find(name);
if (obj != null)
obj.SendMessage(method, message);
}
}
#endif
public class WebViewObject : MonoBehaviour
{
Callback onJS;
Callback onError;
Callback onLoaded;
bool visibility;
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
IntPtr webView;
Rect rect;
Texture2D texture;
string inputString;
bool hasFocus;
#elif UNITY_IPHONE
IntPtr webView;
#elif UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaObject webView;
bool mIsKeyboardVisible = false;
/// Called from Java native plugin to set when the keyboard is opened
public void SetKeyboardVisible(string pIsVisible)
{
mIsKeyboardVisible = (pIsVisible == "true");
}
#else
IntPtr webView;
#endif
public bool IsKeyboardVisible
{
get
{
#if !UNITY_EDITOR && UNITY_ANDROID
return mIsKeyboardVisible;
#elif !UNITY_EDITOR && UNITY_IPHONE
return TouchScreenKeyboard.visible;
#else
return false;
#endif
}
}
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if WEBVIEW_SEPARATED
[DllImport("WebViewSeparated")]
private static extern string _CWebViewPlugin_GetAppPath();
[DllImport("WebViewSeparated")]
private static extern IntPtr _CWebViewPlugin_Init(
string gameObject, bool transparent, int width, int height, string ua, bool ineditor);
[DllImport("WebViewSeparated")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_SetRect(
IntPtr instance, int width, int height);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_SetVisibility(
IntPtr instance, bool visibility);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_LoadURL(
IntPtr instance, string url);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_LoadHTML(
IntPtr instance, string html, string baseUrl);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_EvaluateJS(
IntPtr instance, string url);
[DllImport("WebViewSeparated")]
private static extern int _CWebViewPlugin_Progress(
IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern bool _CWebViewPlugin_CanGoBack(
IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern bool _CWebViewPlugin_CanGoForward(
IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_GoBack(
IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_GoForward(
IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_Update(IntPtr instance,
int x, int y, float deltaY, bool down, bool press, bool release,
bool keyPress, short keyCode, string keyChars,
bool refreshBitmap);
[DllImport("WebViewSeparated")]
private static extern int _CWebViewPlugin_BitmapWidth(IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern int _CWebViewPlugin_BitmapHeight(IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_SetTextureId(IntPtr instance, int textureId);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_SetCurrentInstance(IntPtr instance);
[DllImport("WebViewSeparated")]
private static extern IntPtr GetRenderEventFunc();
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_AddCustomHeader(IntPtr instance, string headerKey, string headerValue);
[DllImport("WebViewSeparated")]
private static extern string _CWebViewPlugin_GetCustomHeaderValue(IntPtr instance, string headerKey);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_RemoveCustomHeader(IntPtr instance, string headerKey);
[DllImport("WebViewSeparated")]
private static extern void _CWebViewPlugin_ClearCustomHeader(IntPtr instance);
#else
[DllImport("WebView")]
private static extern string _CWebViewPlugin_GetAppPath();
[DllImport("WebView")]
private static extern IntPtr _CWebViewPlugin_Init(
string gameObject, bool transparent, int width, int height, string ua, bool ineditor);
[DllImport("WebView")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_SetRect(
IntPtr instance, int width, int height);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_SetVisibility(
IntPtr instance, bool visibility);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_LoadURL(
IntPtr instance, string url);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_LoadHTML(
IntPtr instance, string html, string baseUrl);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_EvaluateJS(
IntPtr instance, string url);
[DllImport("WebView")]
private static extern int _CWebViewPlugin_Progress(
IntPtr instance);
[DllImport("WebView")]
private static extern bool _CWebViewPlugin_CanGoBack(
IntPtr instance);
[DllImport("WebView")]
private static extern bool _CWebViewPlugin_CanGoForward(
IntPtr instance);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_GoBack(
IntPtr instance);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_GoForward(
IntPtr instance);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_Update(IntPtr instance,
int x, int y, float deltaY, bool down, bool press, bool release,
bool keyPress, short keyCode, string keyChars,
bool refreshBitmap);
[DllImport("WebView")]
private static extern int _CWebViewPlugin_BitmapWidth(IntPtr instance);
[DllImport("WebView")]
private static extern int _CWebViewPlugin_BitmapHeight(IntPtr instance);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_SetTextureId(IntPtr instance, int textureId);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_SetCurrentInstance(IntPtr instance);
[DllImport("WebView")]
private static extern IntPtr GetRenderEventFunc();
[DllImport("WebView")]
private static extern void _CWebViewPlugin_AddCustomHeader(IntPtr instance, string headerKey, string headerValue);
[DllImport("WebView")]
private static extern string _CWebViewPlugin_GetCustomHeaderValue(IntPtr instance, string headerKey);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_RemoveCustomHeader(IntPtr instance, string headerKey);
[DllImport("WebView")]
private static extern void _CWebViewPlugin_ClearCustomHeader(IntPtr instance);
#endif
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern IntPtr _CWebViewPlugin_Init(string gameObject, bool transparent, string ua, bool enableWKWebView);
[DllImport("__Internal")]
private static extern int _CWebViewPlugin_Destroy(IntPtr instance);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_SetMargins(
IntPtr instance, int left, int top, int right, int bottom);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_SetVisibility(
IntPtr instance, bool visibility);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_LoadURL(
IntPtr instance, string url);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_LoadHTML(
IntPtr instance, string html, string baseUrl);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_EvaluateJS(
IntPtr instance, string url);
[DllImport("__Internal")]
private static extern int _CWebViewPlugin_Progress(
IntPtr instance);
[DllImport("__Internal")]
private static extern bool _CWebViewPlugin_CanGoBack(
IntPtr instance);
[DllImport("__Internal")]
private static extern bool _CWebViewPlugin_CanGoForward(
IntPtr instance);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_GoBack(
IntPtr instance);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_GoForward(
IntPtr instance);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_SetFrame(
IntPtr instance, int x , int y , int width , int height);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_AddCustomHeader(IntPtr instance, string headerKey, string headerValue);
[DllImport("__Internal")]
private static extern string _CWebViewPlugin_GetCustomHeaderValue(IntPtr instance, string headerKey);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_RemoveCustomHeader(IntPtr instance, string headerKey);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_ClearCustomHeader(IntPtr instance);
[DllImport("__Internal")]
private static extern void _CWebViewPlugin_ClearCookies();
#endif
public void Init(Callback cb = null, bool transparent = false, string ua = "", Callback err = null, Callback ld = null, bool enableWKWebView = false)
{
onJS = cb;
onError = err;
onLoaded = ld;
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.init", name);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
{
var uri = new Uri(_CWebViewPlugin_GetAppPath());
var info = File.ReadAllText(uri.LocalPath + "Contents/Info.plist");
if (Regex.IsMatch(info, @"<key>CFBundleGetInfoString</key>\s*<string>Unity version [5-9]\.[3-9]")
&& !Regex.IsMatch(info, @"<key>NSAppTransportSecurity</key>\s*<dict>\s*<key>NSAllowsArbitraryLoads</key>\s*<true/>\s*</dict>")) {
Debug.LogWarning("<color=yellow>WebViewObject: NSAppTransportSecurity isn't configured to allow HTTP. If you need to allow any HTTP access, please shutdown Unity and invoke:</color>\n/usr/libexec/PlistBuddy -c \"Add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true\" /Applications/Unity/Unity.app/Contents/Info.plist");
}
}
#if UNITY_EDITOR_OSX
// if (string.IsNullOrEmpty(ua)) {
// ua = @"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53";
// }
#endif
webView = _CWebViewPlugin_Init(
name,
transparent,
Screen.width,
Screen.height,
ua,
Application.platform == RuntimePlatform.OSXEditor);
// define pseudo requestAnimationFrame.
EvaluateJS(@"(function() {
var vsync = 1000 / 60;
var t0 = window.performance.now();
window.requestAnimationFrame = function(callback, element) {
var t1 = window.performance.now();
var duration = t1 - t0;
var d = vsync - ((duration > vsync) ? duration % vsync : duration);
var id = window.setTimeout(function() {t0 = window.performance.now(); callback(t1 + d);}, d);
return id;
};
})()");
rect = new Rect(0, 0, Screen.width, Screen.height);
OnApplicationFocus(true);
#elif UNITY_IPHONE
webView = _CWebViewPlugin_Init(name, transparent, ua, enableWKWebView);
#elif UNITY_ANDROID && !UNITY_EDITOR
webView = new AndroidJavaObject("net.gree.unitywebview.CWebViewPlugin");
webView.Call("Init", name, transparent, ua);
#else
Debug.Log("Webview is not supported on this platform.");
#endif
}
protected virtual void OnDestroy()
{
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.destroy", name);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_Destroy(webView);
webView = IntPtr.Zero;
#elif UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_Destroy(webView);
webView = IntPtr.Zero;
#elif UNITY_ANDROID && !UNITY_EDITOR
if (webView == null)
return;
webView.Call("Destroy");
webView = null;
#endif
}
/** Use this function instead of SetMargins to easily set up a centered window */
public void SetCenterPositionWithScale(Vector2 center, Vector2 scale)
{
#if UNITY_WEBPLAYER
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
rect.x = center.x + (Screen.width - scale.x)/2;
rect.y = center.y + (Screen.height - scale.y)/2;
rect.width = scale.x;
rect.height = scale.y;
#elif UNITY_IPHONE
if (webView == IntPtr.Zero) return;
_CWebViewPlugin_SetFrame(webView,(int)center.x,(int)center.y,(int)scale.x,(int)scale.y);
#endif
}
public void SetMargins(int left, int top, int right, int bottom)
{
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.setMargins", name, left, top, right, bottom);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
if (webView == IntPtr.Zero)
return;
int width = Screen.width - (left + right);
int height = Screen.height - (bottom + top);
_CWebViewPlugin_SetRect(webView, width, height);
rect = new Rect(left, bottom, width, height);
#elif UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_SetMargins(webView, left, top, right, bottom);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("SetMargins", left, top, right, bottom);
#endif
}
public void SetVisibility(bool v)
{
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.setVisibility", name, v);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_SetVisibility(webView, v);
#elif UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_SetVisibility(webView, v);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("SetVisibility", v);
#endif
visibility = v;
}
public bool GetVisibility()
{
return visibility;
}
public void LoadURL(string url)
{
if (string.IsNullOrEmpty(url))
return;
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.loadURL", name, url);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_LoadURL(webView, url);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("LoadURL", url);
#endif
}
public void LoadHTML(string html, string baseUrl)
{
if (string.IsNullOrEmpty(html))
return;
if (string.IsNullOrEmpty(baseUrl))
baseUrl = "";
#if UNITY_WEBPLAYER
//TODO: UNSUPPORTED
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_LoadHTML(webView, html, baseUrl);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("LoadHTML", html, baseUrl);
#endif
}
public void EvaluateJS(string js)
{
#if UNITY_WEBPLAYER
Application.ExternalCall("unityWebView.evaluateJS", name, js);
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_EvaluateJS(webView, js);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("LoadURL", "javascript:" + js);
#endif
}
public int Progress()
{
#if UNITY_WEBPLAYER
return 0;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return 0;
return _CWebViewPlugin_Progress(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return 0;
return webView.Get<int>("progress");
#endif
return 0;
}
public bool CanGoBack()
{
#if UNITY_WEBPLAYER
return false;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return false;
return _CWebViewPlugin_CanGoBack(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return false;
return webView.Get<bool>("canGoBack");
#endif
return false;
}
public bool CanGoForward()
{
#if UNITY_WEBPLAYER
return false;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return false;
return _CWebViewPlugin_CanGoForward(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return false;
return webView.Get<bool>("canGoForward");
#endif
return false;
}
public void GoBack()
{
#if UNITY_WEBPLAYER
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_GoBack(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("GoBack");
#endif
}
public void GoForward()
{
#if UNITY_WEBPLAYER
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_GoForward(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("GoForward");
#endif
}
public void CallOnError(string error)
{
if (onError != null)
{
onError(error);
}
}
public void CallOnLoaded(string url)
{
if (onLoaded != null)
{
onLoaded(url);
}
}
public void CallFromJS(string message)
{
if (onJS != null)
{
#if !UNITY_ANDROID
message = WWW.UnEscapeURL(message);
#endif
onJS(message);
}
}
public void AddCustomHeader(string headerKey, string headerValue)
{
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_AddCustomHeader(webView, headerKey, headerValue);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("AddCustomHeader", headerKey, headerValue);
#endif
}
public string GetCustomHeaderValue(string headerKey)
{
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return null;
return _CWebViewPlugin_GetCustomHeaderValue(webView, headerKey);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return null;
return webView.Call<string>("GetCustomHeaderValue", headerKey);
#else
return null;
#endif
}
public void RemoveCustomHeader(string headerKey)
{
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_RemoveCustomHeader(webView, headerKey);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("RemoveCustomHeader", headerKey);
#endif
}
public void ClearCustomHeader()
{
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IPHONE
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_ClearCustomHeader(webView);
#elif UNITY_ANDROID&& !UNITY_EDITOR
if (webView == null)
return;
webView.Call("ClearCustomHeader");
#endif
}
public void ClearCookies()
{
#if UNITY_IPHONE && !UNITY_EDITOR
if (webView == IntPtr.Zero)
return;
_CWebViewPlugin_ClearCookies();
#elif UNITY_ANDROID && !UNITY_EDITOR
if (webView == null)
return;
webView.Call("ClearCookies");
#endif
}
#if UNITY_WEBPLAYER
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
void OnApplicationFocus(bool focus)
{
hasFocus = focus;
}
void Update()
{
if (hasFocus) {
inputString += Input.inputString;
}
}
public int bitmapRefreshCycle = 1;
void OnGUI()
{
if (webView == IntPtr.Zero || !visibility)
return;
Vector3 pos = Input.mousePosition;
bool down = Input.GetButton("Fire1");
bool press = Input.GetButtonDown("Fire1");
bool release = Input.GetButtonUp("Fire1");
float deltaY = Input.GetAxis("Mouse ScrollWheel");
bool keyPress = false;
string keyChars = "";
short keyCode = 0;
if (inputString != null && inputString.Length > 0) {
keyPress = true;
keyChars = inputString.Substring(0, 1);
keyCode = (short)inputString[0];
inputString = inputString.Substring(1);
}
bool refreshBitmap = (Time.frameCount % bitmapRefreshCycle == 0);
_CWebViewPlugin_Update(webView,
Mathf.FloorToInt(pos.x - rect.x), Mathf.FloorToInt(pos.y - rect.y), deltaY,
down, press, release, keyPress, keyCode, keyChars,
refreshBitmap);
if (refreshBitmap) {
{
var w = _CWebViewPlugin_BitmapWidth(webView);
var h = _CWebViewPlugin_BitmapHeight(webView);
if (texture == null || texture.width != w || texture.height != h) {
texture = new Texture2D(w, h, TextureFormat.RGBA32, false, true);
texture.filterMode = FilterMode.Bilinear;
texture.wrapMode = TextureWrapMode.Clamp;
}
}
_CWebViewPlugin_SetTextureId(webView, (int)texture.GetNativeTexturePtr());
_CWebViewPlugin_SetCurrentInstance(webView);
#if UNITY_4_6 || UNITY_5_0 || UNITY_5_1
GL.IssuePluginEvent(-1);
#else
GL.IssuePluginEvent(GetRenderEventFunc(), -1);
#endif
}
if (texture != null) {
Matrix4x4 m = GUI.matrix;
GUI.matrix
= Matrix4x4.TRS(
new Vector3(0, Screen.height, 0),
Quaternion.identity,
new Vector3(1, -1, 1));
GUI.DrawTexture(rect, texture);
GUI.matrix = m;
}
}
#endif
}

评论 ( 0 )

你可以在登录后,发表评论

11_float_left_people 11_float_left_close