void SetupAndroidGPGSButtonHandler()
        {
            string webClientId        = sGPGSWebClientId;                                            // Web ClientId, not required for Games Services.
            string folder             = EM_Constants.GeneratedFolder;                                // Folder to contain the generated id constant class.
            string className          = EM_Constants.AndroidGPGSConstantClassName;                   // Name of the generated id constant class.
            string resourceXmlData    = GameServiceProperties.gpgsXmlResources.property.stringValue; // The xml resources inputted.
            string nearbySvcId        = null;                                                        // Nearby Connection Id, not supported by us.
            bool   requiresGooglePlus = false;                                                       // Not required Google+ API.

            try
            {
                if (GPGSUtil.LooksLikeValidPackageName(className))
                {
                    SetupAndroidGPGS(webClientId, folder, className, resourceXmlData, nearbySvcId, requiresGooglePlus);
                }
            }
            catch (System.Exception e)
            {
                GPGSUtil.Alert(
                    GPGSStrings.Error,
                    "Invalid classname: " + e.Message);
            }
        }
    private static bool CheckAndWarnAboutGmsCoreVersion(string libProjAMFile)
    {
        string manifestContents = GPGSUtil.ReadFile(libProjAMFile);

        string[] fields = manifestContents.Split('\"');
        int      i;
        long     vercode = 0;

        for (i = 0; i < fields.Length; i++)
        {
            // check for the newer version attribute
            if (fields[i].Contains("com.google.android.gms.version"))
            {
                // newer SDK, so it is OK
                return(true);
            }
            else if (fields[i].Contains("android:versionCode") && i + 1 < fields.Length)
            {
                vercode = System.Convert.ToInt64(fields[i + 1]);
            }
        }
        if (vercode == 0)
        {
            return(EditorUtility.DisplayDialog(GPGSStrings.Warning, string.Format(
                                                   GPGSStrings.AndroidSetup.LibProjVerNotFound,
                                                   GooglePlayGames.PluginVersion.MinGmsCoreVersionCode),
                                               GPGSStrings.Ok, GPGSStrings.Cancel));
        }
        else if (vercode < GooglePlayGames.PluginVersion.MinGmsCoreVersionCode)
        {
            return(EditorUtility.DisplayDialog(GPGSStrings.Warning, string.Format(
                                                   GPGSStrings.AndroidSetup.LibProjVerTooOld, vercode,
                                                   GooglePlayGames.PluginVersion.MinGmsCoreVersionCode),
                                               GPGSStrings.Ok, GPGSStrings.Cancel));
        }
        return(true);
    }
Ejemplo n.º 3
0
    void DoSetup()
    {
        if (!GPGSUtil.LooksLikeValidClientId(mClientId))
        {
            GPGSUtil.Alert(GPGSStrings.IOSSetup.ClientIdError);
            return;
        }
        if (!GPGSUtil.LooksLikeValidBundleId(mBundleId))
        {
            GPGSUtil.Alert(GPGSStrings.IOSSetup.BundleIdError);
            return;
        }

        Save();
        GPGSUtil.UpdateGameInfo();

        FillInAppData(GameInfoPath, GameInfoPath);

        // Finished!
        GPGSProjectSettings.Instance.Set("ios.SetupDone", true);
        GPGSProjectSettings.Instance.Save();
        AssetDatabase.Refresh();
        GPGSUtil.Alert(GPGSStrings.Success, GPGSStrings.IOSSetup.SetupComplete);
    }
