This commit is contained in:
Nick J. Connors 2021-12-31 15:59:36 -05:00
commit 8af7a7a75b
19 changed files with 415 additions and 176 deletions

View File

@ -6,7 +6,7 @@ namespace NewHorizons.Atmosphere
{
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");
atmoGO.SetActive(false);
@ -14,66 +14,19 @@ namespace NewHorizons.Atmosphere
if (atmosphereModule.HasAtmosphere)
{
var mat = GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere/Atmosphere_LOD0").GetComponent<MeshRenderer>().material;
GameObject atmo = GameObject.Instantiate(GameObject.Find("Atmosphere_TH/AtmoSphere"));
GameObject atmo = GameObject.Instantiate(GameObject.Find("TimberHearth_Body/Atmosphere_TH/AtmoSphere"));
atmo.transform.parent = atmoGO.transform;
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);
/*
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;

View File

@ -59,8 +59,6 @@ namespace NewHorizons.Builder.Body
}
};
Logger.Log($"{config}");
var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets);
Main.NextPassBodies.Add(asteroid);
}

View File

@ -14,79 +14,97 @@ namespace NewHorizons.Builder.Body
static class StarBuilder
{
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");
var sunGO = new GameObject("Star");
sunGO.transform.parent = body.transform;
var starGO = new GameObject("Star");
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.localScale = Vector3.one;
sunSurface.name = "Surface";
//var sunLight = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight"), sunGO.transform);
var sunLight = new GameObject();
sunLight.transform.parent = sunGO.transform;
sunLight.transform.parent = starGO.transform;
sunLight.transform.localPosition = Vector3.zero;
sunLight.transform.localScale = Vector3.one;
sunLight.name = "StarLight";
var light = sunLight.AddComponent<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.localScale = Vector3.one;
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.localScale = Vector3.one;
sunAudio.transform.Find("SurfaceAudio_Sun").GetComponent<AudioSource>().maxDistance = starModule.Size * 2f;
var surfaceAudio = sunAudio.GetComponentInChildren<SunSurfaceAudioController>();
surfaceAudio.SetSector(sector);
surfaceAudio._sunController = null;
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.localScale = Vector3.one;
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.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.localScale = Vector3.one;
heatVolume.GetComponent<SphereShape>().radius = 1f;
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.localScale = Vector3.one;
deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.name = "DestructionVolume";
PlanetaryFogController fog = sunAtmosphere.transform.Find("FogSphere").GetComponent<PlanetaryFogController>();
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();
Light ambientLight = ambientLightGO.GetComponent<Light>();
//GameObject.Destroy(sunLight.GetComponent<FaceActiveCamera>());
//GameObject.Destroy(sunLight.GetComponent<CSMTextureCacher>());
//GameObject.Destroy(sunLight.GetComponent<ProxyShadowLight>());
//SunLightController sunLightController = sunLight.GetComponent<SunLightController>();
//GameObject.Destroy(sunLight.GetComponent<SunLightParamUpdater>());
//GameObject.Destroy(sunLightController);
Color lightColour = light.color;
if (starModule.LightTint != null) lightColour = starModule.LightTint.ToColor32();
if (lightColour == null && starModule.Tint != null)
{
// Lighten it a bit
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;
if(starModule.Tint != null)
{
var colour = starModule.Tint.ToColor32();
//sunLightController.sunColor = colour;
//ambientLight.color = colour;
fog.fogTint = colour;
var sun = GameObject.Find("Sun_Body");
@ -94,8 +112,9 @@ namespace NewHorizons.Builder.Body
var giantMaterial = sun.GetComponent<SunController>().GetValue<Material>("_endSurfaceMaterial");
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);
surface.sharedMaterial.SetTexture("_ColorRamp", Utility.ImageUtilities.TintImage(_colorOverTime, colour));
var mod = 8f * starModule.SolarLuminosity / 255f;
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;
foreach (var lod in sunAtmosphere.transform.Find("AtmoSphere").GetComponentsInChildren<MeshRenderer>())
@ -109,8 +128,19 @@ namespace NewHorizons.Builder.Body
if(starModule.SolarFlareTint != null)
solarFlareEmitter.GetComponent<SolarFlareEmitter>().tint = starModule.SolarFlareTint.ToColor32();
sunGO.transform.localPosition = Vector3.zero;
sunGO.transform.localScale = starModule.Size * Vector3.one;
starGO.transform.localPosition = Vector3.zero;
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;
}
}
}

View File

@ -10,7 +10,7 @@ namespace NewHorizons.Builder.General
{
static class BaseBuilder
{
public static Tuple<AstroObject, OWRigidbody> Make(GameObject body, AstroObject primaryBody, Vector3 positionVector, IPlanetConfig config)
public static Tuple<AstroObject, OWRigidbody> Make(GameObject body, AstroObject primaryBody, IPlanetConfig config)
{
Rigidbody rigidBody = body.AddComponent<Rigidbody>();
rigidBody.mass = 10000;

View File

@ -181,8 +181,6 @@ namespace NewHorizons.Builder.General
secondaryInitialMotion.SetValue("_initLinearDirection", d2);
secondaryInitialMotion.SetValue("_initLinearSpeed", -v2);
Logger.Log($"Velocity: {d1}, {v1}, {d2}, {v2}");
// InitialMotion already set its speed so we overwrite that
if (!primaryInitialMotion.GetValue<bool>("_isInitVelocityDirty"))
{

View File

@ -8,7 +8,7 @@ namespace NewHorizons.Builder.General
{
static class GravityBuilder
{
public static void Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType)
public static GravityVolume Make(GameObject body, AstroObject ao, float surfaceAccel, float sphereOfInfluence, float surface, string falloffType)
{
GameObject gravityGO = new GameObject("GravityWell");
gravityGO.transform.parent = body.transform;
@ -42,6 +42,8 @@ namespace NewHorizons.Builder.General
gravityGO.SetActive(true);
ao.SetValue("_gravityVolume", GV);
return GV;
}
}
}

View File

@ -49,17 +49,17 @@ namespace NewHorizons.Builder.General
if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin)
{
if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin)
GameObject.Find("TimeLoopRing_Body").SetActive(false);
var focalBody = GameObject.Find("FocalBody");
if (focalBody != null) focalBody.SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite)
else if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite)
{
var msb = GameObject.Find("MapSatellite_Body");
if (msb != null) msb.SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin)
GameObject.Find("TimeLoopRing_Body").SetActive(false);
if (ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon)
else if(ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon)
{
GameObject.Find("NomaiProbe_Body").SetActive(false);
GameObject.Find("CannonMuzzle_Body").SetActive(false);
@ -68,11 +68,11 @@ namespace NewHorizons.Builder.General
GameObject.Find("FakeCannonBarrel_Body (1)").SetActive(false);
GameObject.Find("Debris_Body (1)").SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.SunStation)
else if(ao.GetAstroObjectName() == AstroObject.Name.SunStation)
{
GameObject.Find("SS_Debris_Body").SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep)
else if(ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep)
{
GameObject.Find("BrambleIsland_Body").SetActive(false);
GameObject.Find("GabbroIsland_Body").SetActive(false);
@ -80,15 +80,41 @@ namespace NewHorizons.Builder.General
GameObject.Find("StatueIsland_Body").SetActive(false);
GameObject.Find("ConstructionYardIsland_Body").SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.WhiteHole)
else if(ao.GetAstroObjectName() == AstroObject.Name.WhiteHole)
{
GameObject.Find("WhiteholeStation_Body").SetActive(false);
GameObject.Find("WhiteholeStationSuperstructure_Body").SetActive(false);
}
if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth)
else if(ao.GetAstroObjectName() == AstroObject.Name.TimberHearth)
{
GameObject.Find("MiningRig_Body").SetActive(false);
}
else if(ao.GetAstroObjectName() == AstroObject.Name.Sun)
{
var starController = ao.gameObject.GetComponent<StarController>();
Main.Instance.StarLightController.RemoveStar(starController);
GameObject.Destroy(starController);
var audio = ao.GetComponentInChildren<SunSurfaceAudioController>();
GameObject.Destroy(audio);
foreach(var owAudioSource in ao.GetComponentsInChildren<OWAudioSource>())
{
owAudioSource.Stop();
GameObject.Destroy(owAudioSource);
}
foreach (var audioSource in ao.GetComponentsInChildren<AudioSource>())
{
audioSource.Stop();
GameObject.Destroy(audioSource);
}
}
else if(ao.GetAstroObjectName() == AstroObject.Name.DreamWorld)
{
GameObject.Find("BackRaft_Body").SetActive(false);
GameObject.Find("SealRaft_Body").SetActive(false);
}
// Deal with proxies
foreach (var p in GameObject.FindObjectsOfType<ProxyOrbiter>())

View File

@ -13,15 +13,15 @@ namespace NewHorizons.Builder.Props
{
public static class PropBuilder
{
public static void Make(GameObject body, string propToClone, Vector3 position, Sector sector)
public static GameObject Make(GameObject body, string propToClone, Vector3 position, Sector sector)
{
var prefab = GameObject.Find(propToClone);
Make(body, prefab, position, sector);
return Make(body, prefab, position, sector);
}
public static void Make(GameObject body, GameObject prefab, Vector3 position, Sector sector)
public static GameObject Make(GameObject body, GameObject prefab, Vector3 position, Sector sector)
{
if (prefab == null) return;
if (prefab == null) return null;
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
prop.transform.localPosition = position;
@ -43,7 +43,6 @@ namespace NewHorizons.Builder.Props
sector.OnOccupantEnterSector += ((SectorDetector sd) => StreamingManager.LoadStreamingAssets(assetBundle));
}
/*
foreach(var component in prop.GetComponentsInChildren<Component>())
{
try
@ -61,25 +60,13 @@ namespace NewHorizons.Builder.Props
Logger.Log($"Found a _sector field in {component}");
sectorField.SetValue(component, sector);
}
else
{
if(component is Campfire)
{
Logger.Log("CAMPFIRE");
Campfire campfire = component as Campfire;
if (campfire._sector != null)
campfire._sector.OnSectorOccupantsUpdated -= campfire.OnSectorOccupantsUpdated;
campfire._sector = sector;
campfire._sector.OnSectorOccupantsUpdated += campfire.OnSectorOccupantsUpdated;
}
}
}
catch (Exception e) { Logger.Log($"{e.Message}, {e.StackTrace}"); }
}
*/
prop.SetActive(true);
return prop;
}
public static void Scatter(GameObject body, PropModule.ScatterInfo[] scatterInfo, float radius, Sector sector)
@ -87,14 +74,16 @@ namespace NewHorizons.Builder.Props
var area = 4f * Mathf.PI * radius * radius;
var points = FibonacciSphere((int)area);
foreach (var scatterer in scatterInfo)
foreach (var propInfo in scatterInfo)
{
var prefab = GameObject.Find(scatterer.path);
for(int i = 0; i < scatterer.count; i++)
var prefab = GameObject.Find(propInfo.path);
for(int i = 0; i < propInfo.count; i++)
{
var randomInd = (int)Random.Range(0, points.Count);
var point = points[randomInd];
Make(body, prefab, point.normalized * radius, sector);
var prop = Make(body, prefab, point.normalized * radius, sector);
if(propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
if(propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation);
points.RemoveAt(randomInd);
if (points.Count == 0) return;
}

View File

@ -21,5 +21,6 @@ namespace NewHorizons.External
public bool HasSnow { get; set; }
public bool HasOxygen { get; set; }
public bool HasAtmosphere { get; set; }
public MColor32 AtmosphereTint { get; set; }
}
}

