45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
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)
|
|
{
|
|
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 res = timeArray.DefaultIfEmpty(timeArray[0]).First(item => item.weather == curWeather);
|
|
gameObject.SetActive(res.active);
|
|
}
|
|
|
|
public override void OnWeatherChange(Weather weather)
|
|
{
|
|
curWeather = weather;
|
|
|
|
var weatherArray = activePartAssets.Where(item => item.weather == weather).ToArray();
|
|
if (weatherArray.Length == 0) return;
|
|
var res = weatherArray.DefaultIfEmpty(weatherArray[0]).First(item => item.time == curTime);
|
|
gameObject.SetActive(res.active);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct ActivePartAsset
|
|
{
|
|
public TimesOfDay time;
|
|
public Weather weather;
|
|
public bool active;
|
|
}
|
|
} |