OldBlueWater/BlueWater/Assets/Distant Lands/Cozy Weather/Contents/Scripts/Modules/CozyTVEModule.cs
2023-09-13 14:07:40 +09:00

125 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if THE_VEGETATION_ENGINE
using TheVegetationEngine;
#endif
namespace DistantLands.Cozy
{
[ExecuteAlways]
public class CozyTVEModule : CozyModule
{
public enum UpdateFrequency { everyFrame, onAwake, viaScripting }
public UpdateFrequency updateFrequency;
#if THE_VEGETATION_ENGINE
public TVEGlobalControl globalControl;
public TVEGlobalMotion globalMotion;
#endif
void OnEnable()
{
if (GetComponent<CozyWeather>())
{
GetComponent<CozyWeather>().InitializeModule(typeof(CozyTVEModule));
DestroyImmediate(this);
Debug.LogWarning("Add modules in the settings tab in COZY 2!");
return;
}
}
// Start is called before the first frame update
void Awake()
{
SetupModule();
#if THE_VEGETATION_ENGINE
if (updateFrequency == UpdateFrequency.onAwake)
UpdateTVE();
#endif
}
#if THE_VEGETATION_ENGINE
public override void SetupModule()
{
if (!enabled)
return;
weatherSphere = CozyWeather.instance;
if (!weatherSphere)
{
enabled = false;
return;
}
if (!globalControl)
globalControl = FindObjectOfType<TVEGlobalControl>();
if (!globalControl)
{
enabled = false;
return;
}
if (!globalMotion)
globalMotion = FindObjectOfType<TVEGlobalMotion>();
if (!globalMotion)
{
enabled = false;
return;
}
globalControl.mainLight = weatherSphere.sunLight;
}
// Update is called once per frame
void Update()
{
if (weatherSphere.freezeUpdateInEditMode && !Application.isPlaying)
return;
if (updateFrequency == UpdateFrequency.everyFrame)
UpdateTVE();
}
public void UpdateTVE()
{
if (weatherSphere.cozyMaterials)
{
globalControl.globalWetness = weatherSphere.cozyMaterials.wetness;
globalControl.globalOverlay = weatherSphere.cozyMaterials.snowAmount;
}
globalControl.seasonControl = weatherSphere.GetCurrentYearPercentage() * 4;
if (weatherSphere.VFX)
{
globalMotion.windPower = weatherSphere.VFX.windManager.windAmount;
globalMotion.transform.LookAt(globalMotion.transform.position + weatherSphere.VFX.windManager.windDirection, Vector3.up);
}
}
#endif
}
}