Ejemplo n.º 4
0
        // Replicate the "DoSetup" method of the GPGSAndroidSetupUI class.
        void SetupAndroidGPGS(string webClientId, string folder, string className, string resourceXmlData, string nearbySvcId, bool requiresGooglePlus)
        {
            // Create the folder to store the generated cs file if it doesn't exist.
            SgLib.Editor.FileIO.EnsureFolderExists(folder);

            if (GPGSAndroidSetupUI.PerformSetup(webClientId, folder, className, resourceXmlData, nearbySvcId, requiresGooglePlus))
            {
                GPGSAndroidSetupUI.CheckBundleId();

                EditorUtility.DisplayDialog(
                    GPGSStrings.Success,
                    GPGSStrings.AndroidSetup.SetupComplete,
                    GPGSStrings.Ok);

                GPGSProjectSettings.Instance.Set(GPGSUtil.ANDROIDSETUPDONEKEY, true);
            }
            else
            {
                GPGSUtil.Alert(
                    GPGSStrings.Error,
                    "Invalid or missing XML resource data.  Make sure the data is" +
                    " valid and contains the app_id element");
            }
        }
    void DoSetup()
    {
        /*
         * THE FOLLOWING HAS BEEN COMMENTED OUT to not reload the Google Play Game Services library
         * to prevent errors when Google update its library.
         *
         * string sdkPath = GPGSUtil.GetAndroidSdkPath();
         * string libProjPath = sdkPath +
         * GPGSUtil.FixSlashes("/extras/google/google_play_services/libproject/google-play-services_lib");
         * string libProjAM = libProjPath + GPGSUtil.FixSlashes("/AndroidManifest.xml");
         * string libProjDestDir = GPGSUtil.FixSlashes("Assets/Plugins/Android/google-play-services_lib");
         */

        string projAM = GPGSUtil.FixSlashes("Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

        GPGSProjectSettings.Instance.Set("proj.AppId", mAppId);
        GPGSProjectSettings.Instance.Save();

        // check for valid app id
        if (!GPGSUtil.LooksLikeValidAppId(mAppId))
        {
            GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
            return;
        }

        // check that Android SDK is there
        if (!GPGSUtil.HasAndroidSdk())
        {
            Debug.LogError("Android SDK not found.");
            EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SdkNotFound,
                                        GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok);
            return;
        }

        /*
         *
         * // check that the Google Play Services lib project is there
         * if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM)) {
         * Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
         * EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
         * GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
         * return;
         * }
         *
         * // check lib project version
         * if (!CheckAndWarnAboutGmsCoreVersion(libProjAM)) {
         * return;
         * }
         *
         * // create needed directories
         * EnsureDirExists("Assets/Plugins");
         * EnsureDirExists("Assets/Plugins/Android");
         *
         * // clear out the destination library project
         * DeleteDirIfExists(libProjDestDir);
         *
         * // Copy Google Play Services library
         * FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);
         *
         */

        // Generate AndroidManifest.xml
        string manifestBody = GPGSUtil.ReadTextFile("template-AndroidManifest");

        manifestBody = manifestBody.Replace("___APP_ID___", mAppId);
        GPGSUtil.WriteFile(projAM, manifestBody);

        // refresh assets, and we're done
        AssetDatabase.Refresh();
        GPGSProjectSettings.Instance.Set("android.SetupDone", true);
        GPGSProjectSettings.Instance.Save();
        EditorUtility.DisplayDialog(GPGSStrings.Success,
                                    GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok);
    }
