ca9718144f
Fixed the extra hair, Overhauled the Environment Manager, Removed Save Bloat, Added Loading Screen before Character Menu.
142 lines
3.6 KiB
C#
142 lines
3.6 KiB
C#
using UnityEngine;
|
|
using RPGCreationKit;
|
|
using RPGCreationKit.SaveSystem;
|
|
|
|
namespace RPGCreationKit
|
|
{
|
|
[ExecuteAlways]
|
|
public class SunLightManager : MonoBehaviour
|
|
{
|
|
public static SunLightManager instance;
|
|
private bool Loaded = false;
|
|
private float TimeTrigger = 0f;
|
|
|
|
[Header("References")]
|
|
[SerializeField] private Light DirectionalLight;
|
|
[SerializeField] public SunLightPreset Preset;
|
|
[SerializeField] private Transform StarsSky;
|
|
[SerializeField] private Transform Player;
|
|
[SerializeField] private Material StarsMat;
|
|
public bool IsInterior = false;
|
|
|
|
[Header("Time")]
|
|
[SerializeField] public int Year = 0;
|
|
[SerializeField] public int Month = 1;
|
|
[SerializeField] public int Day = 1;
|
|
[SerializeField, Range(0, 24)] public float TimeOfDay;
|
|
|
|
void Start() {
|
|
StarsMat = StarsSky.GetComponent<ParticleSystem>().GetComponent<Renderer>().sharedMaterial;
|
|
|
|
Year = SaveSystemManager.instance.saveFile.Environment.Year;
|
|
Month = SaveSystemManager.instance.saveFile.Environment.Month;
|
|
Day = SaveSystemManager.instance.saveFile.Environment.Day;
|
|
TimeOfDay = SaveSystemManager.instance.saveFile.Environment.TimeOfDay;
|
|
|
|
Loaded = true;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update() {
|
|
if (TimeTrigger > TimeOfDay) { // Should only trigger once a day.
|
|
Day += 1;
|
|
}
|
|
|
|
TimeTrigger = TimeOfDay;
|
|
|
|
if (Day > 28) {
|
|
Day = 1;
|
|
Month += 1;
|
|
}
|
|
|
|
if (Month > 13) {
|
|
Month = 1;
|
|
Year += 1;
|
|
}
|
|
|
|
if (Loaded == false) {
|
|
return;
|
|
}
|
|
|
|
if (Preset == null) {
|
|
return;
|
|
}
|
|
|
|
if (Application.isPlaying) {
|
|
TimeOfDay += (Time.deltaTime / 180f);
|
|
TimeOfDay %= 24;
|
|
|
|
if (IsInterior == false) {
|
|
|
|
// Setting the Sun
|
|
if (DirectionalLight.gameObject.activeSelf == true) {
|
|
if (RenderSettings.sun != DirectionalLight) {
|
|
RenderSettings.sun = DirectionalLight;
|
|
|
|
}
|
|
}
|
|
|
|
// Setting the Sun
|
|
Color DirectionalTempColor = Preset.DirectionalColor.Evaluate(TimeOfDay / 24f);
|
|
DirectionalLight.color = DirectionalTempColor;
|
|
RenderSettings.skybox.SetFloat("_Exposure", (DirectionalTempColor.a * 5));
|
|
}
|
|
}
|
|
|
|
UpdateLighting(TimeOfDay / 24f);
|
|
}
|
|
|
|
private void UpdateLighting(float TimePercent) {
|
|
RenderSettings.ambientLight = Preset.AmbientColor.Evaluate(TimePercent);
|
|
|
|
// Fog
|
|
Color FogTempColor = Preset.FogColor.Evaluate(TimePercent);
|
|
RenderSettings.fogColor = FogTempColor;
|
|
RenderSettings.fogDensity = ((FogTempColor.a / 10) * 2);
|
|
|
|
// Setting the stars
|
|
StarsSky.position = Player.position;
|
|
Color StarsColor = Preset.StarsVisability.Evaluate(TimePercent);
|
|
Color color = StarsMat.color;
|
|
color.a = StarsColor.a;
|
|
StarsMat.color = color;
|
|
|
|
if (DirectionalLight != null) {
|
|
|
|
DirectionalLight.transform.localRotation = Quaternion.Euler(new Vector3((TimePercent * 360f) -90f, 170f, 0f));
|
|
StarsSky.localRotation = Quaternion.Euler(new Vector3((TimePercent * 360f) -90f, -100, 40));
|
|
}
|
|
}
|
|
|
|
public string GetMonth(int A) { // Ari, Tau, Gen, Can, Le, Ver, Lib, Sco, Sol, Sag, Cap, Aua, Pis.
|
|
if (A == 0) {
|
|
return "Aries";
|
|
} else if (A == 1) {
|
|
return "Taurus";
|
|
} else if (A == 2) {
|
|
return "Gemini";
|
|
} else if (A == 3) {
|
|
return "Cancer";
|
|
} else if (A == 4) {
|
|
return "Leo";
|
|
} else if (A == 5) {
|
|
return "Virgo";
|
|
} else if (A == 6) {
|
|
return "Libra";
|
|
} else if (A == 7) {
|
|
return "Scorpio";
|
|
} else if (A == 8) {
|
|
return "Sol";
|
|
} else if (A == 9) {
|
|
return "Sagittarius";
|
|
} else if (A == 10) {
|
|
return "Capricorn";
|
|
} else if (A == 11) {
|
|
return "Aquarius";
|
|
} else {
|
|
return "Pisces";
|
|
}
|
|
}
|
|
}
|
|
}
|