public static UAConfig LoadConfig()
        {
            try {
                if (File.Exists(filePath))
                {
                    using (Stream fileStream = File.OpenRead(filePath)) {
                        XmlSerializer serializer = new XmlSerializer(typeof(UAConfig));
                        UAConfig      config     = (UAConfig)serializer.Deserialize(fileStream);
                        config.Migrate();
                        config.Validate();
                        cachedInstance = config;
                    }
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("Failed to load UAConfig: " + e.Message);
                File.Delete(filePath);
            }

            if (cachedInstance == null)
            {
                cachedInstance = new UAConfig();
            }

            return(new UAConfig(cachedInstance));
        }
        public static void SaveConfig(UAConfig config)
        {
            config.Validate();
            using (Stream fileStream = File.Open(filePath, FileMode.Create)) {
                XmlSerializer serializer = new XmlSerializer(typeof(UAConfig));
                serializer.Serialize(fileStream, config);
            }

            cachedInstance = config;
        }
Esempio n. 3
0
        void OnGUI()
        {
            minSize = new Vector2(800, 640);

            CreateSection("Production", () => {
                config.ProductionAppKey      = EditorGUILayout.TextField("App Key", config.ProductionAppKey);
                config.ProductionAppSecret   = EditorGUILayout.TextField("App Secret", config.ProductionAppSecret);
                config.ProductionLogLevel    = (UAConfig.LogLevel)EditorGUILayout.EnumPopup("Log level:", config.ProductionLogLevel);
                config.ProductionFCMSenderId = EditorGUILayout.TextField("Android FCM Sender ID:", config.ProductionFCMSenderId);
            });


            CreateSection("Development", () => {
                config.DevelopmentAppKey      = EditorGUILayout.TextField("App Key", config.DevelopmentAppKey);
                config.DevelopmentAppSecret   = EditorGUILayout.TextField("App Secret", config.DevelopmentAppSecret);
                config.DevelopmentLogLevel    = (UAConfig.LogLevel)EditorGUILayout.EnumPopup("Log level:", config.DevelopmentLogLevel);
                config.DevelopmentFCMSenderId = EditorGUILayout.TextField("Android FCM Sender ID:", config.DevelopmentFCMSenderId);
            });

            CreateSection("In Production", () => {
                config.InProduction = EditorGUILayout.Toggle("inProduction", config.InProduction);
            });

            CreateSection("Android Notifications", () => {
                config.AndroidNotificationAccentColor = EditorGUILayout.TextField("Notification Accent Color", config.AndroidNotificationAccentColor);
                config.AndroidNotificationIcon        = EditorGUILayout.TextField("Notification Icon", config.AndroidNotificationIcon);

                GUILayout.Space(5);

                GUILayout.Label("Notification icon must be the name of a drawable in the project, e.g., " +
                                "app_icon, ic_dialog_alert. Drawables can be added " +
                                "in either the Assets/Plugins/Android/urbanairship-resources/res/drawable* directory or by " +
                                "providing a new Android library project.", EditorStyles.wordWrappedMiniLabel);
            });

            CreateSection("iOS Foreground Presentation Options", () => {
                config.NotificationPresentationOptionAlert = EditorGUILayout.Toggle("Alert", config.NotificationPresentationOptionAlert);
                config.NotificationPresentationOptionBadge = EditorGUILayout.Toggle("Badge", config.NotificationPresentationOptionBadge);
                config.NotificationPresentationOptionSound = EditorGUILayout.Toggle("Sound", config.NotificationPresentationOptionSound);
            });

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Cancel"))
            {
                Close();
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Save"))
            {
                try {
                    config.Validate();

                    UnityEngine.Debug.Log("Saving Urban Airship config.");

                    config.Apply();
                    UAConfig.SaveConfig(config);

                    AssetDatabase.Refresh();
                    Close();
                } catch (Exception e) {
                    EditorUtility.DisplayDialog("Urban Airship", "Unable to save config. Error: " + e.Message, "Ok");
                }
            }

            GUILayout.FlexibleSpace();
        }
Esempio n. 4
0
        public static void SaveConfig(UAConfig config)
        {
            config.Validate ();
            using (Stream fileStream = File.Open (filePath, FileMode.Create)) {
                XmlSerializer serializer = new XmlSerializer (typeof(UAConfig));
                serializer.Serialize (fileStream, config);
            }

            cachedInstance = config;
        }