// Draw leaderboard or achievement item.
        void DrawGameServiceItem(SerializedProperty property, string label)
        {
            SerializedProperty name      = property.FindPropertyRelative(GameServiceItem_NameProperty);
            SerializedProperty iosId     = property.FindPropertyRelative(GameServiceItem_IOSIdProperty);
            SerializedProperty androidId = property.FindPropertyRelative(GameServiceItem_AndroidIdProperty);

            EditorGUILayout.BeginVertical(EM_GUIStyleManager.GetCustomStyle("Item Box"));

            EditorGUILayout.LabelField(string.IsNullOrEmpty(name.stringValue) ? "New " + label : name.stringValue, EditorStyles.boldLabel);
            name.stringValue  = EditorGUILayout.TextField("Name", name.stringValue);
            iosId.stringValue = EditorGUILayout.TextField("iOS Id", iosId.stringValue);
            // For Android Id, display a popup of Android leaderboards & achievements for the user to select
            // then assign its associated id to the property.
            EditorGUI.BeginChangeCheck();
            int currentIndex = Mathf.Max(System.Array.IndexOf(gpgsIds, EM_EditorUtil.GetKeyForValue(gpgsIdDict, androidId.stringValue)), 0);
            int newIndex     = EditorGUILayout.Popup("Android Id", currentIndex, gpgsIds);

            if (EditorGUI.EndChangeCheck())
            {
                // Position 0 is [None].
                if (newIndex == 0)
                {
                    androidId.stringValue = string.Empty;
                }
                else
                {
                    // Record the new android Id.
                    string newName = gpgsIds[newIndex];
                    androidId.stringValue = gpgsIdDict[newName];
                }
            }

            EditorGUILayout.EndVertical();
        }
        // Draw leaderboard or achievement item.
        bool DrawGameServiceItem(SerializedProperty property, string label)
        {
            SerializedProperty name      = property.FindPropertyRelative(GameServiceItem_NameProperty);
            SerializedProperty iosId     = property.FindPropertyRelative(GameServiceItem_IOSIdProperty);
            SerializedProperty androidId = property.FindPropertyRelative(GameServiceItem_AndroidIdProperty);

            EditorGUILayout.BeginVertical(EM_GUIStyleManager.GetCustomStyle("Item Box"));

            string key = property.propertyPath;

            if (!gameServiceFoldoutStates.ContainsKey(key))
            {
                gameServiceFoldoutStates.Add(key, false);
            }

            string foldoutLabel = string.IsNullOrEmpty(name.stringValue) ? "[Untitled " + label + "]" : name.stringValue;

            EditorGUI.indentLevel++;
            gameServiceFoldoutStates[key] = EditorGUILayout.Foldout(gameServiceFoldoutStates[key], foldoutLabel, true);

            if (gameServiceFoldoutStates[key])
            {
                name.stringValue  = EditorGUILayout.TextField("Name", name.stringValue);
                iosId.stringValue = EditorGUILayout.TextField("iOS Id", iosId.stringValue);
                // For Android Id, display a popup of Android leaderboards & achievements for the user to select
                // then assign its associated id to the property.
                EditorGUI.BeginChangeCheck();
                int currentIndex = Mathf.Max(System.Array.IndexOf(gpgsIds, EM_EditorUtil.GetKeyForValue(gpgsIdDict, androidId.stringValue)), 0);
                int newIndex     = EditorGUILayout.Popup("Android Id", currentIndex, gpgsIds);
                if (EditorGUI.EndChangeCheck())
                {
                    // Position 0 is [None].
                    if (newIndex == 0)
                    {
                        androidId.stringValue = string.Empty;
                    }
                    else
                    {
                        // Record the new android Id.
                        string newName = gpgsIds[newIndex];
                        androidId.stringValue = gpgsIdDict[newName];
                    }
                }
            }
            EditorGUI.indentLevel--;
            EditorGUILayout.EndVertical();

            return(gameServiceFoldoutStates[key]);
        }
示例#3
0
        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!"
                );
        }
    }