Version: 2019.3
Seguimientos de pila administrados en iOS
Características actualmente no soportadas por Unity iOS.

Social API (API Social)

El API Social es el punto de acceso de Unity para características sociales, tal como:

  • Perfiles de usuario
  • Lista de amigos
  • Logros
  • Estadísticas / Clasificaciones

Proporciona una interfaz unificada para diferentes servidores sociales, como CameCenter, y está destinado a ser utilizado principalmente por los programadores en el proyecto del juego.

La API Social es una API asincrónica, y la manera típica de utilizarla es al hacer un llamado de función y registrar un callback a cuando esa función se complete. La función asincrónica puede tener efectos secundarios, tal como popular ciertas variables de estado en el API, y el callback debería contener los datos del servidor en ser procesados.

La clase Social reside en el namespace de UnityEngine por lo que siempre está disponible pero otras clases de la API Social se mantienen en sus propios namespace, UnityEngine.SocialPlatforms. Adicionalmente, las implementaciones de la API Social están en un sub-namespace, como SocialPlatforms.GameCenter.

Aquí hay un ejemplo (JavaScript) acerca de cómo uno podría utilizar la API Social:


import UnityEngine.SocialPlatforms;

function Start () {
    // Authenticate and register a ProcessAuthentication callback
    // This call needs to be made before we can proceed to other calls in the Social API
    Social.localUser.Authenticate (ProcessAuthentication);
}

// This function gets called when Authenticate completes
// Note that if the operation is successful, Social.localUser will contain data from the server. 
function ProcessAuthentication (success: boolean) {
    if (success) {
        Debug.Log ("Authenticated, checking achievements");

        // Request loaded achievements, and register a callback for processing them
        Social.LoadAchievements (ProcessLoadedAchievements);
    }
    else
        Debug.Log ("Failed to authenticate");
}

// This function gets called when the LoadAchievement call completes
function ProcessLoadedAchievements (achievements: IAchievement[]) {
    if (achievements.Length == 0)
        Debug.Log ("Error: no achievements found");
    else
        Debug.Log ("Got " + achievements.Length + " achievements");
    
    // You can also call into the functions like this
    Social.ReportProgress ("Achievement01", 100.0, function(result) {
        if (result)
            Debug.Log ("Successfully reported achievement progress");
        else
            Debug.Log ("Failed to report achievement");
    });
}


Aquí hay un ejemplo usando C#.

using UnityEngine;
using UnityEngine.SocialPlatforms;

public class SocialExample : MonoBehaviour {
    
    void Start () {
        // Authenticate and register a ProcessAuthentication callback
        // This call needs to be made before we can proceed to other calls in the Social API
        Social.localUser.Authenticate (ProcessAuthentication);
    }

    // This function gets called when Authenticate completes
    // Note that if the operation is successful, Social.localUser will contain data from the server. 
    void ProcessAuthentication (bool success) {
        if (success) {
            Debug.Log ("Authenticated, checking achievements");

            // Request loaded achievements, and register a callback for processing them
            Social.LoadAchievements (ProcessLoadedAchievements);
        }
        else
            Debug.Log ("Failed to authenticate");
    }

    // This function gets called when the LoadAchievement call completes
    void ProcessLoadedAchievements (IAchievement[] achievements) {
        if (achievements.Length == 0)
            Debug.Log ("Error: no achievements found");
        else
            Debug.Log ("Got " + achievements.Length + " achievements");
     
        // You can also call into the functions like this
        Social.ReportProgress ("Achievement01", 100.0, result => {
            if (result)
                Debug.Log ("Successfully reported achievement progress");
            else
                Debug.Log ("Failed to report achievement");
        });
    }
}


Para más información en la API Social, revise la referencia de Scripting de la API Social

Seguimientos de pila administrados en iOS
Características actualmente no soportadas por Unity iOS.