This commit is contained in:
Nick J. Connors 2022-01-03 02:27:56 -05:00
commit c7c5f67aae
22 changed files with 458 additions and 97 deletions

View File

@ -31,6 +31,8 @@ namespace NewHorizons.Atmosphere
return;
}
Color cloudTint = atmo.CloudTint == null ? Color.white : (Color)atmo.CloudTint.ToColor32();
GameObject cloudsMainGO = new GameObject();
cloudsMainGO.SetActive(false);
cloudsMainGO.transform.parent = body.transform;
@ -56,8 +58,8 @@ namespace NewHorizons.Atmosphere
foreach (var material in topMR.sharedMaterials)
{
material.SetColor("_Color", atmo.CloudTint.ToColor32());
material.SetColor("_TintColor", atmo.CloudTint.ToColor32());
material.SetColor("_Color", cloudTint);
material.SetColor("_TintColor", cloudTint);
material.SetTexture("_MainTex", image);
material.SetTexture("_RampTex", ramp);
@ -84,7 +86,7 @@ namespace NewHorizons.Atmosphere
bottomTSR.LODRadius = 1f;
// It's always more green than expected
var bottomCloudTint = atmo.CloudTint.ToColor32();
var bottomCloudTint = cloudTint;
bottomCloudTint.g = (byte)(bottomCloudTint.g * 0.8f);
foreach (Material material in bottomTSR.sharedMaterials)
{

View File

@ -14,7 +14,7 @@ namespace NewHorizons.Builder.Body
{
static class AsteroidBeltBuilder
{
public static void Make(string bodyName, AsteroidBeltModule belt, IModAssets assets)
public static void Make(string bodyName, AsteroidBeltModule belt, IModAssets assets, string uniqueName)
{
var minSize = 20;
var maxSize = 50;
@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Body
}
};
var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets);
var asteroid = new NewHorizonsBody(new PlanetConfig(config), assets, uniqueName);
Main.NextPassBodies.Add(asteroid);
}
}

View File

@ -1,36 +0,0 @@
using NewHorizons.External;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Builder.Body
{
static class BlackHoleBuilder
{
public static void Make(GameObject body, BaseModule module, Sector sector)
{
var blackHole = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH"), body.transform);
blackHole.name = "BlackHole";
blackHole.transform.localPosition = Vector3.zero;
//blackHole.transform.localScale = Vector3.one; //* module.BlackHoleSize;
var blackHoleRenderer = blackHole.transform.Find("BlackHoleRenderer");
//blackHoleRenderer.transform.localScale = Vector3.one;
var singularityLOD = blackHoleRenderer.GetComponent<SingularityLOD>();
singularityLOD.SetSector(sector);
/*
var meshRenderer = blackHoleRenderer.GetComponent<MeshRenderer>();
meshRenderer.material.SetFloat("_Radius", module.BlackHoleSize * 0.4f);
var owRenderer = blackHoleRenderer.gameObject.AddComponent<OWRenderer>();
var propID_Radius = Shader.PropertyToID("_Radius");
owRenderer.SetMaterialProperty(propID_Radius, module.BlackHoleSize * 0.4f);
*/
}
}
}

View File

@ -33,6 +33,7 @@ namespace NewHorizons.Builder.Body
}
GameObject cubeSphere = new GameObject("CubeSphere");
cubeSphere.SetActive(false);
cubeSphere.transform.parent = go.transform;
cubeSphere.transform.rotation = Quaternion.Euler(90, 0, 0);
@ -53,6 +54,8 @@ namespace NewHorizons.Builder.Body
// Fix rotation in the end
cubeSphere.transform.localRotation = Quaternion.Euler(90, 0, 0);
cubeSphere.transform.localPosition = Vector3.zero;
cubeSphere.SetActive(true);
}
}
}

View File

@ -43,11 +43,11 @@ namespace NewHorizons.Builder.Body
var mat = new Material(RingShader);
mat.mainTexture = texture;
mat.renderQueue = 3000;
mat.renderQueue = 2895;
ringMR.material = mat;
// Make mesh
var segments = (int)Math.Max(20, ring.OuterRadius);
var segments = (int)Mathf.Clamp(ring.OuterRadius, 20, 2000);
BuildRingMesh(ringMesh, segments, ring.InnerRadius, ring.OuterRadius);
}

View File