View File

@ -16,6 +16,8 @@ namespace NewHorizons.External
{
public string path;
public int count;
public MVector3 offset;
public MVector3 rotation;
}
}
}

View File

@ -9,10 +9,10 @@ namespace NewHorizons.External
{
public class StarModule : Module
{
public float Size { get; set; }
public float Size { get; set; } = 2000f;
public MColor32 Tint { get; set; }
public MColor32 SolarFlareTint { get; set; }
public MColor32 LightTint { get; set; }
public float SolarLuminosity { get; set; }
public float SolarLuminosity { get; set; } = 1f;
}
}

View File

@ -32,6 +32,8 @@ namespace NewHorizons
public static float FurthestOrbit = 50000f;
public StarLightController StarLightController { get; private set; }
public override object GetApi()
{
return new NewHorizonsApi();
@ -51,7 +53,7 @@ namespace NewHorizons
{
LoadConfigs(this);
}
catch(Exception)
catch (Exception)
{
Logger.LogWarning("Couldn't find planets folder");
}
@ -65,18 +67,47 @@ namespace NewHorizons
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Logger.Log($"Scene Loaded: {scene} {mode}");
if (scene.name != "SolarSystem") return;
Logger.Log($"Scene Loaded: {scene.name} {mode}");
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>());
AstroObjectLocator.RefreshList();
foreach(AstroObject ao in GameObject.FindObjectsOfType<AstroObject>())
foreach (AstroObject ao in GameObject.FindObjectsOfType<AstroObject>())
{
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 =>
(b.Config.BuildPriority != -1 ? b.Config.BuildPriority :
(b.Config.FocalPoint != null ? 0 :
@ -84,33 +115,44 @@ namespace NewHorizons
(b.Config.Orbit.IsMoon ? 2 : 1)
))).ToList();
var flagNoneLoadedThisPass = true;
while(toLoad.Count != 0)
var passCount = 0;
while (toLoad.Count != 0)
{
Logger.Log($"Starting body loading pass #{++passCount}");
var flagNoneLoadedThisPass = true;
foreach (var body in toLoad)
{
if (LoadBody(body))
flagNoneLoadedThisPass = false;
if (LoadBody(body)) flagNoneLoadedThisPass = false;
}
if (flagNoneLoadedThisPass)
{
Logger.LogWarning("No objects were loaded this pass");
// Try again but default to sun
foreach(var body in toLoad)
foreach (var body in toLoad)
{
if (LoadBody(body, true))
flagNoneLoadedThisPass = false;
}
if(flagNoneLoadedThisPass)
{
// Give up
Logger.Log($"Couldn't finish adding bodies.");
return;
if (LoadBody(body, true)) flagNoneLoadedThisPass = false;
}
}
if (flagNoneLoadedThisPass)
{
// Give up
Logger.Log($"Couldn't finish adding bodies.");
return;
}
toLoad = NextPassBodies;
NextPassBodies = new List<NewHorizonsBody>();
// Infinite loop failsafe
if (passCount > 10)
{
Logger.Log("Something went wrong");
break;
}
}
Logger.Log("Done loading bodies");
// I don't know what these do but they look really weird from a distance
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
}
@ -155,7 +197,7 @@ namespace NewHorizons
{
try
{
GameObject planetObject = GenerateBody(body);
GameObject planetObject = GenerateBody(body, defaultPrimaryToSun);
if (planetObject == null) return false;
planetObject.SetActive(true);
}
@ -168,7 +210,6 @@ namespace NewHorizons
return true;
}
public void LoadConfigs(IModBehaviour mod)
{
var folder = mod.ModHelper.Manifest.ModFolderPath;
@ -187,7 +228,7 @@ namespace NewHorizons
}
}
public static GameObject UpdateBody(NewHorizonsBody body, AstroObject ao)
public GameObject UpdateBody(NewHorizonsBody body, AstroObject ao)
{
Logger.Log($"Updating existing AstroObject {ao}");
@ -200,10 +241,10 @@ namespace NewHorizons
return SharedGenerateBody(body, go, sector, rb, ao);
}
public static GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
public GameObject GenerateBody(NewHorizonsBody body, bool defaultPrimaryToSun = false)
{
AstroObject primaryBody;
if(body.Config.Orbit.PrimaryBody != null)
if (body.Config.Orbit.PrimaryBody != null)
{
primaryBody = AstroObjectLocator.GetAstroObject(body.Config.Orbit.PrimaryBody);
if (primaryBody == null)
@ -225,27 +266,25 @@ namespace NewHorizons
primaryBody = null;
}
Logger.Log($"Begin generation sequence of [{body.Config.Name}]");
var go = new GameObject(body.Config.Name.Replace(" ", "").Replace("'", "") + "_Body");
go.SetActive(false);
if(body.Config.Base.GroundSize != 0) GeometryBuilder.Make(go, body.Config.Base.GroundSize);
if (body.Config.Base.GroundSize != 0) GeometryBuilder.Make(go, body.Config.Base.GroundSize);
var atmoSize = body.Config.Atmosphere != null ? body.Config.Atmosphere.Size : 0f;
float sphereOfInfluence = Mathf.Max(atmoSize, body.Config.Base.SurfaceSize * 2f);
var positionVector = OrbitalHelper.RotateTo(Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity), body.Config.Orbit);
var outputTuple = BaseBuilder.Make(go, primaryBody, positionVector, body.Config);
var outputTuple = BaseBuilder.Make(go, primaryBody, body.Config);
var ao = (AstroObject)outputTuple.Item1;
var owRigidBody = (OWRigidbody)outputTuple.Item2;
GravityVolume gv = null;
if (body.Config.Base.SurfaceGravity != 0)
GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff);
gv = GravityBuilder.Make(go, ao, body.Config.Base.SurfaceGravity, sphereOfInfluence * (body.Config.Star != null ? 10f : 1f), body.Config.Base.SurfaceSize, body.Config.Base.GravityFallOff);
if(body.Config.Base.HasReferenceFrame)
if (body.Config.Base.HasReferenceFrame)
RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence);
if (body.Config.Base.HasMapMarker)
@ -268,8 +307,7 @@ namespace NewHorizons
if (body.Config.Base.BlackHoleSize != 0)
BlackHoleBuilder.Make(go, body.Config.Base, sector);
if (body.Config.Star != null)
StarBuilder.Make(go, sector, body.Config.Star);
if (body.Config.Star != null) StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star));
if (body.Config.FocalPoint != null)
FocalPointBuilder.Make(go, body.Config.FocalPoint);
@ -281,6 +319,7 @@ namespace NewHorizons
// Now that we're done move the planet into place
go.transform.parent = Locator.GetRootTransform();
var positionVector = OrbitalHelper.RotateTo(Vector3.left * body.Config.Orbit.SemiMajorAxis * (1 + body.Config.Orbit.Eccentricity), body.Config.Orbit);
go.transform.position = positionVector + (primaryBody == null ? Vector3.zero : primaryBody.transform.position);
if (go.transform.position.magnitude > FurthestOrbit)
@ -289,7 +328,7 @@ namespace NewHorizons
}
// Have to do this after setting position
InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit);
var initialMotion = InitialMotionBuilder.Make(go, primaryBody, owRigidBody, body.Config.Orbit);
// Spawning on other planets is a bit hacky so we do it last
if (body.Config.Spawn != null)
@ -306,7 +345,7 @@ namespace NewHorizons
return go;
}
private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao)
private GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go, Sector sector, OWRigidbody rb, AstroObject ao)
{
if (body.Config.Ring != null)
RingBuilder.Make(go, body.Config.Ring, body.Assets);
@ -317,7 +356,7 @@ namespace NewHorizons
if (body.Config.Base.HasCometTail)
CometTailBuilder.Make(go, body.Config.Base, go.GetComponent<AstroObject>().GetPrimaryBody());
if(body.Config.Base != null)
if (body.Config.Base != null)
{
if (body.Config.Base.LavaSize != 0)
LavaBuilder.Make(go, sector, rb, body.Config.Base.LavaSize);
@ -341,7 +380,7 @@ namespace NewHorizons
if (body.Config.Atmosphere.FogSize != 0)
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)

View File

@ -7,8 +7,8 @@ using UnityEngine;
namespace NewHorizons.OrbitalPhysics
{
public class TrackingOrbitLine : OrbitLine
{
public class TrackingOrbitLine : OrbitLine
{
private Vector3[] _vertices;
private float _timer;
private bool _firstTimeEnabled = true;
@ -65,17 +65,17 @@ namespace NewHorizons.OrbitalPhysics
_timer += Time.deltaTime;
var updateTime = (TrailTime / (float)_numVerts);
if(_timer > updateTime)
{
if (_timer > updateTime)
{
for (int i = _numVerts - 1; i > 0; i--)
{
var v = _vertices[i - 1];
_vertices[i] = new Vector3(v.x, v.y, v.z);
}
_vertices[0] = transform.parent.position - origin;
_lineRenderer.SetPositions(_vertices);
_timer = 0;
}
_vertices[0] = transform.parent.position - origin;
_lineRenderer.SetPositions(_vertices);
base.transform.position = origin;
base.transform.rotation = Quaternion.AngleAxis(0f, Vector3.up);
@ -100,7 +100,7 @@ namespace NewHorizons.OrbitalPhysics
}
public void ResetLineVertices()
{
{
var primary = _astroObject.GetPrimaryBody();
Vector3 origin = primary == null ? Locator.GetRootTransform().position : primary.transform.position;

View File

@ -22,6 +22,20 @@ namespace NewHorizons.Utility
{
if (Keyboard.current != null && Keyboard.current[Key.P].wasReleasedThisFrame)
{
/*
var soundSources = GameObject.FindObjectsOfType<AudioSource>();
foreach(var s in soundSources)
{
if (s.isPlaying)
{
Logger.Log($"{s.name}, {s.gameObject.name}");
Logger.LogPath(s.gameObject);
s.loop = false;
s.Stop();
}
}
*/
// Raycast
_rb.DisableCollisionDetection();
int layerMask = OWLayerMask.physicalMask;

View File

@ -87,7 +87,14 @@ namespace NewHorizons.Utility
continue;
}
targetProperty.SetValue(destination, srcProp.GetValue(source, null), null);
try
{
targetProperty.SetValue(destination, srcProp.GetValue(source, null), null);
} catch(Exception)
{
Logger.LogWarning($"Couldn't copy property {targetProperty.Name} from {source} to {destination}");
}
}
}
}

View File

@ -12,8 +12,13 @@ namespace NewHorizons.Utility
{
public static void Apply()
{
// Prefixes
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ReferenceFrame>("GetHUDDisplayName", typeof(Patches), nameof(Patches.GetHUDDisplayName));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<PlayerState>("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunLightParamUpdater>("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunSurfaceAudioController>("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate));
// Postfixes
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<EllipticOrbitLine>("Start", typeof(Patches), nameof(Patches.OnEllipticOrbitLineStart));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<MapController>("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<OWCamera>("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake));
@ -56,5 +61,37 @@ namespace NewHorizons.Utility
{
__instance.farClipPlane *= 4f;
}
public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance)
{
if (__instance.sunLight)
{
Vector3 position = __instance.transform.position;
float w = 2000f;
if (__instance._sunController != null)
{
w = (__instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius());
}
float range = __instance.sunLight.range;
Color color = (__instance._sunLightController != null) ? __instance._sunLightController.sunColor : __instance.sunLight.color;
float w2 = (__instance._sunLightController != null) ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;
Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w));
Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range)));
Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2));
}
return false;
}
public static bool OnSunSurfaceAudioControllerUpdate(SunSurfaceAudioController __instance)
{
if (__instance._sunController != null) return true;
var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude;
float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius);
float num = Mathf.InverseLerp(1600f, 100f, value);
__instance._audioSource.SetLocalVolume(num * num * __instance._fade);
return false;
}
}
}

