Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
製作 Unity Plugin for Android
Search
Johnny Sung
September 25, 2014
Technology
0
210
製作 Unity Plugin for Android
製作 Unity Plugin for Android
自從上次講的iOS版本了之後,不講一下Android怎麼可以XD
2014.09.25 @ Android Taipei
Johnny Sung
September 25, 2014
Tweet
Share
More Decks by Johnny Sung
See All by Johnny Sung
Kubernetes 地端自建 v.s. GKE,哪個更適合你? @Devfest Taipei 2024
j796160836
0
10
地端自建 Kubernetes (K8s) 小宇宙 (On-premises Kubernetes) @ CNTUG 2024/11 Meetup #63
j796160836
0
11
[AI LLM] Gemma 初體驗 @ GDG Cloud Taipei Meetup #70
j796160836
0
11
ArgoCD 的雷 碰過的人就知道 @TSMC IT Community Meetup #4
j796160836
0
50
使用 Kong 與 GitOps 來管理您企業的 API 呼叫 @ 2024 台灣雲端大會
j796160836
0
46
[AI / ML] 用 LLM (Large language model) 來整理您的知識庫 @ Devfest Taipei 2023
j796160836
0
140
[Flutter] Flutter Provider 看似簡單卻又不簡單的狀態管理工具
j796160836
0
20
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
j796160836
0
38
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
j796160836
0
230
Other Decks in Technology
See All in Technology
モノレポ開発のエラー、誰が見る?Datadog で実現する適切なトリアージとエスカレーション
biwashi
6
770
家電アプリ共通PF "Linova" のAPI利用とPostman活用事例ご紹介
yukiogawa
0
130
Classmethod AI Talks(CATs) #15 司会進行スライド(2025.02.06) / classmethod-ai-talks-aka-cats_moderator-slides_vol15_2025-02-06
shinyaa31
0
170
SA Night #2 FinatextのSA思想/SA Night #2 Finatext session
satoshiimai
1
100
日経電子版 x AIエージェントの可能性とAgentic RAGによって提案書生成を行う技術
masahiro_nishimi
1
290
Postmanを使いこなす!2025年ぜひとも押さえておきたいPostmanの10の機能
nagix
2
120
事業継続を支える自動テストの考え方
tsuemura
0
300
SCSAから学ぶセキュリティ管理
masakamayama
0
140
WAF に頼りすぎない AWS WAF 運用術 meguro sec #1
izzii
0
460
目の前の仕事と向き合うことで成長できる - 仕事とスキルを広げる / Every little bit counts
soudai
22
5.8k
オブザーバビリティの観点でみるAWS / AWS from observability perspective
ymotongpoo
7
1k
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
6
1.4k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
175
51k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
For a Future-Friendly Web
brad_frost
176
9.5k
Transcript
製作 Unity Plugin for Android Johnny Sung 2014.09.24 @ Android
Taipei
荈䖰$PDPB)FBE5BJQFJ ⴕ ٰڅù ❧ ٹډö ✫⛓䖕
ّ∣ὕ҂ấĆ ሱ࠭ᾣ
https://fb.com/j796160836 Johnny Sung Mobile devices Developer https://plus.google.com/+JohnnySung http://about.me/j796160836 Mobile devices
Developer https://plus.google.com/+JohnnySung http://about.me/j796160836
Agenda 6OJUZۀ∻ᾏࢺ (BNF0CKFDU $PNQPOFOU "OESPJE1MVHJOℯቔ "OESPJEࢤ१ $ࢤ१ ẵσյЇ٢ᇂ֥ᇿၩ൙⇊
6OJUZ僽➊랃 %䵔↰ႄౣ ္ॖၛ⇔%(BNF ಆ౯"QQ䵔↰㍇Ⴈ +BWB4DSJQU$#00 ቨℸル֥ॴ https://unity3d.com/unity/multiplatform http://www.moneydj.com/kmdj/news/NewsViewer.aspx?a=f4767522-2281-4d16-8ed0-99c6acb797f8
X .POPEFWFMPQ
6OJUZ涸嚌䙂 GameObject Component
GameObject GameObject
GameObject Component
♧⦐瑠涯涸$PNQPOFOUꟀ鸏垺 using UnityEngine; using System.Collections; public class testComponent :
MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }
.POP#FIBWJPVS涸欰ㄐ鹋劍 "XBLF ⶾ鸤儘ⴲ㨥⻋ 4UBSU 㛂遤儘ⴲ㨥⻋ 6QEBUF 粭㕮鶬㕖 ⣜佪腋罜㹁⢿GQT 'JYFE6QEBUF
暟椚鶬㕖
None
http://docs.unity3d.com/ScriptReference/
C# AndroidJavaClass AndroidJavaObject Java Java UnitySendMessage() C# (對應的接⼝口) (Unity Engine)
(Native) 6OJUZ1MVHJO涸ㄎ〭倰䒭
"OESPJE畮彋⪔ 倞"OESPJEQSPKFDU 䒸欽DMBTTFTKBS PQUJPOBM 之㻨玑䒭
/Applications/Unity/Unity.app/Contents/ PlaybackEngines/AndroidPlayer/development/bin classes.jar 檔案位置 Mac C:\Program Files (x86)\Unity\Editor\Data\ PlaybackEngines\androidplayer\development\bin Windows
(optional)
6OJUZㄎ〭"OESPJE涸侸 AndroidJavaClass AndroidJavaObject
h"p://docs.unity3d.com/ScriptReference/AndroidJavaObject.html
AndroidJavaObject Call() CallStatic() Get() GetStatic() SetStatic()
h"p://docs.unity3d.com/ScriptReference/AndroidJavaObject.Call.html
package com.example.unitytest; ! public class Pet { private int id;
private String name; ! public void setId(int id) { this.id = id; } ! public void setName(String name) { this.name = name; } ! @Override public String toString() { return "Pet [id=" + id + ", name=" + name + "]"; } ! } ♧⦐矦㋲涸眕⢿
AndroidJavaObject obj = new AndroidJavaObject ("com.example.unitytest.Pet"); obj.Call ("setId", 123); obj.Call
("setName", "Lucky"); string str = obj.Call<string> ("toString"); Debug.Log (str); Pet obj = new Pet(); obj.setId(123); obj.setName("Lucky"); String str=obj.toString(); Log.v("Unity", str); Java C# ♧⦐矦㋲涸眕⢿
try { UnityPlayer.UnitySendMessage(gameObject, method, message); } catch(Exception e) { Log.e("Unity",
"UnitySendMessage failed" + e.getMessage()); } ꡠ倴6OJUZ4FOE.FTTBHF GameObject Name Method Name Parameter
C# 䱺佐 ꡠ倴6OJUZ4FOE.FTTBHF public void CallFromObjC(string message) { Debug.Log
(message); } MyViewObject.cs try { UnityPlayer.UnitySendMessage("MyGameObject", "CallFromObjC", "hello"); } catch (Exception e) { e.printStackTrace(); } Java ⫄鷑 MyPlugin.java
《䖤Activity import android.app.Activity; import com.unity3d.player.UnityPlayer; ! public class MyViewPlugin {
public static Activity getActivity() { Activity a = UnityPlayer.currentActivity; return a; } } public static AndroidJavaClass getActivity () { AndroidJavaClass player; player = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"); AndroidJavaObject a; a = player.GetStatic<AndroidJavaObject> (“currentActivity"); return a; } C# Java
package com.unity3d.player; ! public class UnityPlayerNativeActivity extends NativeActivity { //
don't change the name of this variable; referenced from native code protected UnityPlayer mUnityPlayer; ! // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); ! getWindow().takeSurface(null); setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); ! mUnityPlayer = new UnityPlayer(this); if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); ! setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } ! // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } ! // … UnityPlayerNativeActivity.java
糒䪭㸐 package com.example.unitytest; ! import android.os.Bundle; ! import com.unity3d.player.UnityPlayerNativeActivity; !
public class MainActivity extends UnityPlayerNativeActivity { ! @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } ! }
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.unitytest" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" /> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false"> <activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen| keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize| smallestScreenSize|fontScale" android:name="com.example.unitytest.UnityPlayerNativeActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> </activity> </application> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="20" /> <uses-feature android:glEsVersion="0x00020000" /> </manifest> AndroidManifest.xml 岤䠑"OESPJE.BOJGFTU
䩧⺫㛂遤
"OESPJE畮䩧⺫ 鱒ⴀ 玑䒭焺鱒ⴀ䧭KBS "OESPJE.BOJGFTUYNM 须彂墂呪
None
յЇ℻ԛ Assets! Plugins! Android! bin! MyJar.jar! res! drawable-hdpi! drawable-ldpi! …!
layout! values! AndroidManifest.xml
յЇ℻ԛ 6OJUZ晝劥⟃♳佅䴂 ⴀ"OESPJE㼠呪
Q and A
Thanks!
佞♳"TTFU4UPSF风㢫䘰
References Unity Webview https://github.com/gree/unity-webview Building Plugins for Android http://docs.unity3d.com/Manual/PluginsForAndroid.html 藍斯洛‧雜技的雜記:
Unity3D Plug-in for Android -- Activity 擴展⽅方法 http://lancelotdiary.blogspot.tw/2012/05/unity3d-plug-in-for- android-activity.html 懂點Unity Plugin,替荷包省點錢!(安卓 Android篇) http://www.unityin.com/2013/05/%E6%87%82%E9%BB%9Eunity-plugin%EF%BC%8C %E6%9B%BF%E8%8D%B7%E5%8C%85%E7%9C%81%E9%BB%9E%E9%8C%A2%EF%BC %81%E5%AE%89%E5%8D%93-android%E7%AF%87/
Unity3D研究院之打開Activity與調⽤用JAVA代碼傳遞參數 http://www.xuanyusong.com/archives/667 Unity GPS plugin development tutorial: building a
Android plugin for Unity with Eclipse and Ant http://www.mat-d.com/site/unity-gps-plugin-development-tutorial- building-a-android-plugin-for-unity-with-eclipse-and-ant/ References
ꡠ倴Android 涸Back ꒳ public class BackKey : MonoBehaviour { void
Update() { #if UNITY_ANDROID if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); // Application.LoadLevel("PreviousLevel"); } #endif } } #BDL꒳剚㼩䥰ⵌ꒳湏涸&TD h"p://answers.unity3d.com/quesBons/25535/android-‐back-‐bu"on-‐event.html
Unity∣Ⴈ‴თ https://www.facebook.com/groups/581769871867384 想做遊戲?