@ -0,0 +1,203 @@
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Utility;
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.Builder.Body
{
static class SingularityBuilder
{
enum Polarity
{
BlackHole,
WhiteHole
}
private static Shader blackHoleShader = null;
private static Shader whiteHoleShader = null;
public static void Make(GameObject body, Sector sector, OWRigidbody OWRB, IPlanetConfig config)
{
var size = config.Base.BlackHoleSize;
string pairedSingularity = null;
var polarity = Polarity.BlackHole;
if (config.Singularity != null)
{
size = config.Singularity.Size;
pairedSingularity = config.Singularity.PairedSingularity;
if(config.Singularity.Type != null && config.Singularity.Type.ToUpper().Equals("WHITEHOLE"))
{
polarity = Polarity.WhiteHole;
}
}
bool hasHazardVolume = pairedSingularity == null;
GameObject newSingularity = null;
switch (polarity)
{
case Polarity.BlackHole:
newSingularity = MakeBlackHole(body, sector, size, hasHazardVolume);
break;
case Polarity.WhiteHole:
newSingularity = MakeWhiteHole(body, sector, OWRB, size);
break;
}
// Try to pair them
if(pairedSingularity != null && newSingularity != null)
{
var pairedSingularityAO = AstroObjectLocator.GetAstroObject(pairedSingularity);
if(pairedSingularityAO != null)
{
Logger.Log($"Pairing singularities {pairedSingularity}, {config.Name}");
try
{
switch (polarity)
{
case Polarity.BlackHole:
newSingularity.GetComponentInChildren<BlackHoleVolume>()._whiteHole = pairedSingularityAO.GetComponentInChildren<WhiteHoleVolume>();
break;
case Polarity.WhiteHole:
pairedSingularityAO.GetComponentInChildren<BlackHoleVolume>()._whiteHole = newSingularity.GetComponentInChildren<WhiteHoleVolume>();
break;
}
}
catch(Exception)
{
Logger.LogError($"Couldn't pair singularities {pairedSingularity}, {config.Name}");
}
}
}
}
private static GameObject MakeBlackHole(GameObject body, Sector sector, float size, bool hasDestructionVolume)
{
var blackHole = new GameObject("BlackHole");
blackHole.SetActive(false);
blackHole.transform.parent = body.transform;
blackHole.transform.localPosition = Vector3.zero;
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = blackHole.transform;
blackHoleRender.transform.localPosition = Vector3.zero;
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(blackHoleShader);
meshRenderer.material.SetFloat("_Radius", size * 0.4f);
meshRenderer.material.SetFloat("_MaxDistortRadius", size * 0.95f);
meshRenderer.material.SetFloat("_MassScale", 1);
meshRenderer.material.SetFloat("_DistortFadeDist", size * 0.55f);
if(hasDestructionVolume)
{
var destructionVolumeGO = new GameObject("DestructionVolume");
destructionVolumeGO.layer = LayerMask.NameToLayer("BasicEffectVolume");
destructionVolumeGO.transform.parent = blackHole.transform;
destructionVolumeGO.transform.localScale = Vector3.one;
destructionVolumeGO.transform.localPosition = Vector3.zero;
var sphereCollider = destructionVolumeGO.AddComponent<SphereCollider>();
sphereCollider.radius = size * 0.4f;
sphereCollider.isTrigger = true;
destructionVolumeGO.AddComponent<BlackHoleDestructionVolume>();
}
else
{
var blackHoleVolume = GameObject.Instantiate(GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleVolume"), blackHole.transform);
blackHoleVolume.name = "BlackHoleVolume";
blackHoleVolume.GetComponent<SphereCollider>().radius = size * 0.4f;
}
blackHole.SetActive(true);
return blackHole;
}
private static GameObject MakeWhiteHole(GameObject body, Sector sector, OWRigidbody OWRB, float size)
{
var whiteHole = new GameObject("WhiteHole");
whiteHole.SetActive(false);
whiteHole.transform.parent = body.transform;
whiteHole.transform.localPosition = Vector3.zero;
var whiteHoleRenderer = new GameObject("WhiteHoleRenderer");
whiteHoleRenderer.transform.parent = whiteHole.transform;
whiteHoleRenderer.transform.localPosition = Vector3.zero;
whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f;
var meshFilter = whiteHoleRenderer.AddComponent<MeshFilter>();
meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshFilter>().mesh;
var meshRenderer = whiteHoleRenderer.AddComponent<MeshRenderer>();
if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(whiteHoleShader);
meshRenderer.sharedMaterial.SetFloat("_Radius", size * 0.4f);
meshRenderer.sharedMaterial.SetFloat("_DistortFadeDist", size);
meshRenderer.sharedMaterial.SetFloat("_MaxDistortRadius", size * 2.8f);
meshRenderer.sharedMaterial.SetColor("_Color", new Color(1.88f, 1.88f, 1.88f, 1f));
var ambientLight = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/AmbientLight_WH"));
ambientLight.transform.parent = whiteHole.transform;
ambientLight.transform.localScale = Vector3.one;
ambientLight.transform.localPosition = Vector3.zero;
ambientLight.name = "AmbientLight";
ambientLight.GetComponent<Light>().range = size * 7f;
var proxyShadow = sector.gameObject.AddComponent<ProxyShadowCasterSuperGroup>();
// it's going to complain
GameObject whiteHoleVolumeGO = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/WhiteHoleVolume"));
whiteHoleVolumeGO.transform.parent = whiteHole.transform;
whiteHoleVolumeGO.transform.localPosition = Vector3.zero;
whiteHoleVolumeGO.transform.localScale = Vector3.one;
whiteHoleVolumeGO.GetComponent<SphereCollider>().radius = size;
whiteHoleVolumeGO.name = "WhiteHoleVolume";
var whiteHoleFluidVolume = whiteHoleVolumeGO.GetComponent<WhiteHoleFluidVolume>();
whiteHoleFluidVolume._innerRadius = size * 0.5f;
whiteHoleFluidVolume._outerRadius = size;
whiteHoleFluidVolume._attachedBody = OWRB;
var whiteHoleVolume = whiteHoleVolumeGO.GetComponent<WhiteHoleVolume>();
whiteHoleVolume._debrisDistMax = size * 6.5f;
whiteHoleVolume._debrisDistMin = size * 2f;
whiteHoleVolume._whiteHoleSector = sector;
whiteHoleVolume._fluidVolume = whiteHoleFluidVolume;
whiteHoleVolume._whiteHoleBody = OWRB;
whiteHoleVolume._whiteHoleProxyShadowSuperGroup = proxyShadow;
whiteHoleVolumeGO.GetComponent<SphereCollider>().radius = size;
whiteHoleVolume.enabled = true;
whiteHoleFluidVolume.enabled = true;
var zeroGVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/ZeroGVolume"), whiteHole.transform);
zeroGVolume.name = "ZeroGVolume";
zeroGVolume.GetComponent<SphereCollider>().radius = size * 10f;
zeroGVolume.GetComponent<ZeroGVolume>()._attachedBody = OWRB;
var rulesetVolume = GameObject.Instantiate(GameObject.Find("WhiteHole_Body/Sector_WhiteHole/RulesetVolumes_WhiteHole"), sector.transform);
rulesetVolume.name = "RulesetVolume";
rulesetVolume.transform.localPosition = Vector3.zero;
rulesetVolume.transform.localScale = Vector3.one * size / 100f;
rulesetVolume.GetComponent<SphereShape>().enabled = true;
whiteHole.SetActive(true);
return whiteHole;
}
}
}

View File

@ -38,6 +38,7 @@ namespace NewHorizons.Builder.General
var type = AstroObject.Type.Planet;
if (config.Orbit.IsMoon) type = AstroObject.Type.Moon;
else if (config.Base.IsSatellite) type = AstroObject.Type.Satellite;
else if (config.Base.HasCometTail) type = AstroObject.Type.Comet;
else if (config.Star != null) type = AstroObject.Type.Star;
else if (config.FocalPoint != null) type = AstroObject.Type.None;

View File

@ -13,22 +13,26 @@ namespace NewHorizons.Builder.General
MapMarker mapMarker = body.AddComponent<MapMarker>();
mapMarker.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(name.ToUpper()));
var markerType = "Planet";
var markerType = MapMarker.MarkerType.Planet;
if (config.Orbit.IsMoon)
{
markerType = "Moon";
markerType = MapMarker.MarkerType.Moon;
}
else if (config.Star != null)
{
markerType = "Sun";
markerType = MapMarker.MarkerType.Sun;
}
else if (config.FocalPoint != null)
{
markerType = "HourglassTwins";
markerType = MapMarker.MarkerType.HourglassTwins;
}
else if(config.Base.IsSatellite)
{
markerType = MapMarker.MarkerType.Probe;
}
mapMarker.SetValue("_markerType", mapMarker.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField(markerType).GetValue(mapMarker));
mapMarker._markerType = markerType;
}
}
}

