Repository: keijiro/unity-webview-integration Branch: master Commit: 16c7cdb26634 Files: 68 Total size: 29.2 KB Directory structure: gitextract_rbtyjkwj/ ├── .gitignore ├── LICENSE.txt ├── README.md ├── android/ │ ├── AndroidManifest.xml │ ├── ant.properties │ ├── build.xml │ ├── libs/ │ │ └── UnityClasses.jar │ ├── project.properties │ ├── res/ │ │ ├── layout/ │ │ │ └── main.xml │ │ └── values/ │ │ └── strings.xml │ └── src/ │ └── jp/ │ └── radiumsoftware/ │ └── unitywebviewexample/ │ └── ExtendedUnityPlayerActivity.java └── unity/ ├── Assets/ │ ├── GUI/ │ │ ├── Default GUI SKin.guiskin │ │ ├── Default GUI SKin.guiskin.meta │ │ ├── SU3DJPFont/ │ │ │ ├── Fonts/ │ │ │ │ └── s1-mplus-1c-light.ttf.meta │ │ │ ├── Fonts.meta │ │ │ ├── license.txt │ │ │ ├── license.txt.meta │ │ │ ├── readme.txt │ │ │ └── readme.txt.meta │ │ └── SU3DJPFont.meta │ ├── GUI.meta │ ├── Main.unity │ ├── Main.unity.meta │ ├── Materials/ │ │ ├── Blue Box.mat │ │ ├── Blue Box.mat.meta │ │ ├── Floor.mat │ │ ├── Floor.mat.meta │ │ ├── Red Box.mat │ │ └── Red Box.mat.meta │ ├── Materials.meta │ ├── Physics/ │ │ ├── Default Physic Material.physicMaterial │ │ └── Default Physic Material.physicMaterial.meta │ ├── Physics.meta │ ├── Plugins/ │ │ ├── Android/ │ │ │ ├── AndroidManifest.xml │ │ │ ├── AndroidManifest.xml.meta │ │ │ ├── WebViewIntegration.jar │ │ │ └── WebViewIntegration.jar.meta │ │ ├── Android.meta │ │ ├── WebMediator.js │ │ ├── WebMediator.js.meta │ │ ├── iOS/ │ │ │ ├── WebViewPlugin.mm │ │ │ └── WebViewPlugin.mm.meta │ │ └── iOS.meta │ ├── Plugins.meta │ ├── Prefabs/ │ │ ├── Blue Box.prefab │ │ ├── Blue Box.prefab.meta │ │ ├── Red Box.prefab │ │ └── Red Box.prefab.meta │ ├── Prefabs.meta │ ├── Scripts/ │ │ ├── Box.js │ │ ├── Box.js.meta │ │ ├── TestInterface.js │ │ └── TestInterface.js.meta │ ├── Scripts.meta │ ├── Textures/ │ │ ├── Board.png.meta │ │ └── Checker2.png.meta │ └── Textures.meta └── ProjectSettings/ ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .DS_Store *.swp android/bin/* android/gen android/proguard.cfg android/local.properties unity/Library unity/Temp ================================================ FILE: LICENSE.txt ================================================ Copyright (C) 2011 Keijiro Takahashi 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. ================================================ FILE: README.md ================================================ ### 概要 Unity iOS および Android において web view を画面内に組み込み、その内部と連携を行うためのプラグインの実装例です。 ![screenshot](https://github.com/downloads/keijiro/unity-webview-integration/IMG_0004.jpg) 上図は実装されたサンプルシーンを実行した様子です。上部が Unity の画面で、下部が web view です。Web view 内のリンクをクリックすることにより Unity 画面内で特定のアクションが発動されます。 ### 簡単な解説 #### Unity 側 [Assets/Plugins/WebMediator.js](https://github.com/keijiro/unity-webview-integration/blob/master/unity/Assets/Plugins/WebMediator.js) が Unity 側の窓口となるスクリプトです。このスクリプトを通して web view の表示制御、配置マージン設定、指定 URL のロードを行うことができます。また、web view 内から送信されたメッセージをここから拾い上げることができます。詳しい使用方法についてはサンプルプロジェクトの [TestInterface.js](https://github.com/keijiro/unity-webview-integration/blob/master/unity/Assets/Scripts/TestInterface.js) を参照してください。 #### Web view 側 Web view 側からメッセージを送信するには [unity.js](https://github.com/keijiro/unity-webview-integration/blob/gh-pages/unity.js) をインポートし、この中で定義されている `UnityWebMediator` クラスを用いる必要があります。詳しい使用方法についてはサンプルプロジェクトの [index.html](https://github.com/keijiro/unity-webview-integration/blob/gh-pages/index.html) を参照してください。 ================================================ FILE: android/AndroidManifest.xml ================================================ ================================================ FILE: android/ant.properties ================================================ # This file is used to override default values used by the Ant build system. # # This file must be checked in Version Control Systems, as it is # integral to the build system of your project. # This file is only used by the Ant script. # You can use this to override default values such as # 'source.dir' for the location of your java source folder and # 'out.dir' for the location of your output folder. # You can also use it define how the release builds are signed by declaring # the following properties: # 'key.store' for the location of your keystore and # 'key.alias' for the name of the key to use. # The password will be asked during the build when you use the 'release' target. ================================================ FILE: android/build.xml ================================================ ================================================ FILE: android/project.properties ================================================ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! # # This file must be checked in Version Control Systems. # # To customize properties used by the Ant build system use, # "ant.properties", and override values to adapt the script to your # project structure. android.library=true # Project target. target=android-7 ================================================ FILE: android/res/layout/main.xml ================================================ ================================================ FILE: android/res/values/strings.xml ================================================ ACTIVITY_ENTRY_NAME ================================================ FILE: android/src/jp/radiumsoftware/unitywebviewexample/ExtendedUnityPlayerActivity.java ================================================ // UnityPlayerActivity and WebView integration package jp.radiumsoftware.unitywebviewexample; import com.unity3d.player.UnityPlayerActivity; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; import android.widget.ProgressBar; import java.lang.InterruptedException; import java.util.concurrent.SynchronousQueue; public class ExtendedUnityPlayerActivity extends UnityPlayerActivity { // JavaScript interface class for embedded WebView. private class JSInterface { public SynchronousQueue mMessageQueue; JSInterface() { mMessageQueue = new SynchronousQueue(); } public void pushMessage(String message) { Log.d("WebView", message); try { mMessageQueue.put(message); } catch (java.lang.InterruptedException e) { Log.d("WebView", "Queueing error - " + e.getMessage()); } } } private JSInterface mJSInterface; // JavaScript interface (message receiver) private WebView mWebView; // WebView object private ProgressBar mProgress; // Progress bar private int mLeftMargin; // Margins around the WebView private int mTopMargin; private int mRightMargin; private int mBottomMargin; private boolean mInitialLoad; // Initial load flag protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a WebView and make layout. mWebView = new WebView(this); FrameLayout layout = new FrameLayout(this); addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); layout.addView(mWebView, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY)); // Basic settings of WebView. WebSettings webSettings = mWebView.getSettings(); webSettings.setSupportZoom(false); webSettings.setJavaScriptEnabled(true); webSettings.setPluginsEnabled(true); //webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); // Set a dummy WebViewClient (which enables loading a new page in own WebView). mWebView.setWebViewClient(new WebViewClient(){}); // Add a progress bar. mProgress = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal); layout.addView(mProgress, new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, 5)); mProgress.setMax(100); mProgress.setVisibility(View.GONE); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if (progress < 100) { mProgress.setVisibility(View.VISIBLE); mProgress.setProgress(progress); } else { mProgress.setVisibility(View.GONE); } } }); // Create a JavaScript interface and bind the WebView to it. mJSInterface = new JSInterface(); mWebView.addJavascriptInterface(mJSInterface, "UnityInterface"); // Start in invisible state. mWebView.setVisibility(View.GONE); } public void updateWebView(final String lastRequestedUrl, final boolean loadRequest, final boolean visibility, final int leftMargin, final int topMargin, final int rightMargin, final int bottomMargin) { // Process load requests. if (lastRequestedUrl != null && (loadRequest || !mInitialLoad)) { runOnUiThread(new Runnable() { public void run() { mWebView.loadUrl(lastRequestedUrl); } }); mInitialLoad = true; } // Process changes in margin amounts. if (leftMargin != mLeftMargin || topMargin != mTopMargin || rightMargin != mRightMargin || bottomMargin != mBottomMargin) { mLeftMargin = leftMargin; mTopMargin = topMargin; mRightMargin = rightMargin; mBottomMargin = bottomMargin; runOnUiThread(new Runnable() { public void run() { // Apply a new layout to the WebView. FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, Gravity.NO_GRAVITY); params.setMargins(mLeftMargin, mTopMargin, mRightMargin, mBottomMargin); mWebView.setLayoutParams(params); } }); } // Process changes in visibility. if (visibility != (mWebView.getVisibility() == View.VISIBLE)) { runOnUiThread(new Runnable() { public void run() { if (visibility) { // Show and set focus. mWebView.setVisibility(View.VISIBLE); mWebView.requestFocus(); } else { // Hide. mWebView.setVisibility(View.GONE); } } }); } } public String pollWebViewMessage() { return mJSInterface.mMessageQueue.poll(); } // Transparent background public void makeTransparentWebViewBackground() { mWebView.setBackgroundColor(Color.TRANSPARENT); } } ================================================ FILE: unity/Assets/GUI/Default GUI SKin.guiskin.meta ================================================ fileFormatVersion: 1 guid: ecaca87ebef4e4961ab66cf142175f61 ================================================ FILE: unity/Assets/GUI/SU3DJPFont/Fonts/s1-mplus-1c-light.ttf.meta ================================================ fileFormatVersion: 1 guid: 596c1fd1351a65540b8f6baeb5c83ccb TrueTypeFontImporter: importerVersion: 1 size: 16 case: -1 antiAlias: 0 includeFontData: 1 use2xBehaviour: 0 style: 0 fontNames: name: ================================================ FILE: unity/Assets/GUI/SU3DJPFont/Fonts.meta ================================================ fileFormatVersion: 1 guid: 9e26e0c931f64c44799647ea7fd00b96 ================================================ FILE: unity/Assets/GUI/SU3DJPFont/license.txt ================================================ LICENSE These fonts are free softwares. Unlimited permission is granted to use, copy, and distribute it, with or without modification, either commercially and noncommercially. THESE FONTS ARE PROVIDED "AS IS" WITHOUT WARRANTY. これらのフォントはフリー(自由な)ソフトウエアです。 あらゆる改変の有無に関わらず、また商業的な利用であっても、自由にご利用、複製、再配布することができますが、全て無保証とさせていただきます。 ================================================ FILE: unity/Assets/GUI/SU3DJPFont/license.txt.meta ================================================ fileFormatVersion: 1 guid: 876dd09a256784345be2d6045b6571a3 ================================================ FILE: unity/Assets/GUI/SU3DJPFont/readme.txt ================================================  Selected U3D Japanese Fonts 05/17/2011 ------------------------------------------------------------------------ # English Selected U3D Japanese Fonts is based on M+OUTLINE Font TESTFLIGHT039 M+C. Characters are selected so that it may fit in the optimal texture size for mobile devices. It can have the characters of the size of 25 points in the 1024x1024 texture size. The following groups are contained in this asset. * Hiragana * Katakana * Alphabet , Number , Mark * 1,006 Kanji taught in Japanese primary schools * 132 Kanji in Japan states name and game words All the lists of characters are recorded on "list.txt". A question, a request, etc. to Selected U3D Japanese Fonts should inform the following address. http://www.futurecartographer.com/ masashi_wada@dearna.com Refer to the following URL for the details about M+OUTLINE Fonts. http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html ------------------------------------------------------------------------ # Japanese ( 日本語 ) Selected U3D Japanese Fontsは M+OUTLINEフォントTESTFLIGHT039 M+Cを基盤にしています。 主にモバイル機器に最適な文字サイズとテクスチャサイズを両立するために、 フォントに含む文字を以下に限定して再構成したTTFファイルです。 これらの文字セットによって、1024x1024のテクスチャであっても、25ポイントまでの大きさを保てる特徴があります。 ・ひらがな ・カタカナ ・アルファベット、数字、記号 ・小学校6年生までの教育漢字(1006文字) ・都道府県表記、ゲーム用語に適した漢字 (132文字) フォントに含まれる全ての文字のリストは list.txt に記載しています。  Selected U3D Japanese Fontsに関する質問、要望などは次のアドレスに連絡をしてください。 http://www.futurecartographer.com/ masashi_wada@dearna.com M+OUTLINEフォントに関する詳細は次のURLを参照してください。 http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index.html ================================================ FILE: unity/Assets/GUI/SU3DJPFont/readme.txt.meta ================================================ fileFormatVersion: 1 guid: 4a4f1ada9e7459344bc4acb002b22a4b ================================================ FILE: unity/Assets/GUI/SU3DJPFont.meta ================================================ fileFormatVersion: 1 guid: 2c7ff880dcb39c14199433ad6846d37b ================================================ FILE: unity/Assets/GUI.meta ================================================ fileFormatVersion: 1 guid: 3a3b1c6f5244d498e95e41026452dc53 ================================================ FILE: unity/Assets/Main.unity.meta ================================================ fileFormatVersion: 1 guid: 5dd8fad3f211b4f50aaee8743a63da4e ================================================ FILE: unity/Assets/Materials/Blue Box.mat.meta ================================================ fileFormatVersion: 1 guid: 905886db109bd4a36af150540c0bd0f1 ================================================ FILE: unity/Assets/Materials/Floor.mat.meta ================================================ fileFormatVersion: 1 guid: e06bb986f1a7e4dc6841f7cb59aeef8e ================================================ FILE: unity/Assets/Materials/Red Box.mat.meta ================================================ fileFormatVersion: 1 guid: ac8ade9aa523842fab3b893be999d08e ================================================ FILE: unity/Assets/Materials.meta ================================================ fileFormatVersion: 1 guid: eacdd09aa755f4bf6b6531b7af53dad5 ================================================ FILE: unity/Assets/Physics/Default Physic Material.physicMaterial.meta ================================================ fileFormatVersion: 1 guid: daef168d6938746eda86db30cd78df40 ================================================ FILE: unity/Assets/Physics.meta ================================================ fileFormatVersion: 1 guid: 046d56fdea7e34d05bbe1082f55a769d ================================================ FILE: unity/Assets/Plugins/Android/AndroidManifest.xml ================================================ ================================================ FILE: unity/Assets/Plugins/Android/AndroidManifest.xml.meta ================================================ fileFormatVersion: 1 guid: 50bf13cedd20a49f3b2ef3e88cf13d4f ================================================ FILE: unity/Assets/Plugins/Android/WebViewIntegration.jar.meta ================================================ fileFormatVersion: 1 guid: 94d9591b24ce3471383b7b7f121cb653 ================================================ FILE: unity/Assets/Plugins/Android.meta ================================================ fileFormatVersion: 1 guid: 22aac9bb108084be8b2ffc5ec762342e ================================================ FILE: unity/Assets/Plugins/WebMediator.js ================================================ #pragma strict // WebView-Unity mediator plugin script. import System.Runtime.InteropServices; // Message container class. class WebMediatorMessage { var path : String; // Message path var args : Hashtable; // Argument table function WebMediatorMessage(rawMessage : String) { // Retrieve a path. var split = rawMessage.Split("?"[0]); path = split[0]; // Parse arguments. args = new Hashtable(); if (split.Length > 1) { for (var pair in split[1].Split("&"[0])) { var elems = pair.Split("="[0]); args[elems[0]] = WWW.UnEscapeURL(elems[1]); } } } } private static var instance : WebMediator; private static var isClearCache : boolean; private var lastRequestedUrl : String; private var loadRequest : boolean; private var visibility : boolean; private var leftMargin : int; private var topMargin : int; private var rightMargin : int; private var bottomMargin : int; // Install the plugin. // Call this at least once before using the plugin. static function Install() { if (instance == null) { var master = new GameObject("WebMediator"); DontDestroyOnLoad(master); instance = master.AddComponent.(); InstallPlatform(); } } // Set margins around the web view. static function SetMargin(left : int, top: int, right : int, bottom : int) { instance.leftMargin = left; instance.topMargin = top; instance.rightMargin = right; instance.bottomMargin = bottom; ApplyMarginsPlatform(); } // Visibility functions. static function Show() { instance.visibility = true; } static function Hide() { instance.visibility = false; } static function IsVisible() { return instance.visibility; } static function SetClearCache() { isClearCache = true; } static function SetCache() { isClearCache = false; } // Load the page at the URL. static function LoadUrl(url : String) { instance.lastRequestedUrl = url; instance.loadRequest = true; } function Update() { UpdatePlatform(); instance.loadRequest = false; } #if UNITY_EDITOR // Unity Editor implementation. private static function InstallPlatform() { } private static function UpdatePlatform() { } private static function ApplyMarginsPlatform() { } static function PollMessage() : WebMediatorMessage { return null; } static function MakeTransparentWebViewBackground() { } #elif UNITY_IPHONE // iOS platform implementation. @DllImportAttribute("__Internal") static private function _WebViewPluginInstall() {} @DllImportAttribute("__Internal") static private function _WebViewPluginLoadUrl(url : String, isClearCache : boolean) {} @DllImportAttribute("__Internal") static private function _WebViewPluginSetVisibility(visibility : boolean) {} @DllImportAttribute("__Internal") static private function _WebViewPluginSetMargins(left : int, top : int, right : int, bottom : int) {} @DllImportAttribute("__Internal") static private function _WebViewPluginPollMessage() : String {} @DllImportAttribute("__Internal") static private function _WebViewPluginMakeTransparentBackground() {} private static var viewVisibility : boolean; private static function InstallPlatform() { _WebViewPluginInstall(); } private static function ApplyMarginsPlatform() { _WebViewPluginSetMargins(instance.leftMargin, instance.topMargin, instance.rightMargin, instance.bottomMargin); } private static function UpdatePlatform() { if (viewVisibility != instance.visibility) { viewVisibility = instance.visibility; _WebViewPluginSetVisibility(viewVisibility); } if (instance.loadRequest) { instance.loadRequest = false; _WebViewPluginLoadUrl(instance.lastRequestedUrl, isClearCache); } } static function PollMessage() : WebMediatorMessage { var message = _WebViewPluginPollMessage(); return message ? new WebMediatorMessage(message) : null; } static function MakeTransparentWebViewBackground() { _WebViewPluginMakeTransparentBackground(); } #elif UNITY_ANDROID // Android platform implementation. private static var unityPlayerClass : AndroidJavaClass; private static function InstallPlatform() { unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); } private static function ApplyMarginsPlatform() { } private static function UpdatePlatform() { var activity = unityPlayerClass.GetStatic.("currentActivity"); activity.Call("updateWebView", instance.lastRequestedUrl ? instance.lastRequestedUrl : "", instance.loadRequest, instance.visibility, instance.leftMargin, instance.topMargin, instance.rightMargin, instance.bottomMargin); } static function PollMessage() : WebMediatorMessage { var activity = unityPlayerClass.GetStatic.("currentActivity"); var message = activity.Call.("pollWebViewMessage"); return message ? new WebMediatorMessage(message) : null; } static function MakeTransparentWebViewBackground() { var activity = unityPlayerClass.GetStatic.("currentActivity"); activity.Call("makeTransparentWebViewBackground"); } #endif ================================================ FILE: unity/Assets/Plugins/WebMediator.js.meta ================================================ fileFormatVersion: 1 guid: 9b61fa8dd1f9f40d9a0788beb93cd400 ================================================ FILE: unity/Assets/Plugins/iOS/WebViewPlugin.mm ================================================ // Web view integration plug-in for Unity iOS. #import extern UIViewController *UnityGetGLViewController(); // Root view controller of Unity screen. #pragma mark Plug-in Functions static UIWebView *webView; extern "C" void _WebViewPluginInstall() { // Add the web view onto the root view (but don't show). UIViewController *rootViewController = UnityGetGLViewController(); webView = [[UIWebView alloc] initWithFrame:rootViewController.view.frame]; webView.hidden = YES; [rootViewController.view addSubview:webView]; } extern "C" void _WebViewPluginMakeTransparentBackground() { [webView setBackgroundColor:[UIColor clearColor]]; [webView setOpaque:NO]; } extern "C" void _WebViewPluginLoadUrl(const char* url, boolean isClearCache) { if (isClearCache) { [[NSURLCache sharedURLCache] removeAllCachedResponses]; } [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]]]; } extern "C" void _WebViewPluginSetVisibility(bool visibility) { webView.hidden = visibility ? NO : YES; } extern "C" void _WebViewPluginSetMargins(int left, int top, int right, int bottom) { UIViewController *rootViewController = UnityGetGLViewController(); CGRect frame = rootViewController.view.frame; CGFloat scale = rootViewController.view.contentScaleFactor; CGRect screenBound = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBound.size; // Obtaining the current device orientation UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; // landscape if (orientation) { frame.size.width = screenSize.height - (left + right) / scale; frame.size.height = screenSize.width - (top + bottom) / scale; } else { // portrait frame.size.width = screenSize.width - (left + right) / scale; frame.size.height = screenSize.height - (top + bottom) / scale; } frame.origin.x += left / scale; frame.origin.y += top / scale; webView.frame = frame; } extern "C" char *_WebViewPluginPollMessage() { // Try to retrieve a message from the message queue in JavaScript context. NSString *message = [webView stringByEvaluatingJavaScriptFromString:@"unityWebMediatorInstance.pollMessage()"]; if (message && message.length > 0) { NSLog(@"UnityWebViewPlugin: %@", message); char* memory = static_cast(malloc(strlen(message.UTF8String) + 1)); if (memory) strcpy(memory, message.UTF8String); return memory; } else { return NULL; } } ================================================ FILE: unity/Assets/Plugins/iOS/WebViewPlugin.mm.meta ================================================ fileFormatVersion: 2 guid: 4fd761aa32d674f48b76101ac5cf8971 ================================================ FILE: unity/Assets/Plugins/iOS.meta ================================================ fileFormatVersion: 2 guid: 9bde65d35751a4fa88830f764562c2bb ================================================ FILE: unity/Assets/Plugins.meta ================================================ fileFormatVersion: 1 guid: 04a4b0667591a44f6a9cc634795749cf ================================================ FILE: unity/Assets/Prefabs/Blue Box.prefab.meta ================================================ fileFormatVersion: 1 guid: c1a1ab85a23cd4ce1bdd3731ac0ab9dd ================================================ FILE: unity/Assets/Prefabs/Red Box.prefab.meta ================================================ fileFormatVersion: 1 guid: 74768062b89004afb801f11a7a523ca1 ================================================ FILE: unity/Assets/Prefabs.meta ================================================ fileFormatVersion: 1 guid: 9eb3019c10b364779925ef1ec161fb47 ================================================ FILE: unity/Assets/Scripts/Box.js ================================================ #pragma strict function Update() { if (transform.position.y < -2.0) Destroy(gameObject); } ================================================ FILE: unity/Assets/Scripts/Box.js.meta ================================================ fileFormatVersion: 1 guid: 5f957e7e7cda347e0bbfaf9c31ec781d ================================================ FILE: unity/Assets/Scripts/TestInterface.js ================================================ #pragma strict var guiSkin : GUISkin; var redBoxPrefab : GameObject; var blueBoxPrefab : GameObject; private var note : String; // Show the web view (with margins) and load the index page. private function ActivateWebView() { WebMediator.LoadUrl("http://keijiro.github.com/unity-webview-integration/index.html"); WebMediator.SetMargin(12, Screen.height / 2 + 12, 12, 12); WebMediator.Show(); } // Hide the web view. private function DeactivateWebView() { WebMediator.Hide(); // Clear the state of the web view (by loading a blank page). WebMediator.LoadUrl("about:blank"); } // Process messages coming from the web view. private function ProcessMessages() { while (true) { // Poll a message or break. var message = WebMediator.PollMessage(); if (!message) break; if (message.path == "/spawn") { // "spawn" message. if (message.args.ContainsKey("color")) { var prefab = (message.args["color"] == "red") ? redBoxPrefab : blueBoxPrefab; } else { prefab = Random.value < 0.5 ? redBoxPrefab : blueBoxPrefab; } var box = Instantiate(prefab, redBoxPrefab.transform.position, Random.rotation) as GameObject; if (message.args.ContainsKey("scale")) { box.transform.localScale = Vector3.one * float.Parse(message.args["scale"] as String); } } else if (message.path == "/note") { // "note" message. note = message.args["text"] as String; } else if (message.path == "/print") { // "print" message. var text = message.args["line1"] as String; if (message.args.ContainsKey("line2")) { text += "\n" + message.args["line2"] as String; } Debug.Log(text); Debug.Log("(" + text.Length + " chars)"); } else if (message.path == "/close") { // "close" message. DeactivateWebView(); } } } function Start() { WebMediator.Install(); } function Update() { if (WebMediator.IsVisible()) { ProcessMessages(); } else if (Input.GetButtonDown("Fire1") && Input.mousePosition.y < Screen.height / 2) { ActivateWebView(); } } function OnGUI() { var sw = Screen.width; var sh = Screen.height; GUI.skin = guiSkin; if (note) GUI.Label(Rect(0, 0, sw, 0.5 * sh), note); GUI.Label(Rect(0, 0.5 * sh, sw, 0.5 * sh), "TAP HERE", "center"); } ================================================ FILE: unity/Assets/Scripts/TestInterface.js.meta ================================================ fileFormatVersion: 1 guid: de41a1264b5be41c48fa4a0b821508b2 ================================================ FILE: unity/Assets/Scripts.meta ================================================ fileFormatVersion: 1 guid: 6f9ab5fa22bd84d038705e7f6d302a8f ================================================ FILE: unity/Assets/Textures/Board.png.meta ================================================ fileFormatVersion: 1 guid: b9953bd5259dc48cc95acccd0f8c1228 TextureImporter: importerVersion: 1 maxTextureSize: 1024 textureFormat: -1 grayscaleToAlpha: 0 npotScale: 1 generateCubemap: 0 isReadable: 0 mipmaps: generation: 1 correctGamma: 0 border: 0 filter: 0 fadeout: 0 fadeoutStart: 1 fadeoutEnd: 3 bumpmap: generation: 0 bumpyness: 0.25 filter: 0 textureSettings: filterMode: -1 anisoLevel: -1 mipmapBias: -1 wrapMode: -1 ================================================ FILE: unity/Assets/Textures/Checker2.png.meta ================================================ fileFormatVersion: 1 guid: a94bba682ebe648c08416aff1b18ad2e TextureImporter: importerVersion: 2 maxTextureSize: 1024 textureFormat: -1 grayscaleToAlpha: 0 npotScale: 1 generateCubemap: 0 isReadable: 0 textureType: 0 mipmaps: generation: 1 correctGamma: 0 border: 0 filter: 0 fadeout: 0 fadeoutStart: 1 fadeoutEnd: 3 bumpmap: generation: 0 bumpyness: 0.25 filter: 0 textureSettings: filterMode: -1 anisoLevel: -1 mipmapBias: -1 wrapMode: -1 buildTargetSettings: iPhone: maxTextureSize: 128 textureFormat: -3 ================================================ FILE: unity/Assets/Textures.meta ================================================ fileFormatVersion: 1 guid: 28e2e9674dd404ef6ab51022aef57fc0