/// <summary>
    /// Gets the AGS syncable.
    /// </summary>
    /// <returns>
    /// The AGS syncable.
    /// </returns>
    /// <param name='method'>
    /// Method.
    /// </param>
    /// <param name='key'>
    /// Key.
    /// </param>
    /// <typeparam name='T'>
    /// The 1st type parameter.
    /// </typeparam>
    protected T GetAGSSyncable <T>(SyncableMethod method, string key)
    {
#if UNITY_ANDROID
        AndroidJavaObject jo;
        if (key != null)
        {
            jo = javaObject.Call <AndroidJavaObject>(method.ToString(), key);
        }
        else
        {
            jo = javaObject.Call <AndroidJavaObject>(method.ToString());
        }
        if (jo != null)
        {
            return((T)Activator.CreateInstance(typeof(T), new object[] { jo }));
        }
        //return null or 0 as appropriate to the data type returned
        return(default(T));
#elif UNITY_IOS
        return((T)Activator.CreateInstance(typeof(T), key, method));
#else
        //return null or 0 as appropriate to the data type returned
        return(default(T));
#endif
    }
Esempio n. 2
0
    /// <summary>
    /// gets the root game datamap
    /// </summary>
    /// <returns>Game datamap</returns>
    public static AGSGameDataMap GetGameData( )
    {
#if UNITY_ANDROID
        AndroidJavaObject jo = javaObject.Call <AndroidJavaObject>("getGameData");
        return(jo != null ? new AGSGameDataMap(new AmazonJavaWrapper(jo)) : null);
#else
        return(null);
#endif
    }
    /// <summary>
    /// Request the local player player information
    /// </summary>
    public static void RequestLocalPlayer()
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("requestLocalPlayer");
#elif UNITY_IOS
        _AmazonGameCircleRequestLocalPlayer();
#else
        if (PlayerFailedEvent != null)
        {
            PlayerFailedEvent("PLATFORM_NOT_SUPPORTED");
        }
#endif
    }
    /// <summary>
    /// updates an achievement
    /// </summary>
    /// <remarks>
    /// If a value outside of range is submitted, it is capped at 100 or 0.
    /// If submitted value is less than the stored value, the update is ignored.
    /// </remarks>
    /// <param name="achievementId">the id of the achievement to update</param>
    /// <param name="percentComplete">a float between 0.0f and 100.0f</param>
    public static void UpdateAchievementProgress(string achievementId, float progress)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("updateAchievementProgress", achievementId, progress);
#elif UNITY_IOS
        _AmazonGameCircleUpdateAchievementProgress(achievementId, progress);
#else
        if (UpdateAchievementFailedEvent != null)
        {
            UpdateAchievementFailedEvent(achievementId, "PLATFORM_NOT_SUPPORTED");
        }
#endif
    }
Esempio n. 5
0
    /// <summary>
    /// submit a score to leaderboard
    /// </summary>
    /// <remarks>
    /// SubmitScoreSuccess or SubmitScoreFailure events will be called if they are registered
    /// </remarks>
    /// <param name="leaderboardId">the id of the leaderboard for the score request</param>
    /// <param name="score">player score</param>
    public static void SubmitScore(string leaderboardId, long score)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("submitScore", leaderboardId, score);
#elif UNITY_IOS
        _AmazonGameCircleSubmitScore(leaderboardId, score);
#else
        if (SubmitScoreFailedEvent != null)
        {
            SubmitScoreFailedEvent(leaderboardId, "PLATFORM_NOT_SUPPORTED");
        }
#endif
    }
    /// <summary>
    /// show leaderboard in GameCircle overlay
    /// </summary>
    public static void ShowLeaderboardsOverlay(string leaderboardID)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObjectEx.Call("showLeaderboardOverlay", leaderboardID);
#endif
    }
#pragma warning disable 0618

    /// <summary>
    /// updates an achievement
    /// </summary>
    /// <remarks>
    /// If a value outside of range is submitted, it is capped at 100 or 0.
    /// If submitted value is less than the stored value, the update is ignored.
    /// </remarks>
    /// <param name="achievementId">the id of the achievement to update</param>
    /// <param name="percentComplete">a float between 0.0f and 100.0f</param>
    /// <param name="userData">
    /// ANDROID ONLY
    /// An optional code that will be returned in the response. Used to associate a function call to its response.
    /// A value of 0 is not recommended because 0 is the value returned when userData is not specified.
    /// </param>
    public static void UpdateAchievementProgress(string achievementId, float progress, int userData = 0)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("updateAchievementProgress", achievementId, progress, userData);