Ejemplo n.º 6
0
    void DoSetup()
    {
        string sdkPath     = GPGSUtil.GetAndroidSdkPath();
        string libProjPath = sdkPath +
                             GPGSUtil.FixSlashes("/extras/google/google_play_services/libproject/google-play-services_lib");
        string libProjAM      = libProjPath + GPGSUtil.FixSlashes("/AndroidManifest.xml");
        string libProjDestDir = GPGSUtil.FixSlashes("Assets/Plugins/Android/google-play-services_lib");
        string projAM         = GPGSUtil.FixSlashes("Assets/Plugins/Android/MainLibProj/AndroidManifest.xml");

        GPGSProjectSettings.Instance.Set("proj.AppId", mAppId);
        GPGSProjectSettings.Instance.Save();

        // check for valid app id
        if (!GPGSUtil.LooksLikeValidAppId(mAppId))
        {
            GPGSUtil.Alert(GPGSStrings.Setup.AppIdError);
            return;
        }

        // check that Android SDK is there
        if (!GPGSUtil.HasAndroidSdk())
        {
            Debug.LogError("Android SDK not found.");
            EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SdkNotFound,
                                        GPGSStrings.AndroidSetup.SdkNotFoundBlurb, GPGSStrings.Ok);
            return;
        }

        // check that the Google Play Services lib project is there
        if (!System.IO.Directory.Exists(libProjPath) || !System.IO.File.Exists(libProjAM))
        {
            Debug.LogError("Google Play Services lib project not found at: " + libProjPath);
            EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.LibProjNotFound,
                                        GPGSStrings.AndroidSetup.LibProjNotFoundBlurb, GPGSStrings.Ok);
            return;
        }

        string supportJarPath = sdkPath +
                                GPGSUtil.FixSlashes(
            "/extras/android/support/v4/android-support-v4.jar");
        string supportJarDest =
            GPGSUtil.FixSlashes("Assets/Plugins/Android/android-support-v4.jar");

        if (!System.IO.File.Exists(supportJarPath))
        {
            Debug.LogError("Android support library v4 not found at: " + supportJarPath);
            EditorUtility.DisplayDialog(GPGSStrings.AndroidSetup.SupportJarNotFound,
                                        GPGSStrings.AndroidSetup.SupportJarNotFoundBlurb, GPGSStrings.Ok);
            return;
        }



        // check lib project version
        if (!CheckAndWarnAboutGmsCoreVersion(libProjAM))
        {
            return;
        }

        // create needed directories
        EnsureDirExists("Assets/Plugins");
        EnsureDirExists("Assets/Plugins/Android");

        // clear out the destination library project
        DeleteDirIfExists(libProjDestDir);

        // Clear out any stale version of the support jar.
        System.IO.File.Delete(supportJarDest);


        // Copy Google Play Services library
        FileUtil.CopyFileOrDirectory(libProjPath, libProjDestDir);

        // Copy Android Support Library
        FileUtil.CopyFileOrDirectory(supportJarPath, supportJarDest);

        // Generate AndroidManifest.xml
        string manifestBody = GPGSUtil.ReadTextFile("template-AndroidManifest");

        manifestBody = manifestBody.Replace("___APP_ID___", mAppId);
        GPGSUtil.WriteFile(projAM, manifestBody);

        // refresh assets, and we're done
        AssetDatabase.Refresh();
        GPGSProjectSettings.Instance.Set("android.SetupDone", true);
        GPGSProjectSettings.Instance.Save();
        EditorUtility.DisplayDialog(GPGSStrings.Success,
                                    GPGSStrings.AndroidSetup.SetupComplete, GPGSStrings.Ok);
    }
