OldBlueWater/BlueWater/Assets/Distant Lands/Cozy Weather/Contents/Scripts/Modules/CozyTVEModule.cs

166 lines
4.1 KiB
C#
Raw Normal View History

2023-09-13 05:07:40 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if THE_VEGETATION_ENGINE
using TheVegetationEngine;
#endif
2024-01-03 06:34:33 +00:00
#if UNITY_EDITOR
using UnityEditor;
#endif
2023-09-13 05:07:40 +00:00
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
// Start is called before the first frame update
void Awake()
{
2024-01-03 06:34:33 +00:00
InitializeModule();
2023-09-13 05:07:40 +00:00
#if THE_VEGETATION_ENGINE
if (updateFrequency == UpdateFrequency.onAwake)
UpdateTVE();
#endif
}
#if THE_VEGETATION_ENGINE
2024-01-03 06:34:33 +00:00
public override void InitializeModule()
2023-09-13 05:07:40 +00:00
{
if (!enabled)
return;
2024-01-03 06:34:33 +00:00
base.InitializeModule();
2023-09-13 05:07:40 +00:00
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()
{
2024-01-03 06:34:33 +00:00
if (weatherSphere.climateModule)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
globalControl.globalWetness = weatherSphere.climateModule.wetness;
globalControl.globalOverlay = weatherSphere.climateModule.snowAmount;
2023-09-13 05:07:40 +00:00
}
2024-01-03 06:34:33 +00:00
globalControl.seasonControl = weatherSphere.timeModule.yearPercentage * 4;
2023-09-13 05:07:40 +00:00
2024-01-03 06:34:33 +00:00
if (weatherSphere.windModule)
2023-09-13 05:07:40 +00:00
{
2024-01-03 06:34:33 +00:00
globalMotion.windPower = weatherSphere.windModule.windAmount;
globalMotion.transform.LookAt(globalMotion.transform.position + weatherSphere.windModule.WindDirection, Vector3.up);
2023-09-13 05:07:40 +00:00
}
}
#endif
}
2024-01-03 06:34:33 +00:00
#if UNITY_EDITOR
[CustomEditor(typeof(CozyTVEModule))]
[CanEditMultipleObjects]
public class E_TVEIntegration : E_CozyModule
{
SerializedProperty updateFrequency;
CozyTVEModule module;
void OnEnable()
{
}
public override GUIContent GetGUIContent()
{
return new GUIContent(" TVE", (Texture)Resources.Load("Boxophobic"), "Links the COZY system with the vegetation engine by BOXOPHOBIC.");
}
public override void OpenDocumentationURL()
{
Application.OpenURL("https://distant-lands.gitbook.io/cozy-stylized-weather-documentation/how-it-works/modules/the-vegetation-engine-tve-module");
}
public override void DisplayInCozyWindow()
{
serializedObject.Update();
if (module == null)
module = (CozyTVEModule)target;
EditorGUILayout.PropertyField(serializedObject.FindProperty("updateFrequency"));
serializedObject.ApplyModifiedProperties();
#if THE_VEGETATION_ENGINE
if (!module.globalControl || !module.globalMotion)
{
EditorGUILayout.Space(20);
EditorGUILayout.HelpBox("Make sure that you have active TVE Global Motion and TVE Global Control objects in your scene!", MessageType.Warning);
}
#else
EditorGUILayout.Space(20);
EditorGUILayout.HelpBox("The Vegetation Engine is not currently in this project! Please make sure that it has been properly downloaded before using this module.", MessageType.Warning);
#endif
}
}
#endif
2023-09-13 05:07:40 +00:00
}