View File

@ -38,10 +38,20 @@ namespace NewHorizons.Builder.Orbital
else if (config.Base.BlackHoleSize != 0) color = new Color(1f, 0.5f, 1f);
else if (config.Base.WaterSize != 0) color = new Color(0.5f, 0.5f, 1f);
else if (config.Base.LavaSize != 0) color = new Color(1f, 0.5f, 0.5f);
var fade = isMoon;
if (config.Base.IsSatellite)
{
if(config.Orbit.Tint != null) color = new Color(0.4082f, 0.516f, 0.4469f, 1f);
fade = true;
orbitLine._fadeEndDist = 5000;
orbitLine._fadeStartDist = 3000;
}
orbitLine.SetValue("_color", color);
orbitLine.SetValue("_astroObject", astroobject);
orbitLine.SetValue("_fade", isMoon);
orbitLine.SetValue("_fade", fade);
orbitLine.SetValue("_lineWidth", 2f);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() =>

View File

@ -9,39 +9,86 @@ using Random = UnityEngine.Random;
using Logger = NewHorizons.Utility.Logger;
using System.Reflection;
using NewHorizons.Utility;
using OWML.Common;
namespace NewHorizons.Builder.Props
{
public static class PropBuilder
{
public static void Make(GameObject go, Sector sector, IPlanetConfig config)
public static void Make(GameObject go, Sector sector, IPlanetConfig config, IModAssets assets, string uniqueModName)
{
if (config.Props.Scatter != null) PropBuilder.Scatter(go, config.Props.Scatter, config.Base.SurfaceSize, sector);
if(config.Props.Details != null)
{
foreach(var detail in config.Props.Details)
{
MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale);
if(detail.assetBundle != null)
{
string key = uniqueModName + "." + detail.assetBundle;
AssetBundle bundle;
GameObject prefab;
try
{
if (Main.AssetBundles.ContainsKey(key)) bundle = Main.AssetBundles[key];
else
{
bundle = assets.LoadBundle(detail.assetBundle);
Main.AssetBundles[key] = bundle;
}
}
catch(Exception e)
{
Logger.Log($"Couldn't load AssetBundle {detail.assetBundle} : {e.Message}");
return;
}
try
{
prefab = bundle.LoadAsset<GameObject>(detail.path);
prefab.SetActive(false);
}
catch(Exception e)
{
Logger.Log($"Couldn't load asset {detail.path} from AssetBundle {detail.assetBundle} : {e.Message}");
return;
}
MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
}
else if(detail.objFilePath != null)
{
try
{
var prefab = assets.Get3DObject(detail.objFilePath, detail.mtlFilePath);
prefab.SetActive(false);
MakeDetail(go, sector, prefab, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
}
catch(Exception e)
{
Logger.LogError($"Could not load 3d object {detail.objFilePath} with texture {detail.mtlFilePath} : {e.Message}");
}
}
else MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal);
}
}
}
public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale)
public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal)
{
var prefab = GameObject.Find(propToClone);
return MakeDetail(go, sector, prefab, position, rotation, scale);
//TODO: this is super costly
if (prefab == null) prefab = SearchUtilities.FindObjectOfTypeAndName<GameObject>(propToClone.Split(new char[] { '\\', '/' }).Last());
if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}");
return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal);
}
public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal = false)
public static GameObject MakeDetail(GameObject go, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool snapToSurface = false)
{
if (prefab == null) return null;
GameObject prop = GameObject.Instantiate(prefab, sector.transform);
prop.transform.localPosition = position == null ? prefab.transform.localPosition : (Vector3)position;
Quaternion rot = rotation == null ? prefab.transform.localRotation : Quaternion.Euler((Vector3)rotation);
if (alignWithNormal) rot = Quaternion.FromToRotation(prop.transform.TransformDirection(Vector3.up), ((Vector3)position).normalized);
prop.transform.rotation = rot;
prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale;
prop.SetActive(false);
List<string> assetBundles = new List<string>();
@ -77,25 +124,32 @@ namespace NewHorizons.Builder.Props
prop.transform.rotation = rot;
if (alignWithNormal)
{
try
{
var setSectorMethod = component.GetType().GetMethod("SetSector");
var sectorField = component.GetType().GetField("_sector");
// TODO: Make this work or smthng
if (component is GhostIK) (component as GhostIK).enabled = false;
if(component is GhostEffects) (component as GhostEffects).enabled = false;
if (setSectorMethod != null)
var enabledField = component.GetType().GetField("enabled");
if(enabledField != null && enabledField.FieldType == typeof(bool)) enabledField.SetValue(component, true);
}
prop.transform.parent = go.transform;
prop.transform.localPosition = position == null ? prefab.transform.localPosition : (Vector3)position;
Quaternion rot = rotation == null ? prefab.transform.rotation : Quaternion.Euler((Vector3)rotation);
prop.transform.rotation = rot;
if (alignWithNormal)
{
Logger.Log($"Found a SetSector method in {prop}.{component}");
setSectorMethod.Invoke(component, new object[] { sector });
}
else if (sectorField != null)
{
Logger.Log($"Found a _sector field in {component}");
sectorField.SetValue(component, sector);
}
}
catch (Exception e) { Logger.Log($"{e.Message}, {e.StackTrace}"); }
var up = prop.transform.localPosition.normalized;
var front = Vector3.Cross(up, Vector3.left);
if (front.sqrMagnitude == 0f) front = Vector3.Cross(up, Vector3.forward);
if (front.sqrMagnitude == 0f) front = Vector3.Cross(up, Vector3.up);
prop.transform.LookAt(prop.transform.position + front, up);
}
prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale;
prop.SetActive(true);
return prop;
@ -113,7 +167,7 @@ namespace NewHorizons.Builder.Props
{
var randomInd = (int)Random.Range(0, points.Count);
var point = points[randomInd];
var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f, true);
var prop = MakeDetail(go, sector, prefab, (MVector3)(point.normalized * radius), null, 0f, true, true);
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);

