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.

Erstellen von IOS-Plugins

Auf dieser Seite wird erklärt, was iOS-Plugins für Sie tun können, wie Sie ein vorhandenes Plugin verwenden und wie Sie ein neues programmieren können.

iOS Plugins erlauben die Nutzung von Drittanbieterbibliotheken, sowie iOS spezifische Features wie In-App Einkäufe, GameCenter-Integration, ARKit Unterstützung und mehr.

Laden und Verwenden eines vorhandenen Plugins

Ein iOS-Plugin benötigt eine .gdip-Konfigurationsdatei, eine Binärdatei, die entweder eine statische .a-Bibliothek oder eine .xcframework mit statischen .a-Bibliotheken sein kann, und möglicherweise weitere Abhängigkeiten. Um sie zu benutzen, müssen Sie:

  1. Die Dateien des Plugins in das Verzeichnis res://ios/plugins Ihres Godot-Projekts kopieren. Sie können die Dateien auch in einem Unterverzeichnis gruppieren, z. B. res://ios/plugins/my_plugin.

  2. Der Godot-Editor erkennt und importiert automatisch die .gdip-Dateien in res://ios/plugins und seinen Unterverzeichnissen.

  3. Sie können erkannte Plugins finden und aktivieren, indem Sie zu Projekt -> Exportieren... -> iOS gehen und auf dem Optionen-Tab zum Abschnitt Plugins scrollen.

../../../_images/ios_export_preset_plugins_section.png

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())

Bemerkung

Die Dateien des Plugins müssen sich im Verzeichnis res://ios/plugins/ oder einem Unterverzeichnis befinden, da der Godot-Editor sie sonst nicht automatisch erkennt.

Erstellen eines iOS-Plugins

Im Kern ist ein Godot-iOS-Plugin eine iOS-Bibliothek (.a-Archivdatei oder .xcframework mit statischen Bibliotheken) mit den folgenden Anforderungen:

  • Die Bibliothek muss eine Abhängigkeit von den Headern der Godot-Engine haben.

  • Die Bibliothek muss eine .gdip-Konfigurationsdatei enthalten.

Ein iOS-Plugin kann die gleiche Funktionalität wie ein Godot-Modul haben, bietet aber mehr Flexibilität und erfordert keinen Rebuild der Engine.

Hier sind die Schritte, um mit der Entwicklung eines Plugins zu beginnen. Wir empfehlen die Verwendung der Entwicklungsumgebung Xcode.

Siehe auch

Die Godot iOS Plugins.

Die Godot iOS Plugin-Vorlage bietet Ihnen alle notwendigen Grundlagen, um Ihr iOS-Plugin zu starten.

Um ein iOS-Plugin zu erstellen:

  1. Erstellen Sie eine statische Objective-C-Bibliothek für Ihr Plugin in Xcode.

  2. Fügen Sie die Godot-Engine-Header-Dateien als Abhängigkeit für Ihre Plugin-Bibliothek in HEADER_SEARCH_PATHS hinzu. Sie finden diese Einstellung auf der Registerkarte Build Settings:

    • Laden Sie den Quellcode der Godot-Engine von der Godot GitHub-Seite herunter.

    • Starten Sie SCons, um Header zu erzeugen. Sie können den Prozess lernen, indem Sie Kompilieren für iOS lesen. Sie müssen nicht warten, bis die Kompilierung abgeschlossen ist, um weiterzumachen, da die Header generiert werden, bevor die Engine mit der Kompilierung beginnt.

    • Sie sollten die gleichen Header-Dateien für iOS-Plugins und für die iOS-Exportvorlage verwenden.

  3. Geben Sie auf dem Build Settings-Tab unter OTHER_CFLAGS die Kompilierungsflags für Ihre statische Bibliothek an. Die wichtigsten sind -fcxx-modules, -fmodules, und -DDEBUG, wenn Sie Debug-Unterstützung benötigen. Andere Flags sollten die gleichen sein, die Sie zum Kompilieren von Godot verwenden. Zum Beispiel:

-DPTRCALL_ENABLED -DDEBUG_ENABLED -DDEBUG_MEMORY_ALLOC -DDISABLE_FORCED_INLINE -DTYPED_METHOD_BIND
  1. Fügen Sie die erforderliche Logik für Ihr Plugin hinzu und erstellen Sie Ihre Bibliothek, um eine .a-Datei zu erzeugen. Wahrscheinlich müssen Sie .a Dateien für das debug und release-Target erstellen. Abhängig von Ihren Bedürfnissen, wählen Sie eine oder beide. Wenn Sie sowohl Debug- als auch Release-.a Dateien benötigen, sollte ihr Name folgendem Muster entsprechen: [PluginName].[TargetType].a. Sie können die statische Bibliothek auch mit Ihrer SCons-Konfiguration erstellen.

  2. Das iOS-Plugin-System unterstützt auch .xcframework-Dateien. Um eine solche zu erzeugen, können Sie einen Befehl wie den folgenden verwenden:

xcodebuild -create-xcframework -library [DeviceLibrary].a -library [SimulatorLibrary].a -output [PluginName].xcframework
  1. Erstellen Sie eine Godot iOS Plugin-Konfigurationsdatei, damit das System Ihr Plugin erkennen und laden kann:

    • Die Erweiterung der Konfigurationsdatei muss gdip lauten (z.B.: 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 (a or xcframework) file.

    • The filepath can be relative (e.g.: MyPlugin.a, MyPlugin.xcframework) in which case it's relative to the directory where the gdip file is located.

    • The filepath can be absolute: res://some_path/MyPlugin.a or res://some_path/MyPlugin.xcframework.

    • In case you need multitarget library usage, the filename should be MyPlugin.a and .a files should be named as MyPlugin.release.a and MyPlugin.debug.a.

    • In case you use multitarget xcframework libraries, their filename in the configuration should be MyPlugin.xcframework. The .xcframework files should be named as MyPlugin.release.xcframework and MyPlugin.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.plist file.

    • Each line should follow pattern: KeyName:KeyType=KeyValue

    • Supported values for KeyType are string, integer, boolean, raw, string_input

    • If no type is used (e.g.: KeyName="KeyValue") string type will be used.

    • If raw type is used value for corresponding key will be stored in Info.plist as is.

    • If string_input type is used you will be able to modify value in Export window.