private static void ManuallyGenerateManifest() { string jdkPath = EM_EditorUtil.GetJdkPath(); if (string.IsNullOrEmpty(jdkPath)) { EM_EditorUtil.Alert("Missing JDK Path", "A JDK path needs to be specified for the generation of Easy Mobile's AndroidManifest.xml as well as for the Android build. " + "Go to Preferences > External Tools > JDK to set it."); } else { EM_AndroidManifestBuilder.GenerateManifest(jdkPath, true, true); EM_EditorUtil.Alert("Android Manifest Updated", "Easy Mobile's Android manifest (Assets/Plugins/Android/EasyMobile/AndroidManifest.xml) has been updated!"); } }
// Generate a static class containing constants of IAP product names. void GenerateIAPConstants() { // First create a hashtable containing all the names to be stored as constants. SerializedProperty productsProp = IAPProperties.products.property; // First check if there're duplicate names. string duplicateName = EM_EditorUtil.FindDuplicateFieldInArrayProperty(productsProp, IAPProduct_NameProperty); if (!string.IsNullOrEmpty(duplicateName)) { EM_EditorUtil.Alert("Error: Duplicate Names", "Found duplicate product name of \"" + duplicateName + "\"."); return; } // Proceed with adding resource keys. Hashtable resourceKeys = new Hashtable(); // Add the product names. for (int i = 0; i < productsProp.arraySize; i++) { SerializedProperty element = productsProp.GetArrayElementAtIndex(i); string name = element.FindPropertyRelative(IAPProduct_NameProperty).stringValue; // Ignore all items with an empty name. if (!string.IsNullOrEmpty(name)) { string key = "Product_" + name; resourceKeys.Add(key, name); } } if (resourceKeys.Count > 0) { // Now build the class. EM_EditorUtil.GenerateConstantsClass( EM_Constants.GeneratedFolder, EM_Constants.RootNameSpace + "." + EM_Constants.IAPConstantsClassName, resourceKeys, true ); } else { EM_EditorUtil.Alert("Constants Class Generation", "Please fill in required information for all products."); } }
private static GameObject CreateMainPrefab(bool showAlert = false) { // Stop if the prefab is already created. string prefabPath = EM_Constants.MainPrefabPath; GameObject existingPrefab = EM_EditorUtil.GetMainPrefab(); if (existingPrefab != null) { if (showAlert) { EM_EditorUtil.Alert("Prefab Exists", "EasyMobile.prefab already exists at " + prefabPath); } return(existingPrefab); } // Make sure the containing folder exists. FileIO.EnsureFolderExists(EM_Constants.MainPrefabFolder); // Create a temporary gameObject and then create the prefab from it. GameObject tmpObj = new GameObject(EM_Constants.MainPrefabName); // Add PrefabManager component. tmpObj.AddComponent <EM_PrefabManager>(); // Generate the prefab from the temporary game object. GameObject prefabObj = PrefabUtility.CreatePrefab(prefabPath, tmpObj); GameObject.DestroyImmediate(tmpObj); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); if (showAlert) { EM_EditorUtil.Alert("Prefab Created", "EasyMobile.prefab is created at " + prefabPath); } else { Debug.Log("EasyMobile.prefab is created at " + prefabPath); } return(prefabObj); }
public static void PreBuildProcessing(BuildTarget target, string path) { // Search through all enabled scenes in the BuildSettings to find the EasyMobile prefab instance. // Warn the user if none was found. GameObject prefab = EM_EditorUtil.GetMainPrefab(); if (prefab != null) { string[] enabledScenePaths = EM_EditorUtil.GetScenePathInBuildSettings(true); if (!EM_EditorUtil.IsPrefabInstanceFoundInScenes(prefab, enabledScenePaths)) { string title = "EasyMobile Instance Missing"; string msg = "No root-level instance of the EasyMobile prefab was found in the enabled scene(s). " + "Please add one to the first scene of your game for the plugin to function properly."; #if !UNITY_CLOUD_BUILD EM_EditorUtil.Alert(title, msg); #else Debug.LogWarning(msg); #endif } } }
string[] BuildListOfNotificationCategoryGroupsName(IDictionary <string, string> categoryGroupsDict) { if (categoryGroupsDict == null) { return new string[] { EM_Constants.NoneSymbol } } ; var list = new string[categoryGroupsDict.Count + 1]; // Add "None" as first item. list[0] = EM_Constants.NoneSymbol; // Copy keys from the dict. categoryGroupsDict.Keys.CopyTo(list, 1); return(list); } string GetNotificationCategoryNameFromId(IDictionary <string, string> dict, string id) { string name = string.Empty; if (string.IsNullOrEmpty(id)) { name = EM_Constants.NoneSymbol; } else if (dict != null) { name = EM_EditorUtil.GetKeyForValue(dict, id); } return(name); } // Generate a static class containing constants of category IDs. void GenerateNotificationConstants() { // First create a hashtable containing all the names to be stored as constants. SerializedProperty userCategoriesProp = NotificationProperties.userCategories.property; // First check if there're duplicate IDs. string duplicateID = EM_EditorUtil.FindDuplicateFieldInArrayProperty(userCategoriesProp, NotificationCategory_Id); if (!string.IsNullOrEmpty(duplicateID)) { EM_EditorUtil.Alert("Error: Duplicate IDs", "Found duplicate category ID of \"" + duplicateID + "\"."); return; } // Proceed with adding resource keys. Hashtable resourceKeys = new Hashtable(); // Add the category IDs. for (int i = 0; i < userCategoriesProp.arraySize; i++) { SerializedProperty element = userCategoriesProp.GetArrayElementAtIndex(i); string id = element.FindPropertyRelative(NotificationCategory_Id).stringValue; // Ignore all items with an empty ID. if (!string.IsNullOrEmpty(id)) { string key = "UserCategory_" + id; resourceKeys.Add(key, id); } } if (resourceKeys.Count > 0) { // Now build the class. EM_EditorUtil.GenerateConstantsClass( EM_Constants.GeneratedFolder, EM_Constants.RootNameSpace + "." + EM_Constants.NotificationsConstantsClassName, resourceKeys, true ); } else { EM_EditorUtil.Alert("Constants Class Generation", "No user category has been defined or category ID is missing."); } } //---------------------------------------------------------------- // Importing Android Notification Res Folder //---------------------------------------------------------------- void ImportAndroidNotificationResFolder() { string selectedFolder = EditorUtility.OpenFolderPanel(null, notificationSelectedAndroidResFolder, null); if (!string.IsNullOrEmpty(selectedFolder)) { // Some folder was selected. notificationSelectedAndroidResFolder = selectedFolder; // Build Android library from the selected folder. if (EM_EditorUtil.DisplayDialog( "Building Android Resources", "Please make sure the selected folder is correct before proceeding.\n" + notificationSelectedAndroidResFolder, "Go Ahead", "Cancel")) { // Prepare the lib config. var config = new EM_AndroidLibBuilder.AndroidLibConfig(); config.packageName = EM_Constants.AndroidNativeNotificationPackageName; config.targetLibFolderName = EM_Constants.NotificationAndroidResFolderName; config.targetContentFolderName = "res"; EM_AndroidLibBuilder.BuildAndroidLibFromFolder( notificationSelectedAndroidResFolder, config, OnAndroidNotificationResBuildProgress, OnAndroidNotificationResBuildNewStep, OnAndroidNotificationResBuildComplete ); } } } void OnAndroidNotificationResBuildProgress(float progress) { // Display progress bar. EditorUtility.DisplayProgressBar( "Generating Android Notification Resources", notificationCreateAndroidResCurrentStep, progress ); } void OnAndroidNotificationResBuildNewStep(string step) { notificationCreateAndroidResCurrentStep = step; } void OnAndroidNotificationResBuildComplete() { EditorUtility.ClearProgressBar(); EM_EditorUtil.Alert( "Android Resources Imported", "Android notification resources have been imported successfully!" ); } }
// Generate a static class containing constants of leaderboard and achievement names. void GenerateGameServiceConstants() { // First create a hashtable containing all the names to be stored as constants. SerializedProperty ldbProp = GameServiceProperties.leaderboards.property; SerializedProperty acmProp = GameServiceProperties.achievements.property; // First check if there're duplicate names. string duplicateLdbName = EM_EditorUtil.FindDuplicateFieldInArrayProperty(ldbProp, GameServiceItem_NameProperty); if (!string.IsNullOrEmpty(duplicateLdbName)) { EM_EditorUtil.Alert("Error: Duplicate Names", "Found duplicate leaderboard name of \"" + duplicateLdbName + "\"."); return; } string duplicateAcmName = EM_EditorUtil.FindDuplicateFieldInArrayProperty(acmProp, GameServiceItem_NameProperty); if (!string.IsNullOrEmpty(duplicateAcmName)) { EM_EditorUtil.Alert("Error: Duplicate Names", "Found duplicate achievement name of \"" + duplicateAcmName + "\"."); return; } // Proceed with adding resource keys. Hashtable resourceKeys = new Hashtable(); // Add the leaderboard names. for (int i = 0; i < ldbProp.arraySize; i++) { SerializedProperty element = ldbProp.GetArrayElementAtIndex(i); string name = element.FindPropertyRelative(GameServiceItem_NameProperty).stringValue; // Ignore all items with an empty name. if (!string.IsNullOrEmpty(name)) { string key = "Leaderboard_" + name; resourceKeys.Add(key, name); } } // Add the achievement names. for (int j = 0; j < acmProp.arraySize; j++) { SerializedProperty element = acmProp.GetArrayElementAtIndex(j); string name = element.FindPropertyRelative(GameServiceItem_NameProperty).stringValue; // Ignore all items with an empty name. if (!string.IsNullOrEmpty(name)) { string key = "Achievement_" + name; resourceKeys.Add(key, name); } } if (resourceKeys.Count > 0) { // Now build the class. EM_EditorUtil.GenerateConstantsClass( EM_Constants.GeneratedFolder, EM_Constants.RootNameSpace + "." + EM_Constants.GameServicesConstantsClassName, resourceKeys, true ); } else { EM_EditorUtil.Alert("Constants Class Generation", "Please fill in required information for all leaderboards and achievements."); } }