View File

@ -1,6 +1,7 @@
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Utility;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.Linq;
@ -83,20 +84,19 @@ namespace NewHorizons.Builder.Props
public static string GetCustomSignalName(SignalName signalName)
{
string name = null;
_customSignalNames.TryGetValue(signalName, out name);
_customSignalNames.TryGetValue(signalName, out string name);
return name;
}
public static void Make(GameObject body, Sector sector, SignalModule module)
public static void Make(GameObject body, Sector sector, SignalModule module, IModAssets assets)
{
foreach(var info in module.Signals)
{
Make(body, sector, info);
Make(body, sector, info, assets);
}
}
public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info)
public static void Make(GameObject body, Sector sector, SignalModule.SignalInfo info, IModAssets assets)
{
var signalGO = new GameObject($"Signal_{info.Name}");
signalGO.SetActive(false);
@ -107,15 +107,32 @@ namespace NewHorizons.Builder.Props
var source = signalGO.AddComponent<AudioSource>();
var owAudioSource = signalGO.AddComponent<OWAudioSource>();
AudioSignal audioSignal = null;
AudioSignal audioSignal;
if (info.InsideCloak) audioSignal = signalGO.AddComponent<CloakedAudioSignal>();
else audioSignal = signalGO.AddComponent<AudioSignal>();
var frequency = StringToFrequency(info.Frequency);
var name = StringToSignalName(info.Name);
AudioClip clip = SearchUtilities.FindResourceOfTypeAndName<AudioClip>(info.AudioClip);
if (clip == null) return;
AudioClip clip = null;
if(info.AudioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName<AudioClip>(info.AudioClip);
else if (info.AudioFilePath != null)
{
try
{
clip = assets.GetAudio(info.AudioFilePath);
}
catch(Exception e)
{
Logger.LogError($"Couldn't load audio file {info.AudioFilePath} : {e.Message}");
}
}
if (clip == null)
{
Logger.LogError($"Couldn't find AudioClip {info.AudioClip} or AudioFile {info.AudioFilePath}");
return;
}
audioSignal.SetSector(sector);
audioSignal._frequency = frequency;

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Components
{
public class BlackHoleDestructionVolume : DestructionVolume
{
public override void Awake()
{
base.Awake();
_deathType = DeathType.BlackHole;
}
public override void VanishProbe(OWRigidbody probeBody, RelativeLocationData entryLocation)
{
Logger.Log($"Uh oh you shot your probe into a black hole");
SurveyorProbe requiredComponent = probeBody.GetRequiredComponent<SurveyorProbe>();
if (requiredComponent.IsLaunched())
{
UnityEngine.Object.Destroy(requiredComponent.gameObject);
}
}
}
}

View File

@ -16,10 +16,13 @@ namespace NewHorizons.External
public float SurfaceSize { get; set; }
public float WaterSize { get; set; }
public float GroundSize { get; set; }
public float BlackHoleSize { get; set; }
public float LavaSize { get; set; }
public bool HasCometTail { get; set; }
public bool HasReferenceFrame { get; set; } = true;
public bool CenterOfSolarSystem { get; set; } = false;
public bool IsSatellite { get; set; }
// Old, see SingularityModule instead
public float BlackHoleSize { get; set; }
}
}