Ejemplo n.º 7
0
        void GameServiceModuleGUI()
        {
            EditorGUILayout.BeginVertical(EM_GUIStyleManager.GetCustomStyle("Module Box"));

            EditorGUI.BeginChangeCheck();

            isGameServiceModuleEnable.boolValue = EM_EditorGUI.ModuleToggle(isGameServiceModuleEnable.boolValue, GameServiceModuleLabel);

            // Update the main prefab according to the toggle state.
            if (EditorGUI.EndChangeCheck())
            {
                GameObject prefab = EM_EditorUtil.GetMainPrefab();

                if (!isGameServiceModuleEnable.boolValue)
                {
                    EM_Manager.DisableGameServiceModule(prefab);
                }
                else
                {
                    EM_Manager.EnableGameServiceModule(prefab);
                }
            }

            // Now draw the GUI.
            if (!isGameServiceModuleEnable.boolValue)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(GameServiceModuleIntro, MessageType.Info);
            }
            else
            {
                #if UNITY_ANDROID && !EM_GPGS
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(AndroidGPGSImportInstruction, MessageType.Error);
                EditorGUILayout.Space();
                if (GUILayout.Button("Download Google Play Games Plugin", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    EM_ExternalPluginManager.DownloadGooglePlayGamesPlugin();
                }
                #elif UNITY_ANDROID && EM_GPGS
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(AndroidGPGSAvailMsg, MessageType.Info);
                EditorGUILayout.Space();
                if (GUILayout.Button("Download Google Play Games Plugin", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    EM_ExternalPluginManager.DownloadGooglePlayGamesPlugin();
                }

                // Android Google Play Games setup
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("[ANDROID] GOOGLE PLAY GAMES SETUP", EditorStyles.boldLabel);

                // GPGPS debug log
                GameServiceProperties.gpgsDebugLog.property.boolValue = EditorGUILayout.Toggle(GameServiceProperties.gpgsDebugLog.content, GameServiceProperties.gpgsDebugLog.property.boolValue);

                // Text area to input the Android resource.
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(AndroidGPGPSSetupInstruction, MessageType.None);
                EditorGUILayout.LabelField(GameServiceProperties.androidXmlResources.content, EditorStyles.boldLabel);

                // Draw text area inside a scroll view.
                androidResourcesTextAreaScroll = GUILayout.BeginScrollView(androidResourcesTextAreaScroll, false, false, GUILayout.Height(EditorGUIUtility.singleLineHeight * 10));
                GameServiceProperties.androidXmlResources.property.stringValue = EditorGUILayout.TextArea(
                    GameServiceProperties.androidXmlResources.property.stringValue,
                    GUILayout.Height(EditorGUIUtility.singleLineHeight * 100),
                    GUILayout.ExpandHeight(true));
                EditorGUILayout.EndScrollView();

                EditorGUILayout.Space();

                // Replicate the "Setup" button within the Android GPGS setup window.
                if (GUILayout.Button("Setup Google Play Games", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    string webClientId        = null;                                                           // Web ClientId, not required for Games Services.
                    string folder             = EM_Constants.GeneratedFolder;                                   // Folder to contain the generated id constant class.
                    string className          = EM_Constants.AndroidGPGSConstantClassName;                      // Name of the generated id constant class.
                    string resourceXmlData    = GameServiceProperties.androidXmlResources.property.stringValue; // The xml resources inputted.
                    string nearbySvcId        = null;                                                           // Nearby Connection Id, not supported by us.
                    bool   requiresGooglePlus = false;                                                          // Not required Google+ API.

                    try
                    {
                        if (GPGSUtil.LooksLikeValidPackageName(className))
                        {
                            SetupAndroidGPGS(webClientId, folder, className, resourceXmlData, nearbySvcId, requiresGooglePlus);
                        }
                    }
                    catch (System.Exception e)
                    {
                        GPGSUtil.Alert(
                            GPGSStrings.Error,
                            "Invalid classname: " + e.Message);
                    }
                }
                #endif

                #if !UNITY_ANDROID || (UNITY_ANDROID && EM_GPGS)
                // Auto-init config
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("AUTO-INIT CONFIG", EditorStyles.boldLabel);
                GameServiceProperties.autoInit.property.boolValue = EditorGUILayout.Toggle(GameServiceProperties.autoInit.content, GameServiceProperties.autoInit.property.boolValue);

                EditorGUI.BeginDisabledGroup(!GameServiceProperties.autoInit.property.boolValue);
                GameServiceProperties.autoInitDelay.property.floatValue = EditorGUILayout.FloatField(GameServiceProperties.autoInitDelay.content, GameServiceProperties.autoInitDelay.property.floatValue);
                EditorGUI.EndDisabledGroup();

                GameServiceProperties.androidMaxLoginRequest.property.intValue = EditorGUILayout.IntField(GameServiceProperties.androidMaxLoginRequest.content, GameServiceProperties.androidMaxLoginRequest.property.intValue);
                if (!GameServiceProperties.autoInit.property.boolValue)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.HelpBox(GameServiceManualInitInstruction, MessageType.Info);
                }

                // Leaderboard setup.
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("LEADERBOARD SETUP", EditorStyles.boldLabel);
                DrawGameServiceItemArray("Leaderboard", GameServiceProperties.leaderboards, ref isLeadeboardsFoldout);

                // Achievement setup.
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("ACHIEVEMENT SETUP", EditorStyles.boldLabel);
                DrawGameServiceItemArray("Achievement", GameServiceProperties.achievements, ref isAchievementsFoldout);

                // Constant generation.
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("CONSTANTS CLASS GENERATION", EditorStyles.boldLabel);
                EditorGUILayout.HelpBox(GameServiceConstantGenerationIntro, MessageType.None);

                EditorGUILayout.Space();
                if (GUILayout.Button("Generate Constants Class", GUILayout.Height(EM_GUIStyleManager.buttonHeight)))
                {
                    GenerateGameServiceConstants();
                }
                #endif
            }

            EditorGUILayout.EndVertical();
        }