Пример #1
0
        public override void LoadValue(string val)
        {
            if (_enumType == null)
            {
                _enumType = DevConsole.GetVariableType(SettingName);
                if (_enumType == null)
                {
                    return;
                }
            }

            if (_enumNames == null)
            {
                _enumNames = Enum.GetNames(_enumType);
            }

            for (int i = 0; i < _enumNames.Length; i++)
            {
                if (_enumNames[i].Equals(val, StringComparison.OrdinalIgnoreCase))
                {
                    _dropdown.SetValueWithoutNotify(i);
                    _dropdown.RefreshShownValue();
                    break;
                }
            }
        }
Пример #2
0
 protected override void _Initialize()
 {
     _dropdown.ClearOptions();
     _enumType = DevConsole.GetVariableType(SettingName);
     if (_enumType == null || !_enumType.IsEnum)
     {
         Debug.LogError("SettingEnum on wrong type: " + SettingName);
         return;
     }
     _dropdown.AddOptions(Enum.GetNames(_enumType).ToList());
     _dropdown.onValueChanged.AddListener(OnValueChanged);
 }
        private SettingElement GetSettingElement(string settingName)
        {
            var custom = _customElements.FirstOrDefault(x => x.SettingName.Equals(settingName, StringComparison.OrdinalIgnoreCase));

            if (custom != null)
            {
                return(custom.Element);
            }
            if (settingName.StartsWith("bind/"))
            {
                return(_bindElement);
            }

            var type = DevConsole.GetVariableType(settingName);

            if (type == null)
            {
                return(null);
            }

            if (type.IsEnum)
            {
                return(_enumElement);
            }

            if (type == typeof(Color))
            {
                return(_colorElement);
            }

            switch (Type.GetTypeCode(type))
            {
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Int16:
                return(_integerElement);

            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                return(_floatElement);

            case TypeCode.String:
                return(_stringElement);

            case TypeCode.Boolean:
                return(_boolElement);

            default:
                return(null);
            }
        }