View File

@ -19,5 +19,6 @@ namespace NewHorizons.External
PropModule Props { get; }
SpawnModule Spawn { get; }
SignalModule Signal { get; }
SingularityModule Singularity { get; }
}
}

View File

@ -23,6 +23,7 @@ namespace NewHorizons.External
public PropModule Props { get; set; }
public SpawnModule Spawn { get; set; }
public SignalModule Signal { get; set; }
public SingularityModule Singularity { get; set; }
public PlanetConfig(Dictionary<string, object> dict)
{

View File

@ -24,9 +24,13 @@ namespace NewHorizons.External
public class DetailInfo
{
public string path;
public string objFilePath;
public string mtlFilePath;
public string assetBundle;
public MVector3 position;
public MVector3 rotation;
public float scale;
public bool alignToNormal;
}
}
}

View File

@ -16,7 +16,8 @@ namespace NewHorizons.External
public MVector3 Position;
public string Frequency;
public string Name;
public string AudioClip;
public string AudioClip = null;
public string AudioFilePath = null;
public float SourceRadius = 1f;
public float DetectionRadius = 0f;
public float IdentificationRadius = 10f;

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External
{
public class SingularityModule : Module
{
public float Size;
public string PairedSingularity;
public string Type; //BlackHole or WhiteHole
}
}