#else
        AGSUpdateAchievementResponse response = AGSUpdateAchievementResponse.GetPlatformNotSupportedResponse(achievementId, userData);
        if (UpdateAchievementFailedEvent != null)
        {
            UpdateAchievementFailedEvent(response.achievementId, response.error);
        }
        if (UpdateAchievementCompleted != null)
        {
            UpdateAchievementCompleted(response);
        }
#endif
    }
Esempio n. 8
0
#pragma warning disable 0618

    /// <summary>
    /// Request the local player player information
    /// <param name="userData">
    /// ANDROID ONLY
    /// An optional code that will be returned in the response. Used to associate a function call to its response.
    /// A value of 0 is not recommended because 0 is the value returned when userData is not specified.
    /// </param>
    /// </summary>
    public static void RequestLocalPlayer(int userData = 0)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("requestLocalPlayer", userData);
#else
        AGSRequestPlayerResponse response = AGSRequestPlayerResponse.GetPlatformNotSupportedResponse(userData);
        if (PlayerFailedEvent != null)
        {
            PlayerFailedEvent(response.error);
        }
        if (RequestLocalPlayerCompleted != null)
        {
            RequestLocalPlayerCompleted(response);
        }
#endif
    }
Esempio n. 9
0
    /// <summary>
    /// gets the root game datamap
    /// </summary>
    /// <returns>Game datamap</returns>
    public static AGSGameDataMap GetGameData( )
    {
#if UNITY_ANDROID
        AndroidJavaObject jo = javaObject.Call <AndroidJavaObject>("getGameData");
        if (jo != null)
        {
            return(new AGSGameDataMap(new AmazonJavaWrapper(jo)));
        }
        return(null);
#elif UNITY_IOS
        if (null == gameDataMapInstance)
        {
            gameDataMapInstance = new AGSGameDataMap();
        }
        return(gameDataMapInstance);
#else
        return(null);
#endif
    }
Esempio n. 10
0
    /// <summary>
    /// submit a score to leaderboard
    /// </summary>
    /// <remarks>
    /// SubmitScoreCompleted will be called if the event is registered.
    /// </remarks>
    /// <param name="leaderboardId">the id of the leaderboard for the score request</param>
    /// <param name="score">player score</param>
    /// <param name="userData">
    /// ANDROID ONLY
    /// An optional code that will be returned in the response. Used to associate a function call to its response.
    /// A value of 0 is not recommended because 0 is the value returned when userData is not specified.
    /// </param>
    /// </remarks>
    public static void SubmitScore(string leaderboardId, long score, int userData = 0)
    {
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // GameCircle only functions on device.
#elif UNITY_ANDROID
        JavaObject.Call("submitScore", leaderboardId, score, userData);
#else
        AGSSubmitScoreResponse response = AGSSubmitScoreResponse.GetPlatformNotSupportedResponse(leaderboardId, userData);
        if (SubmitScoreFailedEvent != null)
        {
            SubmitScoreFailedEvent(response.leaderboardId, response.error);
        }
        if (SubmitScoreCompleted != null)
        {
            SubmitScoreCompleted(response);
        }
#endif
    }
Esempio n. 11
0
    /// <summary>
    /// Initializes this AGSClient.  The serviceReadyEvent or the serviceNotReady event will be called
    /// upon completion
    /// </summary>
    /// <param name="supportsLeaderboards">bool indicating if this game uses leaderboards</param>
    /// <param name="supportsAchievements">bool indicating if this game uses achievements</param>
    /// <param name="supportsWhispersync">bool indicating if this game uses whispersync</param>
    public static void Init(bool supportsLeaderboards, bool supportsAchievements, bool supportsWhispersync)
    {
        AGSClient.ReinitializeOnFocus  = true;
        AGSClient.supportsAchievements = supportsAchievements;
        AGSClient.supportsLeaderboards = supportsLeaderboards;
        AGSClient.supportsWhispersync  = supportsWhispersync;
#if UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
        // fake a success in editor mode, to allow for easier testing.
        ServiceReady(string.Empty);
#elif UNITY_ANDROID
        JavaObject.Call("init", supportsLeaderboards, supportsAchievements, supportsWhispersync);
#else
        ServiceNotReady(serviceUnavailableOnPlatform);
#endif
    }