using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using UniRx; using UnityEngine; using UnityEngine.AzureSky; using UnityEngine.UI; public class GameSettingPanel : UIView { #region Variables //时间天气面板 public CanvasGroup TimePanel; //显示面板 public CanvasGroup DisplayPanel; //时间天气面板开关 public Toggle TimeToggle; //显示面板开关 public Toggle DisplayToggle; //省份选择 public Dropdown ProvinceDropdown; //城市选择 public Dropdown CityDropdown; //实时天气开关 public Toggle RTWeatherToggle; //实时天气刷新按钮 public Button RTWeatherButton; //天气 public Dropdown WeatherDropdown; //温度 public Slider TempSlider; public InputField TempInput; //风力 public Slider ForceSlider; public InputField ForceInput; //风向 public Dropdown DirectionDropdown; //昼夜交替 public Toggle TimeOfDayToggle; //持续时间 public Slider DurationSlider; public InputField DurationInput; public float DurationTime = 6f; //时间 public Slider TimeSlider; public InputField HourInput; public InputField MinuteInput; //贴图质量 public Dropdown TextureDropdown; //各向异性 public Dropdown AnisotropicDropdown; //阴影开关 public Toggle ShadowToggle; //画面质量 public Dropdown QualityDropdown; //亮度 public Slider BrightnessSlider; ////反射 //public Dropdown ReflectionDropdown; //分辨率 public Dropdown ResolutionDropdown; //全屏 public Toggle FullScreenToggle; public Button CloseButton; public CountryCodeData CodeData = new CountryCodeData(); public List ProvinceOptions = new List(); public List CityOptions = new List(); //public GameSettingDataReactive DataSource = new GameSettingDataReactive(); public ResolutionDatas ResData = new ResolutionDatas(); #endregion public override void Awake() { base.Awake(); Observable.EveryUpdate() .Subscribe(_ => { TimeSlider.value = AzureSkyController.Instance.timeOfDay.hour; }); #region 获取省份列表 HttpManager.Instance.Get(HttpManager.Instance.GetCityCode, data => { CodeData = data; foreach (var tempdata in data.CountryCode) { ProvinceOptions.Add(tempdata.province); } ProvinceDropdown.AddOptions(ProvinceOptions); GetCity(true); }); #endregion #region 获取分辨率数据 #if UNITY_STANDALONE var url = HttpManager.Instance.GetResolution; HttpManager.Instance.Get(url, data => { ResData = data; foreach (var temdata in ResData.ResList) { var option = new Dropdown.OptionData { text = temdata.Width + "*" + temdata.Height }; ResolutionDropdown.options.Add(option); } //分辨率 DataSource.Resolution.Subscribe(value => ResolutionDropdown.value = value).AddTo(gameObject); DataSource.Resolution.Subscribe(value => { Screen.SetResolution(ResData.ResList[value].Width, ResData.ResList[value].Height, DataSource.FullScreen.Value); }).AddTo(gameObject); ResolutionDropdown.OnValueChangedAsObservable().Subscribe(value => DataSource.Resolution.Value = value); //全屏 DataSource.FullScreen.Subscribe(value => FullScreenToggle.isOn = value).AddTo(gameObject); DataSource.FullScreen.Subscribe(value => { Screen.SetResolution(ResData.ResList[ResolutionDropdown.value].Width, ResData.ResList[ResolutionDropdown.value].Height, value); }).AddTo(gameObject); FullScreenToggle.OnValueChangedAsObservable().Subscribe(value => DataSource.FullScreen.Value = value); }); #endif #endregion #if UNITY_WEBGL ResolutionDropdown.interactable = false; FullScreenToggle.interactable = false; #endif #region 数据绑定 //省份 DataSource.Province.Subscribe(value => ProvinceDropdown.value = value).AddTo(gameObject); ProvinceDropdown.OnValueChangedAsObservable().Subscribe(value => DataSource.Province.Value = value); //城市 DataSource.City.Subscribe(value => CityDropdown.value = value).AddTo(gameObject); CityDropdown.OnValueChangedAsObservable().Subscribe(value => DataSource.City.Value = value); //实时天气 DataSource.RealTimeWeather.Subscribe(value => RTWeatherToggle.isOn = value).AddTo(gameObject); RTWeatherToggle.OnValueChangedAsObservable().Subscribe(value => DataSource.RealTimeWeather.Value = value); //天气 DataSource.Weather.Subscribe(value => WeatherDropdown.value = value).AddTo(gameObject); DataSource.Weather.SubscribeToText(UIManager.Instance.GetView().WeatherText, x => WeatherDropdown.captionText.text).AddTo(gameObject); DataSource.Weather .Where(_ => RTWeatherToggle.isOn == false) .Subscribe(value => { AzureSkyController.Instance.isBlendingWeathers = false; AzureSkyController.Instance.SetNewWeatherProfile(value); }).AddTo(gameObject); WeatherDropdown.OnValueChangedAsObservable() .Where(_ => RTWeatherToggle.isOn == false) .Subscribe(s => DataSource.Weather.Value = s); //温度 DataSource.Temperature.Subscribe(value => TempSlider.value = value).AddTo(gameObject); DataSource.Temperature.SubscribeToText(UIManager.Instance.GetView().TemperatureText, x => (int)TempSlider.value + "℃").AddTo(gameObject); DataSource.Temperature.SubscribeToText(TempInput, x => ((int)TempSlider.value).ToString()).AddTo(gameObject); TempSlider.OnValueChangedAsObservable().Subscribe(s => DataSource.Temperature.Value = (int)s); TempInput.OnEndEditAsObservable().Subscribe(s => DataSource.Temperature.Value = int.Parse(s)); //风力 DataSource.WindForce.Subscribe(value => AssetManager.Instance.windZone.windMain = value); DataSource.WindForce.Subscribe(value => ForceSlider.value = value).AddTo(gameObject); DataSource.WindForce.SubscribeToText(UIManager.Instance.GetView().WindText, x => (int)ForceSlider.value + "级").AddTo(gameObject); DataSource.WindForce.SubscribeToText(ForceInput, x => ((int)ForceSlider.value).ToString()).AddTo(gameObject); ForceSlider.OnValueChangedAsObservable().Subscribe(s => DataSource.WindForce.Value = (int)s); ForceInput.OnEndEditAsObservable().Subscribe(s => DataSource.WindForce.Value = int.Parse(s)); //风向 DataSource.WindDirection.Subscribe(value => DirectionDropdown.value = value).AddTo(gameObject); DataSource.WindDirection.SubscribeToText(UIManager.Instance.GetView().DirectionText, x => DirectionDropdown.captionText.text).AddTo(gameObject); DataSource.WindDirection.Subscribe(value => AssetManager.Instance.windZone.transform.localEulerAngles = new Vector3(0, value * 45 - AssetManager.Instance.InitialAngle, 0)).AddTo(gameObject); DirectionDropdown.OnValueChangedAsObservable().Subscribe(s => DataSource.WindDirection.Value = s); //昼夜交替 DataSource.TimeOfDay.Subscribe(value => TimeOfDayToggle.isOn = value).AddTo(gameObject); DataSource.TimeOfDay.Subscribe(isOn => { if (isOn) { DurationTime = DurationSlider.value * 60f; } else { DurationTime = 0f; TimeSlider.value = 11.0f; } AzureSkyController.Instance.timeOfDay.dayCycle = DurationTime; var value = AzureSkyController.Instance.timeOfDay.GetDayLength(); AzureSkyController.Instance.GetTimeProgression(value); }).AddTo(gameObject); TimeOfDayToggle.OnValueChangedAsObservable().Subscribe(s => DataSource.TimeOfDay.Value = s); //持续时间 DataSource.Duration.Subscribe(value => DurationSlider.value = value).AddTo(gameObject); DataSource.Duration.SubscribeToText(DurationInput, x => DurationSlider.value.ToString()).AddTo(gameObject); DataSource.Duration.Subscribe(value => { DurationTime = value * 60f; if (TimeOfDayToggle.isOn) { AzureSkyController.Instance.timeOfDay.dayCycle = DurationTime; var value2 = AzureSkyController.Instance.timeOfDay.GetDayLength(); AzureSkyController.Instance.GetTimeProgression(value2); } }).AddTo(gameObject); DurationSlider.OnValueChangedAsObservable().Subscribe(s => { DataSource.Duration.Value = s; }); DurationInput.OnEndEditAsObservable().Subscribe(s => DataSource.Duration.Value = float.Parse(s)); //时间滑块 DataSource.Time.Subscribe(value => TimeSlider.value = value).AddTo(gameObject); DataSource.Time.Subscribe(value => { string[] times = value.ToString("F2").Split('.'); int hour = int.Parse(times[0]); float _minute = int.Parse(times[1]) * 0.6f; int minute = (int)_minute; HourInput.text = hour.ToString("D2"); MinuteInput.text = minute.ToString("D2"); }).AddTo(gameObject); DataSource.Time.Subscribe(value => AzureSkyController.Instance.timeOfDay.hour = value).AddTo(gameObject); TimeSlider.OnValueChangedAsObservable().Subscribe(s => DataSource.Time.Value = s); HourInput.OnEndEditAsObservable().Subscribe(s => DataSource.Time.Value = float.Parse(s + "." + int.Parse(MinuteInput.text) / 6)); MinuteInput.OnEndEditAsObservable().Subscribe(s => DataSource.Time.Value = float.Parse(HourInput.text + "." + int.Parse(s) / 6)); //贴图质量 DataSource.TextureQuality.Subscribe(value => TextureDropdown.value = value).AddTo(gameObject); DataSource.TextureQuality.Subscribe(value => QualitySettings.masterTextureLimit = value).AddTo(gameObject); TextureDropdown.OnValueChangedAsObservable().Subscribe(v => DataSource.TextureQuality.Value = v); //各向异性 DataSource.Anisotropic.Subscribe(value => AnisotropicDropdown.value = value).AddTo(gameObject); DataSource.Anisotropic.Subscribe(value => { switch (value) { case 0: QualitySettings.anisotropicFiltering = AnisotropicFiltering.Disable; break; case 1: QualitySettings.anisotropicFiltering = AnisotropicFiltering.ForceEnable; break; } }).AddTo(gameObject); AnisotropicDropdown.OnValueChangedAsObservable().Subscribe(v => DataSource.Anisotropic.Value = v); //画面质量 DataSource.Quality.Subscribe(value => QualityDropdown.value = value).AddTo(gameObject); DataSource.Quality .Subscribe(value => { //QualitySettings.renderPipeline = AssetManager.Instance.RenderPipelines[value]; QualitySettings.SetQualityLevel(value); }); QualityDropdown.OnValueChangedAsObservable().Subscribe(value => DataSource.Quality.Value = value); //阴影开关 DataSource.ShadowSwitch.Subscribe(value => ShadowToggle.isOn = value).AddTo(gameObject); DataSource.ShadowSwitch.Subscribe(value => { if (value) { AzureSkyController.Instance.lightTransform.GetComponent().shadows = LightShadows.Soft; } else { AzureSkyController.Instance.lightTransform.GetComponent().shadows = LightShadows.None; } }).AddTo(gameObject); ShadowToggle.OnValueChangedAsObservable().Subscribe(value => DataSource.ShadowSwitch.Value = value); //亮度 DataSource.Brightness.Subscribe(value => BrightnessSlider.value = value).AddTo(gameObject); DataSource.Brightness.Subscribe(value => AzureSkyController.Instance.LightAddition = value).AddTo(gameObject); BrightnessSlider.OnValueChangedAsObservable().Subscribe(value => DataSource.Brightness.Value = value); //反射 //DataSource.Reflection.Subscribe(value => ReflectionDropdown.value = value).AddTo(gameObject); //DataSource.Reflection.Subscribe(value => //{ // switch (value) // { // case 0: // AssetManager.Instance.ReflectionProbes.SetActive(false); // break; // case 1: // AssetManager.Instance.ReflectionProbes.SetActive(true); // break; // } //}).AddTo(gameObject); //ReflectionDropdown.OnValueChangedAsObservable().Subscribe(value => DataSource.Reflection.Value = value); #endregion #region Button Click ProvinceDropdown.OnValueChangedAsObservable() .Where(_ => CodeData.CountryCode != null) .Subscribe(value => { GetCity(false); }); CityDropdown.OnValueChangedAsObservable() .Where(_ => CodeData.CountryCode != null) .Subscribe(value => { AssetManager.Instance.CityCode = GetCityCode(ProvinceDropdown.captionText.text, CityDropdown.captionText.text); GetWeather(); }); RTWeatherToggle.onValueChanged.AddListener((bool value) => CustomWeather(!value)); RTWeatherButton.OnClickAsObservable() .Where(_ => RTWeatherToggle.isOn) .Subscribe(_ => GetWeather()); //重置 transform.Find("Bottom/Restoring").GetComponent