View File

@ -30,6 +30,8 @@ namespace NewHorizons
public static List<NewHorizonsBody> BodyList = new List<NewHorizonsBody>();
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
public static Dictionary<string, AssetBundle> AssetBundles = new Dictionary<string, AssetBundle>();
public static float FurthestOrbit { get; set; } = 50000f;
public StarLightController StarLightController { get; private set; }
@ -187,7 +189,7 @@ namespace NewHorizons
existingPlanet = AstroObjectLocator.GetAstroObject(stringID).gameObject;
if (existingPlanet == null) existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.Name.Replace(" ", "")).gameObject;
}
catch (Exception e)
catch (Exception)
{
existingPlanet = GameObject.Find(body.Config.Name.Replace(" ", "") + "_Body");
}
@ -236,7 +238,7 @@ namespace NewHorizons
{
var config = mod.ModHelper.Storage.Load<PlanetConfig>(file.Replace(folder, ""));
Logger.Log($"Loaded {config.Name}");
BodyList.Add(new NewHorizonsBody(config, mod.ModHelper.Assets));
BodyList.Add(new NewHorizonsBody(config, mod.ModHelper.Assets, mod.ModHelper.Manifest.UniqueName));
}
catch (Exception e)
{
@ -289,7 +291,7 @@ namespace NewHorizons
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);
float sphereOfInfluence = Mathf.Max(Mathf.Max(atmoSize, 50), body.Config.Base.SurfaceSize * 2f);
var outputTuple = BaseBuilder.Make(go, primaryBody, body.Config);
var ao = (AstroObject)outputTuple.Item1;
@ -319,8 +321,8 @@ namespace NewHorizons
if (body.Config.ProcGen != null)
ProcGenBuilder.Make(go, body.Config.ProcGen);
if (body.Config.Base.BlackHoleSize != 0)
BlackHoleBuilder.Make(go, body.Config.Base, sector);
if (body.Config.Base.BlackHoleSize != 0 || body.Config.Singularity != null)
SingularityBuilder.Make(go, sector, owRigidBody, body.Config);
if (body.Config.Star != null) StarLightController.AddStar(StarBuilder.Make(go, sector, body.Config.Star));
@ -366,7 +368,7 @@ namespace NewHorizons
RingBuilder.Make(go, body.Config.Ring, body.Assets);
if (body.Config.AsteroidBelt != null)
AsteroidBeltBuilder.Make(body.Config.Name, body.Config.AsteroidBelt, body.Assets);
AsteroidBeltBuilder.Make(body.Config.Name, body.Config.AsteroidBelt, body.Assets, body.ModUniqueName);
if (body.Config.Base.HasCometTail)
CometTailBuilder.Make(go, body.Config.Base, go.GetComponent<AstroObject>().GetPrimaryBody());
@ -396,10 +398,10 @@ namespace NewHorizons
}
if (body.Config.Props != null)
PropBuilder.Make(go, sector, body.Config);
PropBuilder.Make(go, sector, body.Config, body.Assets, body.ModUniqueName);
if (body.Config.Signal != null)
SignalBuilder.Make(go, sector, body.Config.Signal);
SignalBuilder.Make(go, sector, body.Config.Signal, body.Assets);
return go;
}
@ -418,7 +420,7 @@ namespace NewHorizons
Logger.Log("Recieved API request to create planet " + (string)config["Name"], Logger.LogType.Log);
var planetConfig = new PlanetConfig(config);
var body = new NewHorizonsBody(planetConfig, mod != null ? mod.ModHelper.Assets : Main.Instance.ModHelper.Assets);
var body = new NewHorizonsBody(planetConfig, mod != null ? mod.ModHelper.Assets : Main.Instance.ModHelper.Assets, mod.ModHelper.Manifest.UniqueName);
Main.BodyList.Add(body);
}

