SlideShare une entreprise Scribd logo
1  sur  19
Télécharger pour lire hors ligne
Unity3D Plugins
Development Guide
ChenKaiJung
Plugins Are?
● Libraries of native code written in C, C++,
Objective-C….etc
● Allow your game code to call functions from
these libraries
Why do you need to develop a Plugin?
●
●
●
●
●
●

Unity3D can’t Do That
Reuse C/C++/Objective-C components
Difficult customize in Unity3D Assets Store
Cross-Device
Cross-Platform
Security Issues
Interface?
● Just like call Unmanaged DLL in .NET
● Sync
○ Call the functions and get return values

● Async
○ Use UnitySendMessage

● Name mangling Issue
○ Use extern "C" { }
○ or _ZN·9funtown·7ios·6init·E
Plugins for Different Device
● Compile time - iOS
#if UNITY_IOS
#else
#endif

● Compile time - Android
#if UNITY_ANDROID
#else
#endif
Plugins for Different Device
● Runtime - iOS
if (Application.platform == RuntimePlatform.OSXPlayer)

● Runtime - Android
if (Application.platform == RuntimePlatform.Android)
iOS Plugins
● C# Dll Import
[DllImport ("__Internal")] private static extern void iosInit(bool cookie, bool
logging, bool status, bool frictionlessRequests);

● C/C++ Native Functions in xxx.mm
extern "C" {
void iosInit(bool _cookie, bool _logging, bool _status, bool
_frictionlessRequests) { [[FbUnityInterface alloc] initWithCookie:_cookie
logging:_logging status:_status frictionlessRequests:_frictionlessRequests]; } }
iOS Plugins
#ifdef __cplusplus
extern "C" {
#endif
void UnitySendMessage(const char* obj, const char* method, const char*
msg);
#ifdef __cplusplus
}
#endif
iOS 3rd Powerful tools
● XCode Editor for
Unity3D

{
"group": "Facebook",
"patches": [],
"libs": [
"Facebook/Editor/iOS/FacebookSDK/libfacebook_ios_sdk.a:<group>"
],
"librarysearchpaths": [
"Facebook/Editor/iOS/FacebookSDK/"
],
"frameworks": [
"Accounts.framework:weak"
],
"headerpaths": [
"Facebook/Editor/iOS"
],
"files": [
"Facebook/Editor/iOS/FbUnityInterface.mm",
"Facebook/Editor/iOS/FbUnityInterface.h"
],
"folders": [],
"excludes": [
"^.*.meta$",
"^.*.mdown^",
"^.*.pdf$"
]

○ Post Process Build
○ Json Configure
(fixup.projmods)

}
iOS Tips
● DO NOT call plugins Pre-Frame
● String passing should be encoded by UTF-8
● Wrappers your Message and let it easily
encodes and decodes cross language. Ex:
JSON,Query String
● Uses XCode Editor for building automation
Android Plugins
● C# Dll Import
[DllImport ("unityinapppurchase")] private static extern void androidFTInit
(bool cookie, bool logging, bool status, bool frictionlessRequests);

● C++ Native Functions in unityinapppurchase.
so
extern "C" {
void androidFTInit(bool _cookie, bool _logging, bool _status, bool
_frictionlessRequests) { LOGD("androidFTInit called"); } }
Android Plugins
● C# Load Java Class
ftJava = new AndroidJavaClass("tw.com.funtown.unity.FT");
ftjava.CallStatic("Init", "");

● Java Class
public class FT
{
public static void init(String params) {
Log.d("FTUnitySDK", "init called with params: " + params);
}
}
Android Plugins
● Overwrite onActivityResult
public class FTUnityPlayerActivity extends UnityPlayerActivity
{
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("FTUnityPlayerActivity", "onActivityResult: requestCode: " +
requestCode + ", resultCode:" + resultCode);
}
}
Android Plugins
● Modify your Manifest.xml Automatically
<activity android:name="tw.com.funtown.unity.FTUnityPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="tw.com.funtown.LoginActivity" >
</activity>
Android Plugins
● Call UnitySendMessage using JNI
bool retval=JniHelper::getStaticMethodInfo(t, "com/unity3d/player/UnityPlayer" ,"UnitySendMessage"
,"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
if(retval==false) return;
jstring objectStr = t.env->NewStringUTF(obj);
jstring methodStr = t.env->NewStringUTF(method);
jstring msgStr = t.env->NewStringUTF(msg);
t.env->CallStaticVoidMethod(t.classID,t.methodID,objectStr,methodStr,msgStr);
jthrowable exception = t.env->ExceptionOccurred();
if (exception) {
t.env->ExceptionDescribe();
t.env->DeleteLocalRef(exception);
t.env->ExceptionClear();
} else {
}
…..Please delete your allocated resource here
Android Tips
● DO NOT call plugins Pre-Frame
● Mono garbage collector by using(){..} or xx.
Dispose() in C#
● Put your *.jar *.so in
YOUR_PROJECT/Assets/Plugins
● Be careful of Android resource conflict
problem
Go through OAuth SDK
Q&A
References
● Unity3D Official Plugins document http://docs.unity3d.
com/Documentation/Manual/Plugins.html
● Facebook Unity3D Plugin https://developers.facebook.
com/docs/unity
● A company sells Unity3D Mobile Plugins http://prime31.
com/

Contenu connexe

Tendances

Standalone Android Apps in Python
Standalone Android Apps in PythonStandalone Android Apps in Python
Standalone Android Apps in PythonBaptiste Lagarde
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)DroidConTLV
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Xavier Hallade
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with DartGDGKuwaitGoogleDevel
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Brillo/Weave Internals
Brillo/Weave InternalsBrillo/Weave Internals
Brillo/Weave InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform ToolsOpersys inc.
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development KitPeter R. Egli
 
