SlideShare a Scribd company logo
Plugin
What is Plugin?
• 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

Plugins for Different Device
• iOS
#if UNITY_IOS
#else

#endif
if (Application.platform == RuntimePlatform.IPhonePlayer)
• Android
#if UNITY_ANDROID
#else

#endif
if (Application.platform == RuntimePlatform.Android)
iOS Plugins
• C/C++ Native Functions in xxx.mm
extern “C”{
float ReturnFloat()
{ return 10.5; }
}
• C# Dll Import

using System.Runtime.InteropServices;
[DllImport("__Internal")]
public static extern float ReturnFloat();
iOS Plugins
• C/C++ Native Functions in xxx.h
void UnitySendMessage(const char* obj, const char* method, const
char* msg);
• C/C++ Native Functions in xxx.mm
extern “C”{
void UnityMessage(char* obj, char* function, char* message){
UnitySendMessage(obj, function, message);}
}
• C# Dll Import

using System.Runtime.InteropServices;
[DllImport("__Internal")]
public static extern float UnityMessage(string obj, string function, string
message);
Android Plugins
• C/C++ Native Functions in xxx.mm
extern “C”{
float ReturnFloat()
{ return 10.5; }
}
• C# Dll Import

using System.Runtime.InteropServices;
[DllImport("__Internal")]
public static extern float ReturnFloat();
Android Plugins
• Jave Class
public class PlugInBridge{
public static float ReturnFloat()
{ return 10.5f; }
}
• C#