View File

@ -6,14 +6,16 @@ namespace NewHorizons.Utility
{
public class NewHorizonsBody
{
public NewHorizonsBody(IPlanetConfig config, IModAssets assets)
public NewHorizonsBody(IPlanetConfig config, IModAssets assets, string modUniqueName)
{
Config = config;
Assets = assets;
ModUniqueName = modUniqueName;
}
public IPlanetConfig Config;
public IModAssets Assets;
public string ModUniqueName;
public GameObject Object;
}

View File

@ -43,6 +43,10 @@ namespace NewHorizons.Utility
var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame");
Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<BlackHoleVolume>("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<WhiteHoleVolume>("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ProbeLauncher>("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues));
// Postfixes
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<MapController>("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<OWCamera>("Awake", typeof(Patches), nameof(Patches.OnOWCameraAwake));
@ -306,5 +310,30 @@ namespace NewHorizons.Utility
NewHorizonsData.Reset();
}
#endregion
public static bool OnBlackHoleVolumeStart(BlackHoleVolume __instance)
{
return __instance._whiteHole == null;
}
public static bool OnWhiteHoleVolumeAwake(WhiteHoleVolume __instance)
{
__instance._growQueue = new List<OWRigidbody>(8);
__instance._growQueueLocationData = new List<RelativeLocationData>(8);
__instance._ejectedBodyList = new List<OWRigidbody>(64);
try
{
__instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false);
__instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren<ProxyShadowCasterSuperGroup>();
__instance._fluidVolume = __instance.gameObject.GetRequiredComponent<WhiteHoleFluidVolume>();
}
catch (Exception) { }
return false;
}
public static bool OnProbeLauncherUpdateOrbitalLaunchValues(ProbeLauncher __instance)
{
return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null);
}
}
}

View File

@ -10,7 +10,7 @@ namespace NewHorizons.Utility
{
public static class SearchUtilities
{
public static List<T> FindObjectsOfTypeAndName<T>(string name) where T : MonoBehaviour
public static List<T> FindObjectsOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = GameObject.FindObjectsOfType<T>();
List<T> finalList = new List<T>();
@ -26,6 +26,22 @@ namespace NewHorizons.Utility
return finalList;
}
public static T FindObjectOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = GameObject.FindObjectsOfType<T>();
List<T> finalList = new List<T>();
for (var i = 0; i < firstList.Length; i++)
{
if (firstList[i].name == name)
{
return firstList[i];
}
}
return null;
}
public static List<T> FindResourcesOfTypeAndName<T>(string name) where T : Object
{
T[] firstList = Resources.FindObjectsOfTypeAll<T>();