371 lines
14 KiB
C#
371 lines
14 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
[ExecuteAlways]
|
|
public class AutoConfigureSM : MonoBehaviour
|
|
{
|
|
public SkyMasterManager SkyManager;
|
|
|
|
public bool configure;
|
|
|
|
public bool enableWater = true;
|
|
|
|
public bool configured;
|
|
|
|
public bool addFullVolumeClouds;
|
|
|
|
public bool addSmoothSun;
|
|
|
|
public controlWeatherTOD_SM_SRP sunController;
|
|
|
|
public WeatherScript weatherTexture;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!configure || configured || !(SkyManager != null))
|
|
{
|
|
return;
|
|
}
|
|
if (Camera.main == null)
|
|
{
|
|
GameObject obj = new GameObject();
|
|
obj.tag = "MainCamera";
|
|
obj.AddComponent<Camera>();
|
|
obj.name = "Main Camera";
|
|
}
|
|
if (Camera.main != null)
|
|
{
|
|
Camera.main.farClipPlane = 30000f;
|
|
Camera.main.transform.position = Camera.main.transform.position + new Vector3(0f, 10f, 0f);
|
|
SkyManager.Current_Time = 10.3f;
|
|
if (!addFullVolumeClouds)
|
|
{
|
|
FullVolumeCloudsSkyMaster fullVolumeCloudsSkyMaster = Camera.main.gameObject.GetComponent<FullVolumeCloudsSkyMaster>();
|
|
if (fullVolumeCloudsSkyMaster != null)
|
|
{
|
|
fullVolumeCloudsSkyMaster.Sun = SkyManager.SunObj.transform;
|
|
fullVolumeCloudsSkyMaster.SkyManager = SkyManager;
|
|
fullVolumeCloudsSkyMaster.initVariablesScatter();
|
|
SkyManager.volumeClouds = fullVolumeCloudsSkyMaster;
|
|
}
|
|
else
|
|
{
|
|
fullVolumeCloudsSkyMaster = Camera.main.gameObject.AddComponent<FullVolumeCloudsSkyMaster>();
|
|
fullVolumeCloudsSkyMaster.Sun = SkyManager.SunObj.transform;
|
|
fullVolumeCloudsSkyMaster.SkyManager = SkyManager;
|
|
fullVolumeCloudsSkyMaster.initVariablesA();
|
|
fullVolumeCloudsSkyMaster.initVariablesScatter();
|
|
SkyManager.volumeClouds = fullVolumeCloudsSkyMaster;
|
|
}
|
|
fullVolumeCloudsSkyMaster._SampleCount0 = 11f;
|
|
if (Camera.main.gameObject.GetComponent<TemporalReprojection>() == null)
|
|
{
|
|
Camera.main.gameObject.AddComponent<TemporalReprojection>();
|
|
}
|
|
FullVolumeCloudsSkyMaster volumeClouds = SkyManager.volumeClouds;
|
|
int num = LayerMask.NameToLayer("Background");
|
|
if (volumeClouds != null)
|
|
{
|
|
if (SkyManager.water != null)
|
|
{
|
|
if (volumeClouds.reflectClouds == null)
|
|
{
|
|
if (enableWater)
|
|
{
|
|
SkyManager.water.transform.parent.gameObject.SetActive(value: true);
|
|
SkyManager.water.GetComponent<PlanarReflectionSM>().enabled = true;
|
|
if (Camera.main != null && Camera.main.gameObject.GetComponent<UnderWaterImageEffect>() == null)
|
|
{
|
|
Camera.main.gameObject.AddComponent<UnderWaterImageEffect>();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Add a main camera first");
|
|
}
|
|
}
|
|
if (SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut != null && SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.GetComponent<FullVolumeCloudsSkyMaster>() != null)
|
|
{
|
|
FullVolumeCloudsSkyMaster component = SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.GetComponent<FullVolumeCloudsSkyMaster>();
|
|
volumeClouds.updateReflectionCamera = true;
|
|
volumeClouds.reflectClouds = component;
|
|
Debug.Log("Cloud script found on reflection camera, adding auto update based on main clouds system");
|
|
volumeClouds.reflectClouds.startDistance = 1E+10f;
|
|
volumeClouds.reflectClouds.Sun = volumeClouds.Sun;
|
|
component.backgroundCam = volumeClouds.backgroundCam;
|
|
}
|
|
else if (SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut != null)
|
|
{
|
|
volumeClouds.updateReflectionCamera = true;
|
|
volumeClouds.updateReflections();
|
|
volumeClouds.reflectClouds._HorizonYAdjust = -500f;
|
|
volumeClouds.reflectClouds._FarDist = volumeClouds._FarDist / 2f;
|
|
volumeClouds.reflectClouds.isForReflections = true;
|
|
SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.cullingMask &= ~(1 << num);
|
|
PlanarReflectionSM component2 = SkyManager.water.GetComponent<PlanarReflectionSM>();
|
|
component2.reflectionMask = (int)component2.reflectionMask & ~(1 << num);
|
|
volumeClouds.reflectClouds.startDistance = 1E+10f;
|
|
volumeClouds.reflectClouds.Sun = volumeClouds.Sun;
|
|
volumeClouds.reflectClouds.backgroundCam = volumeClouds.backgroundCam;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No reflection camera in scene, please enable the water and Planer reflection script components.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Reflection cloud script already setup on reflect camera");
|
|
volumeClouds.updateReflectionCamera = true;
|
|
volumeClouds.updateReflections();
|
|
volumeClouds.reflectClouds.isForReflections = true;
|
|
SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.cullingMask &= ~(1 << num);
|
|
PlanarReflectionSM component3 = SkyManager.water.GetComponent<PlanarReflectionSM>();
|
|
component3.reflectionMask = (int)component3.reflectionMask & ~(1 << num);
|
|
volumeClouds.reflectClouds.startDistance = 1E+10f;
|
|
volumeClouds.reflectClouds.Sun = volumeClouds.Sun;
|
|
volumeClouds.reflectClouds.backgroundCam = volumeClouds.backgroundCam;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No Water in scene, please add water component first in Water section");
|
|
}
|
|
if (volumeClouds != null && volumeClouds.shadowDome == null)
|
|
{
|
|
volumeClouds.setupShadows = true;
|
|
volumeClouds.createShadowDome();
|
|
volumeClouds.shadowsUpdate();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Shadows already setup");
|
|
}
|
|
if (num > -1)
|
|
{
|
|
if (volumeClouds != null && volumeClouds.backgroundCam == null)
|
|
{
|
|
volumeClouds.setupDepth = true;
|
|
volumeClouds.createDepthSetup();
|
|
volumeClouds.setupDepth = true;
|
|
volumeClouds.blendBackground = true;
|
|
volumeClouds.reflectClouds.backgroundCam = volumeClouds.backgroundCam;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Depth camera already setup");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Please add the Background layer to proceed with the setup");
|
|
}
|
|
if (volumeClouds != null && volumeClouds.LightningBox == null)
|
|
{
|
|
volumeClouds.setupLightning = true;
|
|
volumeClouds.createLightningBox();
|
|
volumeClouds.EnableLightning = true;
|
|
volumeClouds.lightning_every = 5f;
|
|
volumeClouds.max_lightning_time = 9f;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Lightning components already setup");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No Clouds");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CloudScript cloudScript = Camera.main.gameObject.GetComponent<CloudScript>();
|
|
if (cloudScript != null)
|
|
{
|
|
cloudScript.sunLight = SkyManager.SUN_LIGHT.GetComponent<Light>();
|
|
}
|
|
else
|
|
{
|
|
cloudScript = Camera.main.gameObject.AddComponent<CloudScript>();
|
|
cloudScript.sunLight = SkyManager.SUN_LIGHT.GetComponent<Light>();
|
|
}
|
|
if (cloudScript != null && cloudScript.gameObject.GetComponent<lightningCameraVolumeCloudsSM_SRP>() == null)
|
|
{
|
|
lightningCameraVolumeCloudsSM_SRP obj2 = cloudScript.gameObject.AddComponent<lightningCameraVolumeCloudsSM_SRP>();
|
|
obj2.SkyManager = SkyManager;
|
|
obj2.fullvolumeCloudsScript = cloudScript;
|
|
obj2.setupLightning = true;
|
|
obj2.createLightningBox();
|
|
obj2.EnableLightning = true;
|
|
obj2.lightning_every = 5f;
|
|
obj2.max_lightning_time = 9f;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Lightning components already setup");
|
|
}
|
|
if (SkyManager.water != null)
|
|
{
|
|
if (SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut != null && SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.GetComponent<CloudScript>() == null)
|
|
{
|
|
if (enableWater)
|
|
{
|
|
SkyManager.water.transform.parent.gameObject.SetActive(value: true);
|
|
SkyManager.water.GetComponent<PlanarReflectionSM>().enabled = true;
|
|
if (Camera.main != null && Camera.main.gameObject.GetComponent<UnderWaterImageEffect>() == null)
|
|
{
|
|
Camera.main.gameObject.AddComponent<UnderWaterImageEffect>();
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Add a main camera first");
|
|
}
|
|
}
|
|
if (SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut != null)
|
|
{
|
|
CloudScript cloudScript2 = SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.gameObject.AddComponent<CloudScript>();
|
|
cloudScript2.renderInFront = 0;
|
|
cloudScript2.planetSize = cloudScript.planetSize;
|
|
cloudScript2.planetZeroCoordinate.y = 0f;
|
|
cloudScript2.sunLight = cloudScript.sunLight;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No reflection camera in scene, please enable the water and Planer reflection script components.");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("Reflection cloud script already setup on reflect camera");
|
|
CloudScript component4 = SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.gameObject.GetComponent<CloudScript>();
|
|
component4.renderInFront = 0;
|
|
component4.planetSize = cloudScript.planetSize;
|
|
component4.planetZeroCoordinate.y = 0f;
|
|
component4.sunLight = cloudScript.sunLight;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No Water in scene, please add water component first in Water section");
|
|
}
|
|
if (sunController != null && addSmoothSun)
|
|
{
|
|
sunController.fullVolumeClouds = cloudScript;
|
|
sunController.lightningController = cloudScript.gameObject.GetComponent<lightningCameraVolumeCloudsSM_SRP>();
|
|
sunController.enabled = true;
|
|
}
|
|
}
|
|
SeasonalTerrainSKYMASTER component5 = SkyManager.gameObject.GetComponent<SeasonalTerrainSKYMASTER>();
|
|
if (Camera.main != null && Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>() == null)
|
|
{
|
|
Camera.main.gameObject.AddComponent<GlobalFogSkyMaster>();
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().SkyManager = SkyManager;
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().Sun = SkyManager.SUN_LIGHT.transform;
|
|
component5.Lerp_gradient = true;
|
|
component5.ImageEffectFog = true;
|
|
component5.FogHeightByTerrain = true;
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().heightDensity = 0.0001f;
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().height = 400f;
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().distanceFog = false;
|
|
}
|
|
else
|
|
{
|
|
if (Camera.main == null)
|
|
{
|
|
Debug.Log("Add a main camera first");
|
|
}
|
|
if (Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>() != null)
|
|
{
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().SkyManager = SkyManager;
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().Sun = SkyManager.SUN_LIGHT.transform;
|
|
component5.Lerp_gradient = true;
|
|
component5.ImageEffectFog = true;
|
|
component5.FogHeightByTerrain = true;
|
|
}
|
|
}
|
|
if (sunController != null && addSmoothSun)
|
|
{
|
|
sunController.etherealVolFog = Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>();
|
|
}
|
|
component5.setVFogCurvesPresetE();
|
|
if (Camera.main != null && Camera.main.gameObject.GetComponent<SunShaftsSkyMaster>() == null)
|
|
{
|
|
Camera.main.gameObject.AddComponent<SunShaftsSkyMaster>();
|
|
Camera.main.gameObject.GetComponent<SunShaftsSkyMaster>().sunTransform = SkyManager.SunObj.transform;
|
|
component5.ImageEffectShafts = true;
|
|
}
|
|
else
|
|
{
|
|
if (Camera.main == null)
|
|
{
|
|
Debug.Log("Add a main camera first");
|
|
}
|
|
if (Camera.main.gameObject.GetComponent<SunShaftsSkyMaster>() != null)
|
|
{
|
|
Camera.main.gameObject.GetComponent<SunShaftsSkyMaster>().sunTransform = SkyManager.SunObj.transform;
|
|
component5.ImageEffectShafts = true;
|
|
}
|
|
}
|
|
}
|
|
CloudScript component6 = Camera.main.gameObject.GetComponent<CloudScript>();
|
|
if (component6 != null && component6.weatherTexture == null)
|
|
{
|
|
component6.weatherTexture = (Texture2D)Resources.Load("weather3");
|
|
component6.blueNoiseTexture = (Texture2D)Resources.Load("blueNoise");
|
|
component6.curlNoise = (Texture2D)Resources.Load("curlNoise");
|
|
component6.lowFreqNoise = (TextAsset)Resources.Load("noiseShapePacked");
|
|
component6.highFreqNoise = (TextAsset)Resources.Load("noiseErosionPacked");
|
|
component6.cloudsHighTexture = (Texture2D)Resources.Load("wispyClouds1");
|
|
Camera.main.gameObject.GetComponent<VelocityBuffer>().velocityShader = (Shader)Resources.Load("VelocityBuffer");
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().fogShader = (Shader)Resources.Load("GlobalFogSkyMaster");
|
|
SunShaftsSkyMaster component7 = Camera.main.gameObject.GetComponent<SunShaftsSkyMaster>();
|
|
component7.sunShaftsShader = (Shader)Resources.Load("SunShaftsCompositeSM");
|
|
component7.simpleClearShader = (Shader)Resources.Load("SimpleClearSM");
|
|
}
|
|
base.transform.position = Vector3.zero;
|
|
if (addFullVolumeClouds)
|
|
{
|
|
SkyManager.Current_Time = 13.2f;
|
|
}
|
|
if (addFullVolumeClouds && weatherTexture != null)
|
|
{
|
|
weatherTexture.clouds = Camera.main.gameObject.GetComponent<CloudScript>();
|
|
if (enableWater && SkyManager.water != null)
|
|
{
|
|
CloudScript component8 = SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.gameObject.GetComponent<CloudScript>();
|
|
if (component8 != null)
|
|
{
|
|
weatherTexture.cloudsREFL = component8;
|
|
}
|
|
}
|
|
weatherTexture.enabled = true;
|
|
weatherTexture.gameObject.SetActive(value: true);
|
|
}
|
|
if (sunController != null && addSmoothSun)
|
|
{
|
|
Camera.main.gameObject.GetComponent<GlobalFogSkyMaster>().Sun = sunController.temporalSunMoon.transform;
|
|
Camera.main.gameObject.GetComponent<CloudScript>().sunLight = sunController.temporalSunMoon.GetComponent<Light>();
|
|
if (enableWater && SkyManager.water != null)
|
|
{
|
|
CloudScript component9 = SkyManager.water.GetComponent<PlanarReflectionSM>().m_ReflectionCameraOut.gameObject.GetComponent<CloudScript>();
|
|
if (component9 != null)
|
|
{
|
|
sunController.fullVolumeCloudsREFL = component9;
|
|
}
|
|
}
|
|
}
|
|
if (Camera.main.transform.eulerAngles.x == 0f && Camera.main.transform.eulerAngles.y == 0f && Camera.main.transform.eulerAngles.z == 0f)
|
|
{
|
|
Camera.main.transform.eulerAngles = new Vector3(0.04f, 0f, 0f);
|
|
}
|
|
configured = true;
|
|
base.enabled = false;
|
|
}
|
|
}
|
|
}
|