Search Unity

[HELP] Testing Social in Editor

Discussion in 'Scripting' started by Wahooney, Jan 27, 2015.

  1. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    281
    Is there an easier way to test the Social API in the Editor?

    My main problem is that then posting progress I get "Achievement ID not found" errors. When running in iOS the Achievement Descriptions are pulled from the OS, but in the editor the only descriptions are "Achievement1", "Achievement2", "Achievement3".

    I have found a workaround (below) but I would like to know if there is an easier way:
    Code (csharp):
    1. void Start ()
    2. {
    3. #if UNITY_EDITOR
    4.         Local instance = Social.Active as Local;
    5.        
    6.         List<UnityEngine.SocialPlatforms.Impl.AchievementDescription> descriptions = new List<UnityEngine.SocialPlatforms.Impl.AchievementDescription> ();
    7.        
    8.         // provide testing data for social achievements
    9.         foreach (Achievement ach in myLocalAchievements)
    10.         {
    11.             UnityEngine.SocialPlatforms.Impl.AchievementDescription achievement = new UnityEngine.SocialPlatforms.Impl.AchievementDescription (ach.Code, "", null, "", "", false, 0);
    12.             descriptions.Add (achievement);
    13.         }
    14.        
    15.         FieldInfo field = instance.GetType ().GetField ("m_AchievementDescriptions", BindingFlags.Instance | BindingFlags.NonPublic);
    16.        
    17.         field.SetValue (instance, descriptions);
    18. #endif
    19. }
    20.  
    Any suggestions would be great, if there is no built-in solution, feel free to use mine ;)

    Cheers.