Extending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteExtending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentKarim Yaghmour
 

Tendances (20)

Standalone Android Apps in Python
Standalone Android Apps in PythonStandalone Android Apps in Python
Standalone Android Apps in Python
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
NDK Introduction
NDK IntroductionNDK Introduction
NDK Introduction
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart
 
Embedded Android Workshop with Marshmallow
Embedded Android Workshop with MarshmallowEmbedded Android Workshop with Marshmallow
Embedded Android Workshop with Marshmallow
 
Android ndk: Entering the native world
Android ndk: Entering the native worldAndroid ndk: Entering the native world
Android ndk: Entering the native world
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Brillo/Weave Internals
Brillo/Weave InternalsBrillo/Weave Internals
Brillo/Weave Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Developing Android Platform Tools
Developing Android Platform ToolsDeveloping Android Platform Tools
Developing Android Platform Tools
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development Kit
 
Extending Android's Platform Toolsuite
Extending Android's Platform ToolsuiteExtending Android's Platform Toolsuite
Extending Android's Platform Toolsuite
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 

En vedette

製作 Unity Plugin for iOS
製作 Unity Plugin for iOS製作 Unity Plugin for iOS
製作 Unity Plugin for iOSJohnny Sung
 
New York 2013
New York 2013New York 2013
New York 2013osarma9
 
Imperial Distribution CaseStudy-Vunani-2012
Imperial Distribution CaseStudy-Vunani-2012Imperial Distribution CaseStudy-Vunani-2012
Imperial Distribution CaseStudy-Vunani-2012IMPERIAL Logistics
 
Hayn portfolio 2012
Hayn portfolio 2012Hayn portfolio 2012
Hayn portfolio 2012dylanhayn
 
Solo in italia (1)
Solo in italia (1)Solo in italia (1)
Solo in italia (1)decrescentis
 
Entregapremiosvela
EntregapremiosvelaEntregapremiosvela
Entregapremiosvelaosarma9
 
6A THE THREE WISE MEN
6A THE THREE WISE MEN6A THE THREE WISE MEN
6A THE THREE WISE MENosarma9
 
Primary research
Primary researchPrimary research
Primary researchRuthN
 
Las marzas
Las marzasLas marzas
Las marzasosarma9
 
How I feel in a day, by Sofía.
How I feel in a day, by Sofía.How I feel in a day, by Sofía.
How I feel in a day, by Sofía.osarma9
 
Avoid loss of hair while coding Unity3D plugin for mobile
Avoid loss of hair while coding Unity3D plugin for mobileAvoid loss of hair while coding Unity3D plugin for mobile
Avoid loss of hair while coding Unity3D plugin for mobileValerio Riva
 
Dr philtest -know_yourself
Dr philtest -know_yourselfDr philtest -know_yourself
Dr philtest -know_yourselfOmar Farooq
 
Barriers and facilitators to community pharmacy management of people with ost...
Barriers and facilitators to community pharmacy management of people with ost...Barriers and facilitators to community pharmacy management of people with ost...
Barriers and facilitators to community pharmacy management of people with ost...NIK HADIJAH
 
Introduction to AR with Unity3D
Introduction to AR with Unity3DIntroduction to AR with Unity3D
Introduction to AR with Unity3DAndreas Blick
 

En vedette (17)

製作 Unity Plugin for iOS
製作 Unity Plugin for iOS製作 Unity Plugin for iOS
製作 Unity Plugin for iOS
 
New York 2013
New York 2013New York 2013
New York 2013
 
