mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Added atmo colour + improved star lighting
Only missing proper shader settings
This commit is contained in:
parent
4cac4e7641
commit
2c3436b303
@ -6,7 +6,7 @@ namespace NewHorizons.Atmosphere
|
|||||||
{
|
{
|
||||||
static class AtmosphereBuilder
|
static class AtmosphereBuilder
|
||||||
{
|
{
|
||||||
public static void Make(GameObject body, AtmosphereModule atmosphereModule)
|
public static void Make(GameObject body, AtmosphereModule atmosphereModule, float surfaceSize)
|
||||||
{
|
{
|
||||||
GameObject atmoGO = new GameObject("Atmosphere");
|
GameObject atmoGO = new GameObject("Atmosphere");
|
||||||
atmoGO.SetActive(false);
|
atmoGO.SetActive(false);
|
||||||
@ -14,66 +14,19 @@ namespace NewHorizons.Atmosphere
|
|||||||
|
|
||||||
if (atmosphereModule.HasAtmosphere)
|
if (atmosphereModule.HasAtmosphere)
|
||||||
{
|
{
|
||||||
var mat = GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere/Atmosphere_LOD0").GetComponent<MeshRenderer>().material;
|
GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"));
|
||||||
|
|
||||||
GameObject atmo = GameObject.Instantiate(GameObject.Find("Atmosphere_TH/AtmoSphere"));
|
|
||||||
atmo.transform.parent = atmoGO.transform;
|
atmo.transform.parent = atmoGO.transform;
|
||||||
atmo.transform.localPosition = Vector3.zero;
|
atmo.transform.localPosition = Vector3.zero;
|
||||||
atmo.transform.localScale = Vector3.one * atmosphereModule.Size;
|
atmo.transform.localScale = Vector3.one * atmosphereModule.Size * 1.2f;
|
||||||
|
foreach(var meshRenderer in atmo.GetComponentsInChildren<MeshRenderer>())
|
||||||
|
{
|
||||||
|
meshRenderer.material.SetFloat("_InnerRadius", atmosphereModule.Cloud != null ? atmosphereModule.Size : surfaceSize);
|
||||||
|
meshRenderer.material.SetFloat("_OuterRadius", atmosphereModule.Size * 1.2f);
|
||||||
|
if(atmosphereModule.AtmosphereTint != null)
|
||||||
|
meshRenderer.material.SetColor("_SkyColor", atmosphereModule.AtmosphereTint.ToColor32());
|
||||||
|
}
|
||||||
|
|
||||||
atmo.SetActive(true);
|
atmo.SetActive(true);
|
||||||
|
|
||||||
/*
|
|
||||||
GameObject lod0 = new GameObject();
|
|
||||||
lod0.transform.parent = atmo.transform;
|
|
||||||
lod0.transform.localPosition = Vector3.zero;
|
|
||||||
MeshFilter f0 = lod0.AddComponent<MeshFilter>();
|
|
||||||
f0.mesh = GameObject.Find("Atmosphere_LOD0").GetComponent<MeshFilter>().mesh;
|
|
||||||
MeshRenderer r0 = lod0.AddComponent<MeshRenderer>();
|
|
||||||
r0.material = mat;
|
|
||||||
|
|
||||||
GameObject lod1 = new GameObject();
|
|
||||||
lod1.transform.parent = atmo.transform;
|
|
||||||
lod1.transform.localPosition = Vector3.zero;
|
|
||||||
MeshFilter f1 = lod1.AddComponent<MeshFilter>();
|
|
||||||
f1.mesh = GameObject.Find("Atmosphere_LOD1").GetComponent<MeshFilter>().mesh;
|
|
||||||
MeshRenderer r1 = lod1.AddComponent<MeshRenderer>();
|
|
||||||
r1.material = mat;
|
|
||||||
|
|
||||||
GameObject lod2 = new GameObject();
|
|
||||||
lod2.transform.parent = atmo.transform;
|
|
||||||
lod2.transform.localPosition = Vector3.zero;
|
|
||||||
MeshFilter f2 = lod2.AddComponent<MeshFilter>();
|
|
||||||
f2.mesh = GameObject.Find("Atmosphere_LOD2").GetComponent<MeshFilter>().mesh;
|
|
||||||
MeshRenderer r2 = lod2.AddComponent<MeshRenderer>();
|
|
||||||
r2.material = mat;
|
|
||||||
|
|
||||||
GameObject lod3 = new GameObject();
|
|
||||||
lod3.transform.parent = atmo.transform;
|
|
||||||
lod3.transform.localPosition = Vector3.zero;
|
|
||||||
MeshFilter f3 = lod3.AddComponent<MeshFilter>();
|
|
||||||
f3.mesh = GameObject.Find("Atmosphere_LOD3").GetComponent<MeshFilter>().mesh;
|
|
||||||
MeshRenderer r3 = lod3.AddComponent<MeshRenderer>();
|
|
||||||
r3.material = mat;
|
|
||||||
|
|
||||||
LODGroup lodg = atmo.AddComponent<LODGroup>();
|
|
||||||
|
|
||||||
LOD[] lodlist = new LOD[4];
|
|
||||||
Renderer[] t0 = { r0 };
|
|
||||||
Renderer[] t1 = { r1 };
|
|
||||||
Renderer[] t2 = { r2 };
|
|
||||||
Renderer[] t3 = { r3 };
|
|
||||||
LOD one = new LOD(1, t0);
|
|
||||||
LOD two = new LOD(0.7f, t1);
|
|
||||||
LOD three = new LOD(0.27f, t2);
|
|
||||||
LOD four = new LOD(0.08f, t3);
|
|
||||||
lodlist[0] = one;
|
|
||||||
lodlist[1] = two;
|
|
||||||
lodlist[2] = three;
|
|
||||||
lodlist[3] = four;
|
|
||||||
|
|
||||||
lodg.SetLODs(lodlist);
|
|
||||||
lodg.fadeMode = LODFadeMode.None;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
atmoGO.transform.localPosition = Vector3.zero;
|
atmoGO.transform.localPosition = Vector3.zero;
|
||||||
|
|||||||
@ -59,8 +59,6 @@ namespace NewHorizons.Builder.Body
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger.Log($"{config}");
|
|
||||||
|
|
||||||
var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets);
|
var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets);
|
||||||
Main.NextPassBodies.Add(asteroid);
|
Main.NextPassBodies.Add(asteroid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,79 +14,93 @@ namespace NewHorizons.Builder.Body
|
|||||||
static class StarBuilder
|
static class StarBuilder
|
||||||
{
|
{
|
||||||
private static Texture2D _colorOverTime;
|
private static Texture2D _colorOverTime;
|
||||||
public static void Make(GameObject body, Sector sector, StarModule starModule)
|
public static StarController Make(GameObject body, Sector sector, StarModule starModule)
|
||||||
{
|
{
|
||||||
if (_colorOverTime == null) _colorOverTime = Main.Instance.ModHelper.Assets.GetTexture("AssetBundle/StarColorOverTime.png");
|
if (_colorOverTime == null) _colorOverTime = Main.Instance.ModHelper.Assets.GetTexture("AssetBundle/StarColorOverTime.png");
|
||||||
|
|
||||||
var sunGO = new GameObject("Star");
|
var starGO = new GameObject("Star");
|
||||||
sunGO.transform.parent = body.transform;
|
starGO.transform.parent = body.transform;
|
||||||
|
|
||||||
var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), sunGO.transform);
|
var sunSurface = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Geometry_SUN/Surface"), starGO.transform);
|
||||||
sunSurface.transform.localPosition = Vector3.zero;
|
sunSurface.transform.localPosition = Vector3.zero;
|
||||||
sunSurface.transform.localScale = Vector3.one;
|
sunSurface.transform.localScale = Vector3.one;
|
||||||
sunSurface.name = "Surface";
|
sunSurface.name = "Surface";
|
||||||
|
|
||||||
//var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform);
|
//var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform);
|
||||||
var sunLight = new GameObject();
|
var sunLight = new GameObject();
|
||||||
sunLight.transform.parent = sunGO.transform;
|
sunLight.transform.parent = starGO.transform;
|
||||||
sunLight.transform.localPosition = Vector3.zero;
|
sunLight.transform.localPosition = Vector3.zero;
|
||||||
sunLight.transform.localScale = Vector3.one;
|
sunLight.transform.localScale = Vector3.one;
|
||||||
sunLight.name = "StarLight";
|
sunLight.name = "StarLight";
|
||||||
var light = sunLight.AddComponent<Light>();
|
var light = sunLight.AddComponent<Light>();
|
||||||
light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
light.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
|
||||||
|
light.intensity *= starModule.SolarLuminosity;
|
||||||
|
|
||||||
|
var faceActiveCamera = sunLight.AddComponent<FaceActiveCamera>();
|
||||||
|
faceActiveCamera.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<FaceActiveCamera>());
|
||||||
|
var csmTextureCacher = sunLight.AddComponent<CSMTextureCacher>();
|
||||||
|
csmTextureCacher.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<CSMTextureCacher>());
|
||||||
|
csmTextureCacher._light = light;
|
||||||
|
var proxyShadowLight = sunLight.AddComponent<ProxyShadowLight>();
|
||||||
|
proxyShadowLight.CopyPropertiesFrom(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>());
|
||||||
|
proxyShadowLight._light = light;
|
||||||
|
|
||||||
var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), sunGO.transform);
|
var solarFlareEmitter = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SolarFlareEmitter"), starGO.transform);
|
||||||
solarFlareEmitter.transform.localPosition = Vector3.zero;
|
solarFlareEmitter.transform.localPosition = Vector3.zero;
|
||||||
solarFlareEmitter.transform.localScale = Vector3.one;
|
solarFlareEmitter.transform.localScale = Vector3.one;
|
||||||
solarFlareEmitter.name = "SolarFlareEmitter";
|
solarFlareEmitter.name = "SolarFlareEmitter";
|
||||||
|
|
||||||
var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), sunGO.transform);
|
var sunAudio = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
|
||||||
sunAudio.transform.localPosition = Vector3.zero;
|
sunAudio.transform.localPosition = Vector3.zero;
|
||||||
sunAudio.transform.localScale = Vector3.one;
|
sunAudio.transform.localScale = Vector3.one;
|
||||||
sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.Size * 2f;
|
sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.Size * 2f;
|
||||||
sunAudio.name = "Audio_Star";
|
sunAudio.name = "Audio_Star";
|
||||||
|
|
||||||
var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), sunGO.transform);
|
var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), starGO.transform);
|
||||||
sunAtmosphere.transform.localPosition = Vector3.zero;
|
sunAtmosphere.transform.localPosition = Vector3.zero;
|
||||||
sunAtmosphere.transform.localScale = Vector3.one;
|
sunAtmosphere.transform.localScale = Vector3.one;
|
||||||
sunAtmosphere.name = "Atmosphere_Star";
|
sunAtmosphere.name = "Atmosphere_Star";
|
||||||
|
|
||||||
var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), sunGO.transform);
|
var ambientLightGO = GameObject.Instantiate(GameObject.Find("Sun_Body/AmbientLight_SUN"), starGO.transform);
|
||||||
ambientLightGO.transform.localPosition = Vector3.zero;
|
ambientLightGO.transform.localPosition = Vector3.zero;
|
||||||
ambientLightGO.name = "AmbientLight_Star";
|
ambientLightGO.name = "AmbientLight_Star";
|
||||||
|
|
||||||
var heatVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), sunGO.transform);
|
var heatVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/HeatVolume"), starGO.transform);
|
||||||
heatVolume.transform.localPosition = Vector3.zero;
|
heatVolume.transform.localPosition = Vector3.zero;
|
||||||
heatVolume.transform.localScale = Vector3.one;
|
heatVolume.transform.localScale = Vector3.one;
|
||||||
heatVolume.GetComponent<SphereShape>().radius = 1f;
|
heatVolume.GetComponent<SphereShape>().radius = 1f;
|
||||||
heatVolume.name = "HeatVolume";
|
heatVolume.name = "HeatVolume";
|
||||||
|
|
||||||
var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), sunGO.transform);
|
var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform);
|
||||||
deathVolume.transform.localPosition = Vector3.zero;
|
deathVolume.transform.localPosition = Vector3.zero;
|
||||||
deathVolume.transform.localScale = Vector3.one;
|
deathVolume.transform.localScale = Vector3.one;
|
||||||
deathVolume.GetComponent<SphereCollider>().radius = 1f;
|
deathVolume.GetComponent<SphereCollider>().radius = 1f;
|
||||||
deathVolume.name = "DestructionVolume";
|
deathVolume.name = "DestructionVolume";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
|
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
|
||||||
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
|
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
|
||||||
Light ambientLight = ambientLightGO.GetComponent<Light>();
|
Light ambientLight = ambientLightGO.GetComponent<Light>();
|
||||||
|
|
||||||
//GameObject.Destroy(sunLight.GetComponent<FaceActiveCamera>());
|
Color lightColour = light.color;
|
||||||
//GameObject.Destroy(sunLight.GetComponent<CSMTextureCacher>());
|
if (starModule.LightTint != null) lightColour = starModule.LightTint.ToColor32();
|
||||||
//GameObject.Destroy(sunLight.GetComponent<ProxyShadowLight>());
|
if (lightColour == null && starModule.Tint != null)
|
||||||
//SunLightController sunLightController = sunLight.GetComponent<SunLightController>();
|
{
|
||||||
//GameObject.Destroy(sunLight.GetComponent<SunLightParamUpdater>());
|
// Lighten it a bit
|
||||||
//GameObject.Destroy(sunLightController);
|
var r = Mathf.Clamp01(starModule.Tint.R * 1.5f / 255f);
|
||||||
|
var g = Mathf.Clamp01(starModule.Tint.G * 1.5f / 255f);
|
||||||
|
var b = Mathf.Clamp01(starModule.Tint.B * 1.5f / 255f);
|
||||||
|
lightColour = new Color(r, g, b);
|
||||||
|
}
|
||||||
|
if (lightColour != null) light.color = (Color)lightColour;
|
||||||
|
|
||||||
|
light.color = lightColour;
|
||||||
|
ambientLight.color = lightColour;
|
||||||
|
|
||||||
fog.fogRadius = starModule.Size * 1.2f;
|
fog.fogRadius = starModule.Size * 1.2f;
|
||||||
if(starModule.Tint != null)
|
if(starModule.Tint != null)
|
||||||
{
|
{
|
||||||
var colour = starModule.Tint.ToColor32();
|
var colour = starModule.Tint.ToColor32();
|
||||||
//sunLightController.sunColor = colour;
|
//sunLightController.sunColor = colour;
|
||||||
//ambientLight.color = colour;
|
|
||||||
fog.fogTint = colour;
|
fog.fogTint = colour;
|
||||||
|
|
||||||
var sun = GameObject.Find("Sun_Body");
|
var sun = GameObject.Find("Sun_Body");
|
||||||
@ -94,8 +108,9 @@ namespace NewHorizons.Builder.Body
|
|||||||
var giantMaterial = sun.GetComponent<SunController>().GetValue<Material>("_endSurfaceMaterial");
|
var giantMaterial = sun.GetComponent<SunController>().GetValue<Material>("_endSurfaceMaterial");
|
||||||
|
|
||||||
surface.sharedMaterial = new Material(starModule.Size >= 3000 ? giantMaterial : mainSequenceMaterial);
|
surface.sharedMaterial = new Material(starModule.Size >= 3000 ? giantMaterial : mainSequenceMaterial);
|
||||||
surface.sharedMaterial.color = new Color(colour.r * 8f / 255f, colour.g * 8f / 255f, colour.b * 8f / 255f);
|
var mod = 8f * starModule.SolarLuminosity / 255f;
|
||||||
surface.sharedMaterial.SetTexture("_ColorRamp", Utility.ImageUtilities.TintImage(_colorOverTime, colour));
|
surface.sharedMaterial.color = new Color(colour.r * mod, colour.g * mod, colour.b * mod);
|
||||||
|
surface.sharedMaterial.SetTexture("_ColorRamp", ImageUtilities.TintImage(_colorOverTime, colour));
|
||||||
|
|
||||||
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000)/starModule.Size;
|
sunAtmosphere.transform.Find("AtmoSphere").transform.localScale = Vector3.one * (starModule.Size + 1000)/starModule.Size;
|
||||||
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
|
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
|
||||||
@ -109,8 +124,19 @@ namespace NewHorizons.Builder.Body
|
|||||||
if(starModule.SolarFlareTint != null)
|
if(starModule.SolarFlareTint != null)
|
||||||
solarFlareEmitter.GetComponent<SolarFlareEmitter>().tint = starModule.SolarFlareTint.ToColor32();
|
solarFlareEmitter.GetComponent<SolarFlareEmitter>().tint = starModule.SolarFlareTint.ToColor32();
|
||||||
|
|
||||||
sunGO.transform.localPosition = Vector3.zero;
|
starGO.transform.localPosition = Vector3.zero;
|
||||||
sunGO.transform.localScale = starModule.Size * Vector3.one;
|
starGO.transform.localScale = starModule.Size * Vector3.one;
|
||||||
|
|
||||||
|
var starController = body.AddComponent<StarController>();
|
||||||
|
starController.Light = light;
|
||||||
|
starController.AmbientLight = ambientLight;
|
||||||
|
starController.FaceActiveCamera = faceActiveCamera;
|
||||||
|
starController.CSMTextureCacher = csmTextureCacher;
|
||||||
|
starController.ProxyShadowLight = proxyShadowLight;
|
||||||
|
starController.Intensity = starModule.SolarLuminosity;
|
||||||
|
starController.SunColor = lightColour;
|
||||||
|
|
||||||
|
return starController;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,8 +181,6 @@ namespace NewHorizons.Builder.General
|
|||||||
secondaryInitialMotion.SetValue("_initLinearDirection", d2);
|
secondaryInitialMotion.SetValue("_initLinearDirection", d2);
|
||||||
secondaryInitialMotion.SetValue("_initLinearSpeed", -v2);
|
secondaryInitialMotion.SetValue("_initLinearSpeed", -v2);
|
||||||
|
|
||||||
Logger.Log($"Velocity: {d1}, {v1}, {d2}, {v2}");
|
|
||||||
|
|
||||||
// InitialMotion already set its speed so we overwrite that
|
// InitialMotion already set its speed so we overwrite that
|
||||||
if (!primaryInitialMotion.GetValue<bool>("_isInitVelocityDirty"))
|
if (!primaryInitialMotion.GetValue<bool>("_isInitVelocityDirty"))
|
||||||
{
|
{
|
||||||
|
|||||||
1
NewHorizons/External/AtmosphereModule.cs
vendored
1
NewHorizons/External/AtmosphereModule.cs
vendored
@ -21,5 +21,6 @@ namespace NewHorizons.External
|
|||||||
public bool HasSnow { get; set; }
|
public bool HasSnow { get; set; }
|
||||||
public bool HasOxygen { get; set; }
|
public bool HasOxygen { get; set; }
|
||||||
public bool HasAtmosphere { get; set; }
|
public bool HasAtmosphere { get; set; }
|
||||||
|
public MColor32 AtmosphereTint { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
NewHorizons/External/StarModule.cs
vendored
4
NewHorizons/External/StarModule.cs
vendored
@ -9,10 +9,10 @@ namespace NewHorizons.External
|
|||||||
{
|
{
|
||||||
public class StarModule : Module
|
public class StarModule : Module
|
||||||
{
|
{
|
||||||
public float Size { get; set; }
|
public float Size { get; set; } = 2000f;
|
||||||
public MColor32 Tint { get; set; }
|
public MColor32 Tint { get; set; }
|
||||||
public MColor32 SolarFlareTint { get; set; }
|
public MColor32 SolarFlareTint { get; set; }
|
||||||
public MColor32 LightTint { get; set; }
|
public MColor32 LightTint { get; set; }
|
||||||
public float SolarLuminosity { get; set; }
|
public float SolarLuminosity { get; set; } = 1f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,8 @@ namespace NewHorizons
|
|||||||
|
|
||||||
public static float FurthestOrbit = 50000f;
|
public static float FurthestOrbit = 50000f;
|
||||||
|
|
||||||
|
private static StarLightController _starLightController;
|
||||||
|
|
||||||
public override object GetApi()
|
public override object GetApi()
|
||||||
{
|
{
|
||||||
return new NewHorizonsApi();
|
return new NewHorizonsApi();
|
||||||
@ -69,6 +71,34 @@ namespace NewHorizons
|
|||||||
|
|
||||||
if (scene.name != "SolarSystem") { return; }
|
if (scene.name != "SolarSystem") { return; }
|
||||||
|
|
||||||
|
// Need to manage this when there are multiple stars
|
||||||
|
var sun = GameObject.Find("Sun_Body");
|
||||||
|
var starController = sun.AddComponent<StarController>();
|
||||||
|
starController.Light = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>();
|
||||||
|
starController.AmbientLight = GameObject.Find("Sun_Body/AmbientLight_SUN").GetComponent<Light>();
|
||||||
|
starController.FaceActiveCamera = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<FaceActiveCamera>();
|
||||||
|
starController.CSMTextureCacher = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<CSMTextureCacher>();
|
||||||
|
starController.ProxyShadowLight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>();
|
||||||
|
starController.Intensity = 0.9859f;
|
||||||
|
starController.SunColor = new Color(1f, 0.8845f, 0.6677f, 1f);
|
||||||
|
|
||||||
|
var starLightGO = GameObject.Instantiate(sun.GetComponentInChildren<SunLightController>().gameObject);
|
||||||
|
foreach(var comp in starLightGO.GetComponents<Component>())
|
||||||
|
{
|
||||||
|
if(!(comp is SunLightController) && !(comp is SunLightParamUpdater) && !(comp is Light) && !(comp is Transform))
|
||||||
|
{
|
||||||
|
GameObject.Destroy(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameObject.Destroy(starLightGO.GetComponent<Light>());
|
||||||
|
starLightGO.name = "StarLightController";
|
||||||
|
|
||||||
|
_starLightController = starLightGO.AddComponent<StarLightController>();
|
||||||
|
_starLightController.AddStar(starController);
|
||||||
|
|
||||||
|
starLightGO.SetActive(true);
|
||||||
|
|
||||||
|
// TODO: Make this configurable probably
|
||||||
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>());
|
||||||
|
|
||||||
AstroObjectLocator.RefreshList();
|
AstroObjectLocator.RefreshList();
|
||||||
@ -77,7 +107,7 @@ namespace NewHorizons
|
|||||||
AstroObjectLocator.AddAstroObject(ao);
|
AstroObjectLocator.AddAstroObject(ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stars then planets then moons
|
// Stars then planets then moons (not necessary but probably speeds things up, maybe)
|
||||||
var toLoad = BodyList.OrderBy(b =>
|
var toLoad = BodyList.OrderBy(b =>
|
||||||
(b.Config.BuildPriority != -1 ? b.Config.BuildPriority :
|
(b.Config.BuildPriority != -1 ? b.Config.BuildPriority :
|
||||||
(b.Config.FocalPoint != null ? 0 :
|
(b.Config.FocalPoint != null ? 0 :
|
||||||
@ -85,10 +115,10 @@ namespace NewHorizons
|
|||||||
(b.Config.Orbit.IsMoon ? 2 : 1)
|
(b.Config.Orbit.IsMoon ? 2 : 1)
|
||||||
))).ToList();
|
))).ToList();
|
||||||
|
|
||||||
var count = 0;
|
var passCount = 0;
|
||||||
while (toLoad.Count != 0)
|
while (toLoad.Count != 0)
|
||||||
{
|
{
|
||||||
Logger.Log($"Starting body loading pass #{++count}");
|
Logger.Log($"Starting body loading pass #{++passCount}");
|
||||||
var flagNoneLoadedThisPass = true;
|
var flagNoneLoadedThisPass = true;
|
||||||
foreach (var body in toLoad)
|
foreach (var body in toLoad)
|
||||||
{
|
{
|
||||||
@ -114,7 +144,7 @@ namespace NewHorizons
|
|||||||
NextPassBodies = new List<NewHorizonsBody>();
|
NextPassBodies = new List<NewHorizonsBody>();
|
||||||
|
|
||||||
// Infinite loop failsafe
|
// Infinite loop failsafe
|
||||||
if (count > 10)
|
if (passCount > 10)
|
||||||
{
|
{
|
||||||
Logger.Log("Something went wrong");
|
Logger.Log("Something went wrong");
|
||||||
break;
|
break;
|
||||||
@ -180,7 +210,6 @@ namespace NewHorizons
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void LoadConfigs(IModBehaviour mod)
|
public void LoadConfigs(IModBehaviour mod)
|
||||||
{
|
{
|
||||||
var folder = mod.ModHelper.Manifest.ModFolderPath;
|
var folder = mod.ModHelper.Manifest.ModFolderPath;
|
||||||
@ -278,8 +307,7 @@ namespace NewHorizons
|
|||||||
if (body.Config.Base.BlackHoleSize != 0)
|
if (body.Config.Base.BlackHoleSize != 0)
|
||||||
BlackHoleBuilder.Make(go, body.Config.Base, sector);
|
BlackHoleBuilder.Make(go, body.Config.Base, sector);
|
||||||
|
|
||||||
if (body.Config.Star != null)
|
if (body.Config.Star != null) _starLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star));
|
||||||
StarBuilder.Make(go, sector, body.Config.Star);
|
|
||||||
|
|
||||||
if (body.Config.FocalPoint != null)
|
if (body.Config.FocalPoint != null)
|
||||||
FocalPointBuilder.Make(go, body.Config.FocalPoint);
|
FocalPointBuilder.Make(go, body.Config.FocalPoint);
|
||||||
@ -352,7 +380,7 @@ namespace NewHorizons
|
|||||||
if (body.Config.Atmosphere.FogSize != 0)
|
if (body.Config.Atmosphere.FogSize != 0)
|
||||||
FogBuilder.Make(go, sector, body.Config.Atmosphere);
|
FogBuilder.Make(go, sector, body.Config.Atmosphere);
|
||||||
|
|
||||||
AtmosphereBuilder.Make(go, body.Config.Atmosphere);
|
AtmosphereBuilder.Make(go, body.Config.Atmosphere, body.Config.Base.SurfaceSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.Config.Props != null)
|
if (body.Config.Props != null)
|
||||||
|
|||||||
@ -87,7 +87,14 @@ namespace NewHorizons.Utility
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
targetProperty.SetValue(destination, srcProp.GetValue(source, null), null);
|
targetProperty.SetValue(destination, srcProp.GetValue(source, null), null);
|
||||||
|
} catch(Exception)
|
||||||
|
{
|
||||||
|
Logger.LogWarning($"Couldn't copy property {targetProperty.Name} from {source} to {destination}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
NewHorizons/Utility/StarController.cs
Normal file
39
NewHorizons/Utility/StarController.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace NewHorizons.Utility
|
||||||
|
{
|
||||||
|
public class StarController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Light Light;
|
||||||
|
public Light AmbientLight;
|
||||||
|
public FaceActiveCamera FaceActiveCamera;
|
||||||
|
public CSMTextureCacher CSMTextureCacher;
|
||||||
|
public ProxyShadowLight ProxyShadowLight;
|
||||||
|
public float Intensity;
|
||||||
|
public Color SunColor;
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
Disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Disable()
|
||||||
|
{
|
||||||
|
if (FaceActiveCamera != null) FaceActiveCamera.enabled = false;
|
||||||
|
if (CSMTextureCacher != null) CSMTextureCacher.enabled = false;
|
||||||
|
if (ProxyShadowLight != null) ProxyShadowLight.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Enable()
|
||||||
|
{
|
||||||
|
if (FaceActiveCamera != null) FaceActiveCamera.enabled = true;
|
||||||
|
if (CSMTextureCacher != null) CSMTextureCacher.enabled = true;
|
||||||
|
if (ProxyShadowLight != null) ProxyShadowLight.enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
80
NewHorizons/Utility/StarLightController.cs
Normal file
80
NewHorizons/Utility/StarLightController.cs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
|
||||||
|
namespace NewHorizons.Utility
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(SunLightController))]
|
||||||
|
[RequireComponent(typeof(SunLightParamUpdater))]
|
||||||
|
public class StarLightController : MonoBehaviour
|
||||||
|
{
|
||||||
|
private List<StarController> _stars = new List<StarController>();
|
||||||
|
private StarController _activeStar;
|
||||||
|
|
||||||
|
private SunLightController _sunLightController;
|
||||||
|
private SunLightParamUpdater _sunLightParamUpdater;
|
||||||
|
|
||||||
|
public void Awake()
|
||||||
|
{
|
||||||
|
_sunLightController = GetComponent<SunLightController>();
|
||||||
|
_sunLightController.enabled = true;
|
||||||
|
_sunLightParamUpdater = GetComponent<SunLightParamUpdater>();
|
||||||
|
_sunLightParamUpdater._sunLightController = _sunLightController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddStar(StarController star)
|
||||||
|
{
|
||||||
|
Logger.Log($"Adding new star to list: {star.gameObject.name}");
|
||||||
|
_stars.Add(star);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
// Player is always at 0,0,0 more or less
|
||||||
|
|
||||||
|
if (_activeStar == null && _stars.Count > 0)
|
||||||
|
{
|
||||||
|
ChangeActiveStar(_stars[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var star in _stars)
|
||||||
|
{
|
||||||
|
if (star != null && star.transform.position.sqrMagnitude < _activeStar.transform.position.sqrMagnitude)
|
||||||
|
{
|
||||||
|
ChangeActiveStar(star);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ChangeActiveStar(StarController star)
|
||||||
|
{
|
||||||
|
if (_sunLightController == null || _sunLightParamUpdater == null) return;
|
||||||
|
|
||||||
|
if(_activeStar != null) _activeStar.Disable();
|
||||||
|
|
||||||
|
Logger.Log($"Switching active star: {star.gameObject.name}");
|
||||||
|
|
||||||
|
_activeStar = star;
|
||||||
|
|
||||||
|
star.Enable();
|
||||||
|
|
||||||
|
_sunLightController._sunBaseColor = star.SunColor;
|
||||||
|
_sunLightController._sunBaseIntensity = star.Intensity;
|
||||||
|
_sunLightController._sunLight = star.Light;
|
||||||
|
_sunLightController._ambientLight = star.AmbientLight;
|
||||||
|
|
||||||
|
_sunLightParamUpdater.sunLight = star.Light;
|
||||||
|
_sunLightParamUpdater._sunController = star.transform.GetComponent<SunController>();
|
||||||
|
|
||||||
|
// For the param thing to work it wants this to be on the star idk
|
||||||
|
this.transform.parent = star.transform;
|
||||||
|
this.transform.localPosition = Vector3.zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user