AndroidJNI.AttachCurrentThread();
AndroidJavaClass androidClass = new AndroidJavaClass
("com.example.unityplugin.PlugInBridge");
Debug.Log(androidClass.CallStatic< float >(“ReturnFloat"));
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="com.example.unityplugin.FTUnityPlayerActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


More Related Content

PDF
Unity3D Plugins Development Guide
PPTX
Avoid loss of hair while coding Unity3D plugins for mobile
ODP
Developing apps with Kivy
PPTX
Kivy report
ODP
Kivy - Python UI Library for Any Platform
PDF
Standalone Android Apps in Python
PDF
Couverture de code
Unity3D Plugins Development Guide
Avoid loss of hair while coding Unity3D plugins for mobile
Developing apps with Kivy
Kivy report
Kivy - Python UI Library for Any Platform
Standalone Android Apps in Python
Couverture de code

What's hot (20)

PDF
Flutter tutorial for Beginner Step by Step
PPTX
NDK Introduction
PPTX
Android ndk
PDF
Using the Android Native Development Kit (NDK)
PDF
Using the Android Native Development Kit (NDK)
PDF
#Code2Create:: Introduction to App Development in Flutter with Dart
PDF
Android Platform Debugging and Development
PDF
Introduction to the Android NDK
PDF
Android Platform Debugging and Development
PDF
Android Platform Debugging and Development
PDF
Embedded Android Workshop with Marshmallow
PDF
Android ndk: Entering the native world
PDF
Android Platform Debugging and Development
PDF
Android NDK and the x86 Platform
PDF
Embedded Android Workshop
PDF
Android things introduction - Development for IoT
PPTX
PDF
Android Platform Debugging and Development
PDF
Alberto Mancini - A few benchmark on Android
PDF
Developing Android Platform Tools
Flutter tutorial for Beginner Step by Step
NDK Introduction
Android ndk
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
#Code2Create:: Introduction to App Development in Flutter with Dart
Android Platform Debugging and Development
Introduction to the Android NDK
Android Platform Debugging and Development
Android Platform Debugging and Development
Embedded Android Workshop with Marshmallow
Android ndk: Entering the native world
Android Platform Debugging and Development
Android NDK and the x86 Platform
Embedded Android Workshop
Android things introduction - Development for IoT
Android Platform Debugging and Development
Alberto Mancini - A few benchmark on Android
Developing Android Platform Tools
Ad

Viewers also liked (20)

PDF
Photon For Unity
PDF
Unity5.3をさわってみた
PDF
Unity In App Purchase (IAP)の使い方
PDF
Unity5.3の機能まとめ
PDF
C mo-ganarse-la-vida-escribiendo-orientaciones-para-desarrollar-la-escritura-...
PPT
Roma solo fotos
PDF
Boletín IV enero 2016
PPS
Semantický web a Drupal
PPTX
Chrome-eject がこの先生きのこるには
PPT
SSBs Erling Holmøy_Norge eldes: Langsiktig økonomisk bærekraft 28.01.14
PPTX
Roxana Ivan - Buget mic pentru evenimente mari (Impact Hub Bucharest, 2014.02...
PPSX
Tesla Croatia
PDF
Doing Terrifying Things - Nati Cohen, Similarweb - DevOpsDays Tel Aviv 2016
PDF
Shepherd Elementary School Community Meeting Flyer
DOC
Madagascar analysis
DOCX
Philomena Detailed CV
PPTX
Marcelo acosta ac
PDF
חשבון נפש: מצב לימודי המתמטיקה בישראל - 2014
PPTX
Tudatos márkaépítés
Photon For Unity
Unity5.3をさわってみた
Unity In App Purchase (IAP)の使い方
Unity5.3の機能まとめ
C mo-ganarse-la-vida-escribiendo-orientaciones-para-desarrollar-la-escritura-...
Roma solo fotos
Boletín IV enero 2016
Semantický web a Drupal
Chrome-eject がこの先生きのこるには
SSBs Erling Holmøy_Norge eldes: Langsiktig økonomisk bærekraft 28.01.14
Roxana Ivan - Buget mic pentru evenimente mari (Impact Hub Bucharest, 2014.02...
Tesla Croatia
Doing Terrifying Things - Nati Cohen, Similarweb - DevOpsDays Tel Aviv 2016
Shepherd Elementary School Community Meeting Flyer
Madagascar analysis
Philomena Detailed CV
Marcelo acosta ac
חשבון נפש: מצב לימודי המתמטיקה בישראל - 2014
Tudatos márkaépítés
Ad

Similar to Plugin For Unity (20)

PPTX
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
PPT
Csharp dot net
PDF
Developing On the IntelliJ Platform
PDF
Typhoon Managed Execution Toolkit
PPT
CFInterop
PPTX
Adding Love to an API (or How to Expose C++ in Unity)
PPTX
Xamarin - Beyond the Basics
PPTX
Program Verification / Automated Theorem Proving
PPT
MSMDC_CLI363
PPTX
Compilation Of C/C++ program in Android
PPTX
Introduction to MonoTouch
PDF
Debot android debugging library
PDF
iOS and Android Development with Unity3D
PPTX
Radu vunvulea building and testing windows 8 metro style applications using ...
PPTX
C# Application lifecycle
PPT
Android class provider in mumbai
PPTX
C++ in windows phone apps
PPTX
iOS,From Development to Distribution
PDF
Intro to .NET and Core C#
PDF
C# everywhere
SharePoint Saturday Belgium 2014 - Production debugging of SharePoint applica...
Csharp dot net
Developing On the IntelliJ Platform
Typhoon Managed Execution Toolkit
CFInterop
Adding Love to an API (or How to Expose C++ in Unity)
Xamarin - Beyond the Basics
Program Verification / Automated Theorem Proving
MSMDC_CLI363
Compilation Of C/C++ program in Android
Introduction to MonoTouch
Debot android debugging library
iOS and Android Development with Unity3D
Radu vunvulea building and testing windows 8 metro style applications using ...
C# Application lifecycle
Android class provider in mumbai
C++ in windows phone apps
iOS,From Development to Distribution
Intro to .NET and Core C#
C# everywhere

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PDF
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
sap open course for s4hana steps from ECC to s4
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Chapter 3 Spatial Domain Image Processing.pdf

Plugin For Unity

  • 2. What is Plugin? • 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. Plugins for Different Device • iOS #if UNITY_IOS #else
 #endif if (Application.platform == RuntimePlatform.IPhonePlayer) • Android #if UNITY_ANDROID #else
 #endif if (Application.platform == RuntimePlatform.Android)
  • 5. iOS Plugins • C/C++ Native Functions in xxx.mm extern “C”{ float ReturnFloat() { return 10.5; } } • C# Dll Import
 using System.Runtime.InteropServices; [DllImport("__Internal")] public static extern float ReturnFloat();
  • 6. iOS Plugins • C/C++ Native Functions in xxx.h void UnitySendMessage(const char* obj, const char* method, const char* msg); • C/C++ Native Functions in xxx.mm extern “C”{ void UnityMessage(char* obj, char* function, char* message){ UnitySendMessage(obj, function, message);} } • C# Dll Import
 using System.Runtime.InteropServices; [DllImport("__Internal")] public static extern float UnityMessage(string obj, string function, string message);
  • 7. Android Plugins • C/C++ Native Functions in xxx.mm extern “C”{ float ReturnFloat() { return 10.5; } } • C# Dll Import
 using System.Runtime.InteropServices; [DllImport("__Internal")] public static extern float ReturnFloat();
  • 8. Android Plugins • Jave Class public class PlugInBridge{ public static float ReturnFloat() { return 10.5f; } } • C#
 AndroidJNI.AttachCurrentThread(); AndroidJavaClass androidClass = new AndroidJavaClass ("com.example.unityplugin.PlugInBridge"); Debug.Log(androidClass.CallStatic< float >(“ReturnFloat"));
  • 9. 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); } }
  • 10. Android Plugins • Modify your Manifest.xml Automatically <activity android:name="com.example.unityplugin.FTUnityPlayerActivity" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>