Imperial Distribution CaseStudy-Vunani-2012
Imperial Distribution CaseStudy-Vunani-2012Imperial Distribution CaseStudy-Vunani-2012
Imperial Distribution CaseStudy-Vunani-2012
 
Hayn portfolio 2012
Hayn portfolio 2012Hayn portfolio 2012
Hayn portfolio 2012
 
Solo in italia (1)
Solo in italia (1)Solo in italia (1)
Solo in italia (1)
 
Entregapremiosvela
EntregapremiosvelaEntregapremiosvela
Entregapremiosvela
 
6A THE THREE WISE MEN
6A THE THREE WISE MEN6A THE THREE WISE MEN
6A THE THREE WISE MEN
 
Gamification research
Gamification researchGamification research
Gamification research
 
Macquarie Investor Day 2012
Macquarie Investor Day 2012Macquarie Investor Day 2012
Macquarie Investor Day 2012
 
Primary research
Primary researchPrimary research
Primary research
 
Las marzas
Las marzasLas marzas
Las marzas
 
How I feel in a day, by Sofía.
How I feel in a day, by Sofía.How I feel in a day, by Sofía.
How I feel in a day, by Sofía.
 
Avoid loss of hair while coding Unity3D plugin for mobile
Avoid loss of hair while coding Unity3D plugin for mobileAvoid loss of hair while coding Unity3D plugin for mobile
Avoid loss of hair while coding Unity3D plugin for mobile
 
Dr philtest -know_yourself
Dr philtest -know_yourselfDr philtest -know_yourself
Dr philtest -know_yourself
 
Barriers and facilitators to community pharmacy management of people with ost...
Barriers and facilitators to community pharmacy management of people with ost...Barriers and facilitators to community pharmacy management of people with ost...
Barriers and facilitators to community pharmacy management of people with ost...
 
Introduction to AR with Unity3D
Introduction to AR with Unity3DIntroduction to AR with Unity3D
Introduction to AR with Unity3D
 
Unity 3d Basics
Unity 3d BasicsUnity 3d Basics
Unity 3d Basics
 

Similaire à Unity3D Plugins Development Guide

iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)David Truxall
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Johan Thelin
 
Android Developer Days: Increasing performance of big arrays processing on An...
Android Developer Days: Increasing performance of big arrays processing on An...Android Developer Days: Increasing performance of big arrays processing on An...
Android Developer Days: Increasing performance of big arrays processing on An...Stanfy
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by stepJungsoo Nam
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8Phil Eaton
 
Android Developing Overview
Android Developing OverviewAndroid Developing Overview
Android Developing OverviewAbdallah Abuouf
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity SecuritySeungmin Shin
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.Girish Ghate
 
Lessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidLessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidManish Mathai
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...Paris Open Source Summit
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io
 

Similaire à Unity3D Plugins Development Guide (20)

iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
Nodejs
NodejsNodejs
Nodejs
 
Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011Necessitas - Qt on Android - from FSCONS 2011
Necessitas - Qt on Android - from FSCONS 2011
 
Android Developer Days: Increasing performance of big arrays processing on An...
Android Developer Days: Increasing performance of big arrays processing on An...Android Developer Days: Increasing performance of big arrays processing on An...
Android Developer Days: Increasing performance of big arrays processing on An...
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
Deep Learning Edge
Deep Learning Edge Deep Learning Edge
Deep Learning Edge
 
AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 
Android Developing Overview
Android Developing OverviewAndroid Developing Overview
Android Developing Overview
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
[Gstar 2013] Unity Security
[Gstar 2013] Unity Security[Gstar 2013] Unity Security
[Gstar 2013] Unity Security
 
Hidden Dragons of CGO
Hidden Dragons of CGOHidden Dragons of CGO
Hidden Dragons of CGO
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
OpenGL Introduction.
OpenGL Introduction.OpenGL Introduction.
OpenGL Introduction.
 
Lessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to AndroidLessons learned from porting Roloengine from iOS to Android
Lessons learned from porting Roloengine from iOS to Android
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
 
Mender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and GolangMender.io | Develop embedded applications faster | Comparing C and Golang
Mender.io | Develop embedded applications faster | Comparing C and Golang
 
Transitioning to Native
Transitioning to NativeTransitioning to Native
Transitioning to Native
 

Dernier

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 

Dernier (20)

Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 

