using System;
using UnityEngine;
using UnityEngine.Rendering.Universal;

namespace NBF.Setting
{
    public enum TextureQualityEnum
    {
        FullRes = 0,
        HalfRes = 1,
        QuarterRes = 2,
        EighthRes = 3
    }

    [Sort(9)]
    public class TextureQualitySetting : MultiOption<TextureQualityEnum>
    {
        public override string Name => "TextureQuality";
        public override string Group => SettingsDef.Group.Graphic;
        protected override int DefaultValue => (int)TextureQualityEnum.FullRes;
        public override string Tab => SettingsDef.Tab.Graphic;

        protected override void OnInitialize()
        {
            var enumValues = Enum.GetValues(typeof(TextureQualityEnum));
            foreach (var value in enumValues)
            {
                AddOption(value.ToString(), (TextureQualityEnum)value);
            }
        }

        protected override void OnApply()
        {
            // 获取当前URP Asset
            UniversalRenderPipelineAsset URPAsset =
                QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
                    UniversalRenderPipelineAsset;
            if (URPAsset)
            {
                //纹理质量
                QualitySettings.globalTextureMipmapLimit = (int)GetSelectedOption();
            }
        }
    }
}