using System; using System.Linq; using UnityEngine; namespace AibisDream { public class ActiveScenePart : AbsScenePart { [SerializeField] private ActivePartAsset[] activePartAssets; public override void Init(TimesOfDay time, Weather weather = Weather.Sunny) { curWeather = weather; OnTimeChange(time); } public override void OnTimeChange(TimesOfDay time) { curTime = time; var timeArray = activePartAssets.Where(item => item.time == time).ToArray(); if (timeArray.Length == 0) return; // 先尝试找到匹配当前天气的配置 var matchingWeather = timeArray.FirstOrDefault(item => item.weather == curWeather); if (matchingWeather.time != default) // 如果找到了匹配的天气配置 { gameObject.SetActive(matchingWeather.active); return; } // 如果没有找到匹配的天气配置,使用第一个时间匹配的配置 gameObject.SetActive(timeArray[0].active); } public override void OnWeatherChange(Weather weather) { curWeather = weather; var weatherArray = activePartAssets.Where(item => item.weather == weather).ToArray(); if (weatherArray.Length == 0) return; // 先尝试找到匹配当前时间的配置 var matchingTime = weatherArray.FirstOrDefault(item => item.time == curTime); if (matchingTime.time != default) // 如果找到了匹配的时间配置 { gameObject.SetActive(matchingTime.active); return; } // 如果没有找到匹配的时间配置,使用第一个天气匹配的配置 gameObject.SetActive(weatherArray[0].active); } } [Serializable] public struct ActivePartAsset { public TimesOfDay time; public Weather weather; public bool active; } }