View 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;
}
}
}

View File

@ -0,0 +1,102 @@
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 RemoveStar(StarController star)
{
if (_stars.Contains(star))
{
if (_activeStar.Equals(star)) _activeStar = null;
_stars.Remove(star);
}
}
public void Update()
{
if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy)
{
if (_stars.Contains(_activeStar)) _stars.Remove(_activeStar);
if (_stars.Count > 0) ChangeActiveStar(_stars[0]);
else gameObject.SetActive(false);
return;
}
foreach(var star in _stars)
{
if (star == null) continue;
// Player is always at 0,0,0 more or less so if they arent using the map camera then wtv
var origin = Vector3.zero;
if (PlayerState.InMapView())
{
origin = Locator.GetActiveCamera().transform.position;
}
if (star.Intensity * (star.transform.position - origin).sqrMagnitude < star.Intensity * (_activeStar.transform.position - origin).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>();
_sunLightParamUpdater._propID_SunPosition = Shader.PropertyToID("_SunPosition");
_sunLightParamUpdater._propID_OWSunPositionRange = Shader.PropertyToID("_OWSunPositionRange");
_sunLightParamUpdater._propID_OWSunColorIntensity = Shader.PropertyToID("_OWSunColorIntensity");
// 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;
}
}
}

View File

@ -37,6 +37,8 @@ Planets are created using a JSON file format structure, and placed in the `plane
- Edit existing planet orbits
- Black hole / white hole pairs
- Separate solar system scenes accessible via wormhole
- Cloaking field
- Signalscope signal
## How to create your own planets using configs