Unity3D Plugins Development Guide

  • 2. Plugins Are? ● Libraries of native code written in C, C++, Objective-C….etc ● Allow your game code to call functions from these libraries
  • 3. Why do you need to develop a Plugin? ● ● ● ● ● ● Unity3D can’t Do That Reuse C/C++/Objective-C components Difficult customize in Unity3D Assets Store Cross-Device Cross-Platform Security Issues
  • 4. Interface? ● Just like call Unmanaged DLL in .NET ● Sync ○ Call the functions and get return values ● Async ○ Use UnitySendMessage ● Name mangling Issue ○ Use extern "C" { } ○ or _ZN·9funtown·7ios·6init·E
  • 5. Plugins for Different Device ● Compile time - iOS #if UNITY_IOS #else #endif ● Compile time - Android #if UNITY_ANDROID #else #endif
  • 6. Plugins for Different Device ● Runtime - iOS if (Application.platform == RuntimePlatform.OSXPlayer) ● Runtime - Android if (Application.platform == RuntimePlatform.Android)
  • 7. iOS Plugins ● C# Dll Import [DllImport ("__Internal")] private static extern void iosInit(bool cookie, bool logging, bool status, bool frictionlessRequests); ● C/C++ Native Functions in xxx.mm extern "C" { void iosInit(bool _cookie, bool _logging, bool _status, bool _frictionlessRequests) { [[FbUnityInterface alloc] initWithCookie:_cookie logging:_logging status:_status frictionlessRequests:_frictionlessRequests]; } }
  • 8. iOS Plugins #ifdef __cplusplus extern "C" { #endif void UnitySendMessage(const char* obj, const char* method, const char* msg); #ifdef __cplusplus } #endif
  • 9. iOS 3rd Powerful tools ● XCode Editor for Unity3D { "group": "Facebook", "patches": [], "libs": [ "Facebook/Editor/iOS/FacebookSDK/libfacebook_ios_sdk.a:<group>" ], "librarysearchpaths": [ "Facebook/Editor/iOS/FacebookSDK/" ], "frameworks": [ "Accounts.framework:weak" ], "headerpaths": [ "Facebook/Editor/iOS" ], "files": [ "Facebook/Editor/iOS/FbUnityInterface.mm", "Facebook/Editor/iOS/FbUnityInterface.h" ], "folders": [], "excludes": [ "^.*.meta$", "^.*.mdown^", "^.*.pdf$" ] ○ Post Process Build ○ Json Configure (fixup.projmods) }
  • 10. iOS Tips ● DO NOT call plugins Pre-Frame ● String passing should be encoded by UTF-8 ● Wrappers your Message and let it easily encodes and decodes cross language. Ex: JSON,Query String ● Uses XCode Editor for building automation
  • 11. Android Plugins ● C# Dll Import [DllImport ("unityinapppurchase")] private static extern void androidFTInit (bool cookie, bool logging, bool status, bool frictionlessRequests); ● C++ Native Functions in unityinapppurchase. so extern "C" { void androidFTInit(bool _cookie, bool _logging, bool _status, bool _frictionlessRequests) { LOGD("androidFTInit called"); } }
  • 12. Android Plugins ● C# Load Java Class ftJava = new AndroidJavaClass("tw.com.funtown.unity.FT"); ftjava.CallStatic("Init", ""); ● Java Class public class FT { public static void init(String params) { Log.d("FTUnitySDK", "init called with params: " + params); } }
  • 13. Android Plugins ● Overwrite onActivityResult public class FTUnityPlayerActivity extends UnityPlayerActivity { public void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d("FTUnityPlayerActivity", "onActivityResult: requestCode: " + requestCode + ", resultCode:" + resultCode); } }
  • 14. Android Plugins ● Modify your Manifest.xml Automatically <activity android:name="tw.com.funtown.unity.FTUnityPlayerActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="tw.com.funtown.LoginActivity" > </activity>
  • 15. Android Plugins ● Call UnitySendMessage using JNI bool retval=JniHelper::getStaticMethodInfo(t, "com/unity3d/player/UnityPlayer" ,"UnitySendMessage" ,"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); if(retval==false) return; jstring objectStr = t.env->NewStringUTF(obj); jstring methodStr = t.env->NewStringUTF(method); jstring msgStr = t.env->NewStringUTF(msg); t.env->CallStaticVoidMethod(t.classID,t.methodID,objectStr,methodStr,msgStr); jthrowable exception = t.env->ExceptionOccurred(); if (exception) { t.env->ExceptionDescribe(); t.env->DeleteLocalRef(exception); t.env->ExceptionClear(); } else { } …..Please delete your allocated resource here
  • 16. Android Tips ● DO NOT call plugins Pre-Frame ● Mono garbage collector by using(){..} or xx. Dispose() in C# ● Put your *.jar *.so in YOUR_PROJECT/Assets/Plugins ● Be careful of Android resource conflict problem
  • 18. Q&A
  • 19. References ● Unity3D Official Plugins document http://docs.unity3d. com/Documentation/Manual/Plugins.html ● Facebook Unity3D Plugin https://developers.facebook. com/docs/unity ● A company sells Unity3D Mobile Plugins http://prime31. com/