Пример #1
0
        private int DrawSettingElements(Rect rect, BuildTargetGroup buildTarget, List <NotificationSetting> settings, bool disabled, int layer, int labelWidthMultiplier)
        {
            var spaceOffset = layer * 13;

            var labelStyle = new GUIStyle(NotificationStyles.k_LabelStyle);

            labelStyle.fixedWidth = k_SlotSize * labelWidthMultiplier - spaceOffset;

            var toggleStyle   = NotificationStyles.k_ToggleStyle;
            var dropdownStyle = NotificationStyles.k_DropwDownStyle;

            int elementCount = settings.Count;

            foreach (var setting in settings)
            {
                EditorGUI.BeginDisabledGroup(disabled);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(spaceOffset);

                GUILayout.Label(new GUIContent(setting.Label, setting.Tooltip), labelStyle);

                bool dependenciesDisabled = false;

                EditorGUI.BeginChangeCheck();
                if (setting.Value.GetType() == typeof(bool))
                {
                    setting.Value        = EditorGUILayout.Toggle((bool)setting.Value, toggleStyle);
                    dependenciesDisabled = !(bool)setting.Value;
                }
                else if (setting.Value.GetType() == typeof(string))
                {
                    setting.Value = EditorGUILayout.TextField((string)setting.Value);
                }
                else if (setting.Value.GetType() == typeof(PresentationOption))
                {
                    setting.Value = (PresentationOption)EditorGUILayout.EnumFlagsField((iOSPresentationOption)setting.Value, dropdownStyle);
                }
                else if (setting.Value.GetType() == typeof(AuthorizationOption))
                {
                    setting.Value = (AuthorizationOption)EditorGUILayout.EnumFlagsField((iOSAuthorizationOption)setting.Value, dropdownStyle);
                    if ((iOSAuthorizationOption)setting.Value == 0)
                    {
                        setting.Value = (AuthorizationOption)(iOSAuthorizationOption.Badge | iOSAuthorizationOption.Sound | iOSAuthorizationOption.Alert);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    m_SettingsManager.SaveSetting(setting, buildTarget);
                }

                EditorGUILayout.EndHorizontal();
                EditorGUI.EndDisabledGroup();

                if (setting.Dependencies != null)
                {
                    elementCount += DrawSettingElements(rect, buildTarget, setting.Dependencies, dependenciesDisabled, layer + 1, labelWidthMultiplier);
                }
            }

            return(elementCount);
        }
        private void DrawSettingsElementList(BuildTargetGroup target, List <NotificationSetting> settings, bool disabled, GUIStyle styleToggle, GUIStyle styleDropwDown, Rect rect, int layer = 0)
        {
            foreach (var setting in settings)
            {
                EditorGUI.BeginDisabledGroup(disabled);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(layer * 13);

                var styleLabel = new GUIStyle(GUI.skin.GetStyle("Label"));

                var width = rect.width - kSlotSize * 4.5f - layer * 13;

                styleLabel.fixedWidth = width;
                styleLabel.wordWrap   = true;

                GUILayout.Label(new GUIContent(setting.label, setting.tooltip), styleLabel);

                if (setting.val.GetType() == typeof(bool))
                {
                    setting.val = (object)EditorGUILayout.Toggle((bool)setting.val, styleToggle);
                }
                else if (setting.val.GetType() == typeof(string))
                {
                    setting.val = (object)EditorGUILayout.TextField((string)setting.val);
                }
                else if (setting.val.GetType() == typeof(PresentationOption))
                {
                    setting.val =
                        (PresentationOption)EditorGUILayout.EnumFlagsField((iOSPresentationOption)setting.val, styleDropwDown);
                    if ((int)(iOSPresentationOption)setting.val == 0)
                    {
                        setting.val = (PresentationOption)iOSPresentationOption.All;
                    }
                }
                else if (setting.val.GetType() == typeof(AuthorizationOption))
                {
                    setting.val =
                        (AuthorizationOption)EditorGUILayout.EnumFlagsField((iOSAuthorizationOption)setting.val, styleDropwDown);
                    if ((int)(iOSAuthorizationOption)setting.val == 0)
                    {
                        setting.val = (AuthorizationOption)iOSAuthorizationOption.All;
                    }
                }

                EditorGUILayout.EndHorizontal();
                EditorGUI.EndDisabledGroup();

                bool dependentDisabled = false;
                if (setting.val is bool)
                {
                    dependentDisabled = !(bool)setting.val;
                }

                if (setting.dependentSettings != null)
                {
                    var childLayer = layer;
                    childLayer++;
                    DrawSettingsElementList(target, setting.dependentSettings, dependentDisabled, styleToggle, styleDropwDown, rect, childLayer);
                }

                if (setting.requiredSettings != null && !disabled)
                {
                    if ((bool)setting.val)
                    {
                        foreach (var requiredSettingKey in setting.requiredSettings)
                        {
                            var requiredSetting = manager.iOSNotificationSettings.Find(s => s.key == requiredSettingKey);
                            if (requiredSetting != null)
                            {
                                requiredSetting.val = setting.val;
                                manager.SaveSetting(requiredSetting, target);
                            }
                        }
                    }
                }

                manager.SaveSetting(setting, target);
            }
        }