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

namespace NBF.Setting
{
    [Sort(5)]
    public class RenderScaleSetting : RangeOption
    {
        public override string Name => "RenderScale";
        public override string Group => SettingsDef.Group.Graphic;
        public override string Tab => SettingsDef.Tab.Graphic;
        public override int MinValue => 1;
        public override int MaxValue => 20;

        protected override int DefaultValue => 10;

        public override int ShowRate => 10;

        protected override void OnInitialize()
        {
            SetValue(10);
        }

        protected override void OnApply()
        {
            // 获取当前URP Asset
            UniversalRenderPipelineAsset URPAsset =
                QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
                    UniversalRenderPipelineAsset;
            if (URPAsset)
            {
                //渲染比例
                URPAsset.renderScale = (float)Math.Round(GetValue() / 10f, 1);
            }
        }
    }
}