92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Yarn.Unity;
|
|
|
|
public class EnvironmentManager : MonoBehaviour
|
|
{
|
|
[Header("Time of Day Objects")]
|
|
public List<GameObject> dayObjects;
|
|
public List<GameObject> nightObjects;
|
|
public List<GameObject> midnightObjects;
|
|
|
|
[Header("Weather Effects")]
|
|
public GameObject snowEffect;
|
|
|
|
private void Start()
|
|
{
|
|
// 设置默认状态
|
|
SetTimeOfDay(TimeOfDay.Day);
|
|
SetWeather(false);
|
|
}
|
|
|
|
[YarnCommand("set_time_of_day")]
|
|
public void SetTimeOfDayCommand(string timeOfDay)
|
|
{
|
|
timeOfDay = timeOfDay.ToLower();
|
|
if (timeOfDay == "day" && dayObjects.Count > 0)
|
|
{
|
|
SetTimeOfDay(TimeOfDay.Day);
|
|
}
|
|
else if (timeOfDay == "night" && nightObjects.Count > 0)
|
|
{
|
|
SetTimeOfDay(TimeOfDay.Night);
|
|
}
|
|
else if (timeOfDay == "midnight" && midnightObjects.Count > 0)
|
|
{
|
|
SetTimeOfDay(TimeOfDay.Midnight);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"Invalid or unavailable time of day: {timeOfDay}");
|
|
}
|
|
}
|
|
|
|
public void SetTimeOfDay(TimeOfDay timeOfDay)
|
|
{
|
|
if (dayObjects.Count > 0)
|
|
{
|
|
foreach (var obj in dayObjects)
|
|
{
|
|
obj.SetActive(timeOfDay == TimeOfDay.Day);
|
|
}
|
|
}
|
|
|
|
if (nightObjects.Count > 0)
|
|
{
|
|
foreach (var obj in nightObjects)
|
|
{
|
|
obj.SetActive(timeOfDay == TimeOfDay.Night);
|
|
}
|
|
}
|
|
|
|
if (midnightObjects.Count > 0)
|
|
{
|
|
foreach (var obj in midnightObjects)
|
|
{
|
|
obj.SetActive(timeOfDay == TimeOfDay.Midnight);
|
|
}
|
|
}
|
|
}
|
|
|
|
[YarnCommand("set_weather")]
|
|
public void SetWeatherCommand(string weatherType)
|
|
{
|
|
bool isSnowing = weatherType.ToLower() == "snow";
|
|
SetWeather(isSnowing);
|
|
}
|
|
|
|
public void SetWeather(bool isSnowing)
|
|
{
|
|
if (snowEffect != null)
|
|
{
|
|
snowEffect.SetActive(isSnowing);
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum TimeOfDay
|
|
{
|
|
Day,
|
|
Night,
|
|
Midnight
|
|
} |