using System; using AibisDream.Kit; using UnityEngine; using Yarn.Unity; namespace AibisDream { public class EnvironmentManager : Singleton { public bool initOnAwake = true; public TimesOfDay defaultTime; public Weather defaultWeather; private AbsScenePart[] _absSceneParts; public override void OnSingletonInit() { if (initOnAwake) { InitEnvironment(defaultTime, defaultWeather); } } public void InitEnvironment(TimesOfDay timeOfDay, Weather weather) { _absSceneParts = GetComponentsInChildren(true); foreach (var part in _absSceneParts) { part.Init(timeOfDay, weather); } } public void SetTimeOfDay(TimesOfDay timeOfDay) { foreach (var part in _absSceneParts) { part.OnTimeChange(timeOfDay); } } public void SetWeather(Weather weather) { foreach (var part in _absSceneParts) { part.OnWeatherChange(weather); } } } public static class EnvironmentYarnCommand { [YarnCommand("init_environment")] public static void InitEnvironment(string timeOfDay, string weatherType = "Sunny") { if (!Enum.TryParse(timeOfDay, out var time)) { Debug.Log($"{timeOfDay}是不存在的时间"); return; } if (!Enum.TryParse(weatherType, out var weather)) { Debug.Log($"{weatherType}是不存在的天气"); return; } EnvironmentManager.Instance.InitEnvironment(time, weather); } [YarnCommand("set_time_of_day")] public static void SetTimeOfDay(string timeOfDay) { if (!Enum.TryParse(timeOfDay, out var time)) { Debug.Log($"{timeOfDay}是不存在的时间"); return; } EnvironmentManager.Instance.SetTimeOfDay(time); } [YarnCommand("set_weather")] public static void SetWeather(string weatherType) { if (!Enum.TryParse(weatherType, out var weather)) { Debug.Log($"{weatherType}是不存在的天气"); return; } EnvironmentManager.Instance.SetWeather(weather); } } }