Plugins für iOS¶
Godot provides StoreKit, GameCenter, iCloud services and other plugins. They are using same model of asynchronous calls explained below.
ARKit und Kamerazugriff werden auch als Plugins bereitgestellt.
Zusätzlich zu dieser Dokumentation möchten Sie vielleicht auch einen Blick auf die verschiedenen Godot-Demoprojekte werfen.
Zugriff auf Plugin-Singletons¶
To access plugin functionality, you first need to check that the plugin is exported and available by calling the Engine.has_singleton() function, which returns a registered singleton.
Hier ist ein Beispiel dafür, wie Sie dies in GDScript tun können:
var in_app_store
var game_center
func _ready():
if Engine.has_singleton("InAppStore"):
in_app_store = Engine.get_singleton("InAppStore")
else:
print("iOS IAP plugin is not available on this platform.")
if Engine.has_singleton("GameCenter"):
game_center = Engine.get_singleton("GameCenter")
else:
print("iOS Game Center plugin is not available on this platform.")
Asynchrone Methoden¶
Wenn Sie eine asynchrone Operation anfordern, sieht die Methode folgendermaßen aus:
Error purchase(Variant params);
The parameter will usually be a Dictionary, with the information necessary to make the request, and the call will have two phases. First, the method will immediately return an Error value. If the Error is not 'OK', the call operation is completed, with an error probably caused locally (no internet connection, API incorrectly configured, etc). If the error value is 'OK', a response event will be produced and added to the 'pending events' queue. Example:
func on_purchase_pressed():
var result = InAppStore.purchase({ "product_id": "my_product" })
if result == OK:
animation.play("busy") # show the "waiting for response" animation
else:
show_error()
# put this on a 1 second timer or something
func check_events():
while in_app_store.get_pending_event_count() > 0:
var event = in_app_store.pop_pending_event()
if event.type == "purchase":
if event.result == "ok":
show_success(event.product_id)
else:
show_error()
Remember that when a call returns OK, the API will always produce an event through the pending_event interface, even if it's an error, or a network timeout, etc. You should be able to, for example, safely block the interface waiting for a reply from the server. If any of the APIs don't behave this way it should be treated as a bug.
Die Schnittstelle für ausstehende Ereignisse besteht aus zwei Methoden:
get_pending_event_count()
gibt die Anzahl der ausstehenden Ereignisse in der Warteschlange zurück.Variant pop_pending_event()
löscht das erste Ereignis aus der Warteschlange und gibt es zurück.
Store Kit¶
Implementiert in Godot iOS InAppStore plugin.
The Store Kit API is accessible through the InAppStore
singleton.
It is initialized automatically.
Folgende Methoden sind verfügbar und dokumentiert:
Error purchase(Variant params)
Error request_product_info(Variant params)
Error restore_purchases()
void set_auto_finish_transaction(bool enable)
void finish_transaction(String product_id)
and the pending events interface:
::
int get_pending_event_count()
Variant pop_pending_event()
purchase
¶
Purchases a product ID through the Store Kit API. You have to call finish_transaction(product_id)
once you
receive a successful response or call set_auto_finish_transaction(true)
prior to calling purchase()
.
These two methods ensure the transaction is completed.
Parameter¶
Nimmt ein Dictionary als Parameter mit zwei Feldern:
var result = in_app_store.purchase({ "product_id": "my_product" })
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "purchase",
"result": "error",
"product_id": "the product ID requested",
}
bei Erfolg:
{
"type": "purchase",
"result": "ok",
"product_id": "the product ID requested",
}
request_product_info
¶
Fordert die Produktinfo aus einer Liste von Produkt-IDs an.
Parameter¶
Takes a dictionary as a parameter, with a single product_ids
key to which a
string array of product IDs is assigned. Example:
var result = in_app_store.request_product_info({ "product_ids": ["my_product1", "my_product2"] })
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
{
"type": "product_info",
"result": "ok",
"invalid_ids": [ list of requested IDs that were invalid ],
"ids": [ list of IDs that were valid ],
"titles": [ list of valid product titles (corresponds with list of valid IDs) ],
"descriptions": [ list of valid product descriptions ] ,
"prices": [ list of valid product prices ],
"localized_prices": [ list of valid product localized prices ],
}
restore_purchases
¶
Restores previously made purchases on user's account. This will create response events for each previously purchased product ID.
Antwortereignis¶
Bei den Antwortereignissen geht es um Dictionaries mit den folgenden Feldern:
{
"type": "restore",
"result": "ok",
"product_id": "product ID of restored purchase",
}
set_auto_finish_transaction
¶
If set to true
, once a purchase is successful, your purchase will be
finalized automatically. Call this method prior to calling purchase()
.
Parameter¶
Takes a boolean as a parameter which specifies if purchases should be automatically finalized. Example:
in_app_store.set_auto_finish_transaction(true)
finish_transaction
¶
If you don't want transactions to be automatically finalized, call this method after you receive a successful purchase response.
Parameter¶
Takes a string product_id
as an argument. product_id
specifies what product to
finalize the purchase on. Example:
in_app_store.finish_transaction("my_product1")
Game Center¶
Implementiert in Godot iOS GameCenter Plugin.
The Game Center API is available through the "GameCenter" singleton. It has the following methods:
Error authenticate()
bool is_authenticated()
Error post_score(Variant score)
Error award_achievement(Variant params)
void reset_achievements()
void request_achievements()
void request_achievement_descriptions()
Error show_game_center(Variant params)
Error request_identity_verification_signature()
und die Schnittstelle für anstehende Ereignisse:
int get_pending_event_count()
Variant pop_pending_event()
authenticate
¶
Authentifiziert einen Benutzer im Game Center.
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "authentication",
"result": "error",
"error_code": the value from NSError::code,
"error_description": the value from NSError::localizedDescription,
}
bei Erfolg:
{
"type": "authentication",
"result": "ok",
"player_id": the value from GKLocalPlayer::playerID,
}
post_score
¶
Veröffentlicht eine Punktzahl auf einer Game Center-Bestenliste.
Parameter¶
Nimmt ein Dictionary als Parameter mit zwei Feldern:
score
eine Kleitkommazahlcategory
eine Zeichenfolge mit dem Kategorienamen
Beispiel:
var result = game_center.post_score({ "score": 100, "category": "my_leaderboard", })
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "post_score",
"result": "error",
"error_code": the value from NSError::code,
"error_description": the value from NSError::localizedDescription,
}
bei Erfolg:
{
"type": "post_score",
"result": "ok",
}
award_achievement
¶
Ändert den Fortschritt eines Game Center-Erfolgs.
Parameter¶
Nimmt ein Dictionary als Parameter mit 3 Feldern:
name
(Zeichenfolge) den Namen des Erfolgsprogress
(Fließkomma) der Leistungsfortschritt von 0,0 bis 100,0 (übergeben anGKAchievement::percentComplete
)show_completion_banner
(bool) whether Game Center should display an achievement banner at the top of the screen
Beispiel:
var result = award_achievement({ "name": "hard_mode_completed", "progress": 6.1 })
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "award_achievement",
"result": "error",
"error_code": the error code taken from NSError::code,
}
bei Erfolg:
{
"type": "award_achievement",
"result": "ok",
}
reset_achievements
¶
Löscht alle Game Center-Erfolge. Die Funktion benötigt keine Parameter.
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "reset_achievements",
"result": "error",
"error_code": the value from NSError::code,
}
bei Erfolg:
{
"type": "reset_achievements",
"result": "ok",
}
request_achievements
¶
Request all the Game Center achievements the player has made progress on. The function takes no parameters.
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "achievements",
"result": "error",
"error_code": the value from NSError::code,
}
bei Erfolg:
{
"type": "achievements",
"result": "ok",
"names": [ list of the name of each achievement ],
"progress": [ list of the progress made on each achievement ],
}
request_achievement_descriptions
¶
Request the descriptions of all existing Game Center achievements regardless of progress. The function takes no parameters.
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
bei Fehler:
{
"type": "achievement_descriptions",
"result": "error",
"error_code": the value from NSError::code,
}
bei Erfolg:
{
"type": "achievement_descriptions",
"result": "ok",
"names": [ list of the name of each achievement ],
"titles": [ list of the title of each achievement ],
"unachieved_descriptions": [ list of the description of each achievement when it is unachieved ],
"achieved_descriptions": [ list of the description of each achievement when it is achieved ],
"maximum_points": [ list of the points earned by completing each achievement ],
"hidden": [ list of booleans indicating whether each achievement is initially visible ],
"replayable": [ list of booleans indicating whether each achievement can be earned more than once ],
}
show_game_center
¶
Zeigt das integrierte Game Center-Overlay mit Bestenlisten, Erfolgen und Herausforderungen an.
Parameter¶
Nimmt ein Dictionary als Parameter mit zwei Feldern:
view
(string) (optional) the name of the view to present. Accepts "default", "leaderboards", "achievements", or "challenges". Defaults to "default".leaderboard_name
(string) (optional) the name of the leaderboard to present. Only used when "view" is "leaderboards" (or "default" is configured to show leaderboards). If not specified, Game Center will display the aggregate leaderboard.
Beispiele:
var result = show_game_center({ "view": "leaderboards", "leaderboard_name": "best_time_leaderboard" })
var result = show_game_center({ "view": "achievements" })
Antwortereignis¶
Das Antwortereignis ist ein Dictionary mit den folgenden Feldern:
beim beenden:
{
"type": "show_game_center",
"result": "ok",
}
Multi-Plattform Spiele¶
Wenn Sie an einem Spiel mit Unterstützung für mehrere Plattformen arbeiten, steht Ihnen nicht immer der Singleton "GameCenter" zur Verfügung (z.B. auf einem PC oder Android). Da der GDScript-Compiler die Singletons zur Kompilierungszeit nachschaut, können Sie die Singletons nicht einfach abfragen, um den Inhalt eines bedingten Blocks zu sehen und zu verwenden. Sie müssen diese auch als gültige Bezeichner (lokale Variable oder Klassenmitglied) definieren. Dies ist ein Beispiel dafür, wie Sie dies in einer Klasse umgehen können:
var GameCenter = null # define it as a class member
func post_score(score):
if GameCenter == null:
return
GameCenter.post_score({ "value": score, "category": "my_leaderboard" })
func check_events():
while GameCenter.get_pending_event_count() > 0:
# do something with events here
pass
func _ready():
# check if the singleton exists
if Globals.has_singleton("GameCenter"):
GameCenter = Globals.get_singleton("GameCenter")
# connect your timer here to the "check_events" function