Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Crear plugins de IOS
Esta página explica lo que los plugins de iOS pueden hacer por ti, cómo usar un plugin existente y los pasos para crear uno nuevo.
Los plugins de iOS te permiten utilizar bibliotecas de terceros y admitir características específicas de iOS como compras dentro de la aplicación (In-App Purchases), integración con GameCenter, soporte de ARKit y más.
Cargar y usando un plugin existente
Un plugin de iOS requiere un archivo de configuración .gdip, un archivo binario que puede ser una biblioteca estática .a o un .xcframework que contenga bibliotecas estáticas .a, y posiblemente otras dependencias. Para usarlo, debes hacer lo siguiente:
Copia los archivos del plugin al directorio
res://ios/pluginsde tu proyecto de Godot. También puedes agrupar los archivos en un subdirectorio, comores://ios/plugins/my_plugin.El editor de Godot detecta y importa automáticamente los archivos
.gdipque se encuentren dentro deres://ios/pluginsy sus subdirectorios.Puedes encontrar y activar los plugins detectados yendo a Proyecto -> Exportar... -> iOS y en la pestaña Opciones, desplázate hasta la sección de Plugins.
When a plugin is active, you can access it in your code using Engine.get_singleton():
if Engine.has_singleton("MyPlugin"):
var singleton = Engine.get_singleton("MyPlugin")
print(singleton.foo())
Nota
The plugin's files have to be in the res://ios/plugins/ directory or a subdirectory, otherwise the Godot editor will not automatically detect them.
Crear un plugin de IOS
En su núcleo, un plugin de iOS para Godot es una biblioteca de iOS (archivo de archivo .a o .xcframework que contiene bibliotecas estáticas) con los siguientes requisitos:
La biblioteca debe tener una dependencia en los encabezados del motor de Godot.
La biblioteca debe incluir un archivo de configuración
.gdip.
Un plugin de iOS puede tener la misma funcionalidad que un módulo de Godot, pero proporciona más flexibilidad y no requiere reconstruir el motor.
Aquí están los pasos para comenzar el desarrollo de un plugin. Recomendamos usar Xcode como tu entorno de desarrollo.
Ver también
The Godot iOS Plugins.
La plantilla Godot iOS plugin template te proporciona todo el código de inicio que necesitas para comenzar con tu plugin de iOS.
Para compilar un plugin para iOS:
Crea una biblioteca estática Objective-C para tu plugin dentro de Xcode.
Agrega los archivos de encabezado del motor de Godot como una dependencia para la biblioteca de tu plugin en
HEADER_SEARCH_PATHS. Puedes encontrar esta configuración dentro de la pestañaBuild Settings:Descarga el código fuente de Godot desde la página de GitHub de Godot.
Ejecuta SCons para generar los encabezados. Puedes aprender el proceso leyendo Compilar para IOS. No es necesario esperar a que termine la compilación para continuar, ya que los encabezados se generan antes de que el motor comience a compilar.
Deberías utilizar los mismos archivos de encabezado para los plugins de iOS y para la plantilla de exportación de iOS.
En la pestaña
Build Settings, especifica las banderas de compilación para tu biblioteca estática enOTHER_CFLAGS. Las más importantes son-fcxx-modules,-fmodules, y-DDEBUGsi necesitas soporte de depuración. Otras banderas deben ser las mismas que usas para compilar Godot. Por ejemplo:
-DPTRCALL_ENABLED -DDEBUG_ENABLED -DDEBUG_MEMORY_ALLOC -DDISABLE_FORCED_INLINE -DTYPED_METHOD_BIND
Agrega la lógica requerida para tu plugin y compila tu biblioteca para generar un archivo
.a. Es posible que necesites compilar tanto los archivos.ade destinodebugcomorelease. Dependiendo de tus necesidades, elige uno o ambos. Si necesitas tanto los archivos.ade depuración como los de lanzamiento, su nombre debe seguir el siguiente patrón:[NombreDelPlugin].[TipoDeObjetivo].a. También puedes compilar la biblioteca estática con tu configuración de SCons.El sistema de plugins de iOS también admite archivos
.xcframework. Para generar uno, puedes usar un comando como el siguiente:
xcodebuild -create-xcframework -library [DeviceLibrary].a -library [SimulatorLibrary].a -output [PluginName].xcframework
Crea un archivo de configuración de plugin de iOS para Godot para ayudar al sistema a detectar y cargar tu plugin:
La extensión del archivo de configuración debe ser
gdip(por ejemplo:MyPlugin.gdip).The configuration file format is as follow:
[config] name="MyPlugin" binary="MyPlugin.a" initialization="init_my_plugin" deinitialization="deinit_my_plugin" [dependencies] linked=[] embedded=[] system=["Foundation.framework"] capabilities=["arkit", "metal"] files=["data.json"] linker_flags=["-ObjC"] [plist] PlistKeyWithDefaultType="Some Info.plist key you might need" StringPlistKey:string="String value" IntegerPlistKey:integer=42 BooleanPlistKey:boolean=true RawPlistKey:raw=" <array> <string>UIInterfaceOrientationPortrait</string> </array> " StringPlistKeyToInput:string_input="Type something"
The config section and fields are required and defined as follow:
name: name of the plugin
binary: this should be the filepath of the plugin library (
aorxcframework) file.
The filepath can be relative (e.g.:
MyPlugin.a,MyPlugin.xcframework) in which case it's relative to the directory where thegdipfile is located.The filepath can be absolute:
res://some_path/MyPlugin.aorres://some_path/MyPlugin.xcframework.In case you need multitarget library usage, the filename should be
MyPlugin.aand.afiles should be named asMyPlugin.release.aandMyPlugin.debug.a.In case you use multitarget
xcframeworklibraries, their filename in the configuration should beMyPlugin.xcframework. The.xcframeworkfiles should be named asMyPlugin.release.xcframeworkandMyPlugin.debug.xcframework.
The dependencies and plist sections are optional and defined as follow:
dependencies:
linked: contains a list of iOS frameworks that the iOS application should be linked with.
embedded: contains a list of iOS frameworks or libraries that should be both linked and embedded into the resulting iOS application.
system: contains a list of iOS system frameworks that are required for plugin.
capabilities: contains a list of iOS capabilities that is required for plugin. A list of available capabilities can be found at Apple UIRequiredDeviceCapabilities documentation page.
files: contains a list of files that should be copied on export. This is useful for data files or images.
linker_flags: contains a list of linker flags to add to the Xcode project when exporting the plugin.
plist: should have keys and values that should be present in
Info.plistfile.
Each line should follow pattern:
KeyName:KeyType=KeyValueSupported values for
KeyTypearestring,integer,boolean,raw,string_inputIf no type is used (e.g.:
KeyName="KeyValue")stringtype will be used.If
rawtype is used value for corresponding key will be stored inInfo.plistas is.If
string_inputtype is used you will be able to modify value in Export window.