Massive rewrite

- Added moon support
- Rewrote every class for readability
- Rewrote Main class to simplify code (file planets now load on scene load)
This commit is contained in:
Mister_Nebula 2020-06-11 19:41:39 +01:00
parent ece268c1d8
commit dc23ac2de8
25 changed files with 524 additions and 453 deletions

View File

@ -7,53 +7,53 @@ namespace Marshmallow.Atmosphere
{
public static void Make(GameObject body, float airScale, bool isRaining)
{
GameObject air = new GameObject();
air.layer = 17;
air.SetActive(false);
air.transform.parent = body.transform;
GameObject airGO = new GameObject();
airGO.SetActive(false);
airGO.layer = 17;
airGO.transform.parent = body.transform;
SphereCollider atmoSC = air.AddComponent<SphereCollider>();
atmoSC.isTrigger = true;
atmoSC.radius = airScale;
SphereCollider SC = airGO.AddComponent<SphereCollider>();
SC.isTrigger = true;
SC.radius = airScale;
SimpleFluidVolume sfv = air.AddComponent<SimpleFluidVolume>();
sfv.SetValue("_layer", 5);
sfv.SetValue("_priority", 1);
sfv.SetValue("_density", 1.2f);
sfv.SetValue("_fluidType", FluidVolume.Type.AIR);
sfv.SetValue("_allowShipAutoroll", true);
sfv.SetValue("_disableOnStart", false);
SimpleFluidVolume SFV = airGO.AddComponent<SimpleFluidVolume>();
SFV.SetValue("_layer", 5);
SFV.SetValue("_priority", 1);
SFV.SetValue("_density", 1.2f);
SFV.SetValue("_fluidType", FluidVolume.Type.AIR);
SFV.SetValue("_allowShipAutoroll", true);
SFV.SetValue("_disableOnStart", false);
if (isRaining)
{
VisorRainEffectVolume vref = air.AddComponent<VisorRainEffectVolume>();
vref.SetValue("_rainDirection", VisorRainEffectVolume.RainDirection.Radial);
vref.SetValue("_layer", 0);
vref.SetValue("_priority", 0);
VisorRainEffectVolume VREF = airGO.AddComponent<VisorRainEffectVolume>();
VREF.SetValue("_rainDirection", VisorRainEffectVolume.RainDirection.Radial);
VREF.SetValue("_layer", 0);
VREF.SetValue("_priority", 0);
AudioSource auds = air.AddComponent<AudioSource>();
auds.mute = false;
auds.bypassEffects = false;
auds.bypassListenerEffects = false;
auds.bypassReverbZones = false;
auds.playOnAwake = false;
auds.loop = true;
auds.priority = 128;
auds.volume = 0.35f;
auds.pitch = 1f;
auds.panStereo = 0f;
auds.spatialBlend = 0f;
auds.reverbZoneMix = 1f;
AudioSource AS = airGO.AddComponent<AudioSource>();
AS.mute = false;
AS.bypassEffects = false;
AS.bypassListenerEffects = false;
AS.bypassReverbZones = false;
AS.playOnAwake = false;
AS.loop = true;
AS.priority = 128;
AS.volume = 0.35f;
AS.pitch = 1f;
AS.panStereo = 0f;
AS.spatialBlend = 0f;
AS.reverbZoneMix = 1f;
OWAudioSource owas = air.AddComponent<OWAudioSource>();
owas.SetAudioLibraryClip(AudioType.GD_RainAmbient_LP);
owas.SetClipSelectionType(OWAudioSource.ClipSelectionOnPlay.RANDOM);
owas.SetTrack(OWAudioMixer.TrackName.Environment);
OWAudioSource OWAS = airGO.AddComponent<OWAudioSource>();
OWAS.SetAudioLibraryClip(AudioType.GD_RainAmbient_LP);
OWAS.SetClipSelectionType(OWAudioSource.ClipSelectionOnPlay.RANDOM);
OWAS.SetTrack(OWAudioMixer.TrackName.Environment);
/*AudioVolume av = */air.AddComponent<AudioVolume>();
/*AudioVolume av = */airGO.AddComponent<AudioVolume>();
}
air.SetActive(true);
airGO.SetActive(true);
}
}
}

View File

@ -1,45 +1,47 @@
using UnityEngine;
using Marshmallow.External;
using UnityEngine;
using Logger = Marshmallow.Utility.Logger;
namespace Marshmallow.Atmosphere
{
static class MakeAtmosphere
{
public static void Make(GameObject body, float topCloudScale, bool hasFog, float fogDensity, Color32 fogTint)
public static void Make(GameObject body, IPlanetConfig config)
{
topCloudScale /= 2;
GameObject atmoGO = new GameObject();
atmoGO.SetActive(false);
atmoGO.name = "Atmosphere";
atmoGO.transform.parent = body.transform;
GameObject atmoM = new GameObject();
atmoM.SetActive(false);
atmoM.name = "Atmosphere";
atmoM.transform.parent = body.transform;
if (hasFog)
if (config.HasFog)
{
GameObject fog = new GameObject();
fog.SetActive(false);
fog.name = "FogSphere";
fog.transform.parent = atmoM.transform;
fog.transform.localScale = new Vector3(topCloudScale + 10, topCloudScale + 10, topCloudScale + 10);
GameObject fogGO = new GameObject();
fogGO.SetActive(false);
fogGO.name = "FogSphere";
fogGO.transform.parent = atmoGO.transform;
fogGO.transform.localScale = new Vector3((config.TopCloudSize / 2) + 10, (config.TopCloudSize / 2) + 10, (config.TopCloudSize / 2) + 10);
MeshFilter mf = fog.AddComponent<MeshFilter>();
mf.mesh = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<MeshFilter>().mesh;
MeshFilter MF = fogGO.AddComponent<MeshFilter>();
MF.mesh = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<MeshFilter>().mesh;
MeshRenderer mr = fog.AddComponent<MeshRenderer>();
mr.materials = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<MeshRenderer>().materials;
mr.allowOcclusionWhenDynamic = true;
MeshRenderer MR = fogGO.AddComponent<MeshRenderer>();
MR.materials = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<MeshRenderer>().materials;
MR.allowOcclusionWhenDynamic = true;
PlanetaryFogController pfc = fog.AddComponent<PlanetaryFogController>();
pfc.fogLookupTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<PlanetaryFogController>().fogLookupTexture;
pfc.fogRadius = topCloudScale + 10;
pfc.fogDensity = fogDensity;
pfc.fogExponent = 1f;
pfc.fogColorRampTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<PlanetaryFogController>().fogColorRampTexture;
pfc.fogColorRampIntensity = 1f;
pfc.fogTint = fogTint;
PlanetaryFogController PFC = fogGO.AddComponent<PlanetaryFogController>();
PFC.fogLookupTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<PlanetaryFogController>().fogLookupTexture;
PFC.fogRadius = (config.TopCloudSize / 2) + 10;
PFC.fogDensity = config.FogDensity;
PFC.fogExponent = 1f;
PFC.fogColorRampTexture = GameObject.Find("Atmosphere_GD/FogSphere").GetComponent<PlanetaryFogController>().fogColorRampTexture;
PFC.fogColorRampIntensity = 1f;
PFC.fogTint = config.FogTint.ToColor32();
fog.SetActive(true);
fogGO.SetActive(true);
}
Logger.Log("Re-add LOD atmosphere!", Logger.LogType.Todo);
/*
GameObject atmo = new GameObject();
atmo.SetActive(false);
@ -99,7 +101,7 @@ namespace Marshmallow.Atmosphere
*/
//atmo.SetActive(true);
atmoM.SetActive(true);
atmoGO.SetActive(true);
}
}
}

View File

@ -6,42 +6,42 @@ namespace Marshmallow.Atmosphere
{
static class MakeBaseEffects
{
public static void Make(GameObject body)
public static void Make(GameObject body, Sector sector)
{
GameObject main = new GameObject();
main.SetActive(false);
main.transform.parent = body.transform;
GameObject effectsGO = new GameObject();
effectsGO.SetActive(false);
effectsGO.transform.parent = body.transform;
SectorCullGroup maincull = main.AddComponent<SectorCullGroup>();
maincull.SetValue("_sector", Main.SECTOR);
maincull.SetValue("_particleSystemSuspendMode", CullGroup.ParticleSystemSuspendMode.Stop);
maincull.SetValue("_occlusionCulling", false);
maincull.SetValue("_dynamicCullingBounds", false);
maincull.SetValue("_waitForStreaming", false);
SectorCullGroup SCG = effectsGO.AddComponent<SectorCullGroup>();
SCG.SetValue("_sector", sector);
SCG.SetValue("_particleSystemSuspendMode", CullGroup.ParticleSystemSuspendMode.Stop);
SCG.SetValue("_occlusionCulling", false);
SCG.SetValue("_dynamicCullingBounds", false);
SCG.SetValue("_waitForStreaming", false);
GameObject rain = new GameObject();
rain.SetActive(false);
rain.transform.parent = main.transform;
GameObject rainGO = new GameObject();
rainGO.SetActive(false);
rainGO.transform.parent = effectsGO.transform;
/*ParticleSystem ps = */GameObject.Instantiate(GameObject.Find("Effects_GD_Rain").GetComponent<ParticleSystem>());
VectionFieldEmitter vfe = rain.AddComponent<VectionFieldEmitter>();
vfe.fieldRadius = 20f;
vfe.particleCount = 10;
vfe.emitOnLeadingEdge = false;
vfe.emitDirection = VectionFieldEmitter.EmitDirection.Radial;
vfe.reverseDir = true;
vfe.SetValue("_affectingForces", new ForceVolume[0]);
vfe.SetValue("_applyForcePerParticle", false);
VectionFieldEmitter VFE = rainGO.AddComponent<VectionFieldEmitter>();
VFE.fieldRadius = 20f;
VFE.particleCount = 10;
VFE.emitOnLeadingEdge = false;
VFE.emitDirection = VectionFieldEmitter.EmitDirection.Radial;
VFE.reverseDir = true;
VFE.SetValue("_affectingForces", new ForceVolume[0]);
VFE.SetValue("_applyForcePerParticle", false);
PlanetaryVectionController pvc = rain.AddComponent<PlanetaryVectionController>();
pvc.SetValue("_followTarget", pvc.GetType().GetNestedType("FollowTarget", BindingFlags.NonPublic).GetField("Player").GetValue(pvc));
pvc.SetValue("_activeInSector", Main.SECTOR);
PlanetaryVectionController PVC = rainGO.AddComponent<PlanetaryVectionController>();
PVC.SetValue("_followTarget", PVC.GetType().GetNestedType("FollowTarget", BindingFlags.NonPublic).GetField("Player").GetValue(PVC));
PVC.SetValue("_activeInSector", sector);
rain.GetComponent<Renderer>().material = GameObject.Find("Effects_GD_Rain").GetComponent<Renderer>().material;
rainGO.GetComponent<Renderer>().material = GameObject.Find("Effects_GD_Rain").GetComponent<Renderer>().material;
main.SetActive(true);
rain.SetActive(true);
effectsGO.SetActive(true);
rainGO.SetActive(true);
}
}
}

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Marshmallow.External;
using Newtonsoft.Json.Linq;
using OWML.ModHelper.Events;
using UnityEngine;
@ -6,32 +7,32 @@ namespace Marshmallow.Atmosphere
{
static class MakeClouds
{
public static void Make(GameObject body, float topCloudScale, float bottomCloudScale, Color32 lowerCloudTint, Color32 upperCloudTint)
public static void Make(GameObject body, Sector sector, IPlanetConfig config)
{
GameObject cloudsMain = new GameObject();
cloudsMain.SetActive(false);
cloudsMain.transform.parent = body.transform;
GameObject cloudsMainGO = new GameObject();
cloudsMainGO.SetActive(false);
cloudsMainGO.transform.parent = body.transform;
GameObject cloudsTop = new GameObject();
cloudsTop.SetActive(false);
cloudsTop.transform.parent = cloudsMain.transform;
cloudsTop.transform.localScale = new Vector3(topCloudScale / 2, topCloudScale / 2, topCloudScale / 2);
GameObject cloudsTopGO = new GameObject();
cloudsTopGO.SetActive(false);
cloudsTopGO.transform.parent = cloudsMainGO.transform;
cloudsTopGO.transform.localScale = new Vector3(config.TopCloudSize / 2, config.TopCloudSize / 2, config.TopCloudSize / 2);
MeshFilter MF = cloudsTop.AddComponent<MeshFilter>();
MF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
MeshFilter topMF = cloudsTopGO.AddComponent<MeshFilter>();
topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
MeshRenderer MR = cloudsTop.AddComponent<MeshRenderer>();
MR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().materials;
MeshRenderer topMR = cloudsTopGO.AddComponent<MeshRenderer>();
topMR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshRenderer>().materials;
foreach (var item in MR.materials)
foreach (var material in topMR.materials)
{
item.SetColor("_Color", upperCloudTint);
material.SetColor("_Color", config.TopCloudTint.ToColor32());
}
RotateTransform RT = cloudsTop.AddComponent<RotateTransform>();
RT.SetValue("_localAxis", Vector3.up);
RT.SetValue("degreesPerSecond", 10);
RT.SetValue("randomizeRotationRate", false);
RotateTransform topRT = cloudsTopGO.AddComponent<RotateTransform>();
topRT.SetValue("_localAxis", Vector3.up);
topRT.SetValue("degreesPerSecond", 10);
topRT.SetValue("randomizeRotationRate", false);
/*
SectorCullGroup scg = cloudsTop.AddComponent<SectorCullGroup>();
@ -42,53 +43,50 @@ namespace Marshmallow.Atmosphere
scg.SetValue("_waitForStreaming", false);
*/
GameObject cloudsBottom = new GameObject();
cloudsBottom.SetActive(false);
cloudsBottom.transform.parent = cloudsMain.transform;
cloudsBottom.transform.localScale = new Vector3(bottomCloudScale / 2, bottomCloudScale / 2, bottomCloudScale / 2);
GameObject cloudsBottomGO = new GameObject();
cloudsBottomGO.SetActive(false);
cloudsBottomGO.transform.parent = cloudsMainGO.transform;
cloudsBottomGO.transform.localScale = new Vector3(config.BottomCloudSize / 2, config.BottomCloudSize / 2, config.BottomCloudSize / 2);
TessellatedSphereRenderer TSR = cloudsBottom.AddComponent<TessellatedSphereRenderer>();
TSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
TSR.sharedMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().sharedMaterials;
TessellatedSphereRenderer bottomTSR = cloudsBottomGO.AddComponent<TessellatedSphereRenderer>();
bottomTSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
bottomTSR.sharedMaterials = GameObject.Find("CloudsBottomLayer_GD").GetComponent<TessellatedSphereRenderer>().sharedMaterials;
bottomTSR.maxLOD = 6;
bottomTSR.LODBias = 0;
bottomTSR.LODRadius = 1f;
foreach (var item in TSR.sharedMaterials)
foreach (Material material in bottomTSR.sharedMaterials)
{
item.SetColor("_Color", lowerCloudTint);
material.SetColor("_Color", config.BottomCloudTint.ToColor32());
}
TSR.maxLOD = 6;
TSR.LODBias = 0;
TSR.LODRadius = 1f;
TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent<TessSphereSectorToggle>();
bottomTSST.SetValue("_sector", sector);
TessSphereSectorToggle TSST = cloudsBottom.AddComponent<TessSphereSectorToggle>();
TSST.SetValue("_sector", Main.SECTOR);
GameObject cloudsFluidGO = new GameObject();
cloudsFluidGO.SetActive(false);
cloudsFluidGO.layer = 17;
cloudsFluidGO.transform.parent = cloudsMainGO.transform;
GameObject cloudsFluid = new GameObject();
cloudsFluid.layer = 17;
cloudsFluid.SetActive(false);
cloudsFluid.transform.parent = cloudsMain.transform;
SphereCollider fluidSC = cloudsFluidGO.AddComponent<SphereCollider>();
fluidSC.isTrigger = true;
fluidSC.radius = config.TopCloudSize / 2;
SphereCollider cloudSC = cloudsFluid.AddComponent<SphereCollider>();
cloudSC.isTrigger = true;
cloudSC.radius = topCloudScale / 2;
OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent<OWShellCollider>();
fluidOWSC.SetValue("_innerRadius", config.BottomCloudSize);
OWShellCollider cloudShell = cloudsFluid.AddComponent<OWShellCollider>();
cloudShell.SetValue("_innerRadius", bottomCloudScale);
CloudLayerFluidVolume fluidCLFV = cloudsFluidGO.AddComponent<CloudLayerFluidVolume>();
fluidCLFV.SetValue("_layer", 5);
fluidCLFV.SetValue("_priority", 1);
fluidCLFV.SetValue("_density", 1.2f);
fluidCLFV.SetValue("_fluidType", FluidVolume.Type.CLOUD);
fluidCLFV.SetValue("_allowShipAutoroll", true);
fluidCLFV.SetValue("_disableOnStart", false);
CloudLayerFluidVolume cloudLayer = cloudsFluid.AddComponent<CloudLayerFluidVolume>();
cloudLayer.SetValue("_layer", 5);
cloudLayer.SetValue("_priority", 1);
cloudLayer.SetValue("_density", 1.2f);
cloudLayer.SetValue("_fluidType", FluidVolume.Type.CLOUD);
cloudLayer.SetValue("_allowShipAutoroll", true);
cloudLayer.SetValue("_disableOnStart", false);
cloudsTop.SetActive(true);
cloudsBottom.SetActive(true);
cloudsFluid.SetActive(true);
cloudsMain.SetActive(true);
Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + lowerCloudTint);
cloudsTopGO.SetActive(true);
cloudsBottomGO.SetActive(true);
cloudsFluidGO.SetActive(true);
cloudsMainGO.SetActive(true);
}
}
}

View File

@ -1,24 +1,25 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using OWML.ModHelper.Events;
using UnityEngine;
namespace Marshmallow.Atmosphere
{
static class MakeSunOverride
{
public static void Make(GameObject body, float topCloudScale, float bottomCloudScale, float waterSize)
public static void Make(GameObject body, Sector sector, IPlanetConfig config)
{
GameObject sunov = new GameObject();
sunov.SetActive(false);
sunov.transform.parent = body.transform;
GameObject overrideGO = new GameObject();
overrideGO.SetActive(false);
overrideGO.transform.parent = body.transform;
GiantsDeepSunOverrideVolume vol = sunov.AddComponent<GiantsDeepSunOverrideVolume>();
vol.SetValue("_sector", Main.SECTOR);
vol.SetValue("_cloudsOuterRadius", topCloudScale / 2);
vol.SetValue("_cloudsInnerRadius", bottomCloudScale / 2);
vol.SetValue("_waterOuterRadius", waterSize / 2);
vol.SetValue("_waterInnerRadius", 402.5f);
GiantsDeepSunOverrideVolume GDSOV = overrideGO.AddComponent<GiantsDeepSunOverrideVolume>();
GDSOV.SetValue("_sector", sector);
GDSOV.SetValue("_cloudsOuterRadius", config.TopCloudSize / 2);
GDSOV.SetValue("_cloudsInnerRadius", config.BottomCloudSize / 2);
GDSOV.SetValue("_waterOuterRadius", config.WaterSize / 2);
GDSOV.SetValue("_waterInnerRadius", 402.5f);
sunov.SetActive(true);
overrideGO.SetActive(true);
}
}
}

View File

@ -1,38 +1,39 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using OWML.ModHelper.Events;
using UnityEngine;
namespace Marshmallow.Atmosphere
{
static class MakeVolumes
{
public static void Make(GameObject body, float groundSize, float topCloudSize)
public static void Make(GameObject body, IPlanetConfig config)
{
GameObject volumes = new GameObject();
volumes.SetActive(false);
volumes.transform.parent = body.transform;
GameObject volumesGO = new GameObject();
volumesGO.SetActive(false);
volumesGO.transform.parent = body.transform;
GameObject ruleset = new GameObject();
ruleset.transform.parent = volumes.transform;
GameObject rulesetGO = new GameObject();
rulesetGO.transform.parent = volumesGO.transform;
SphereShape ss = ruleset.AddComponent<SphereShape>();
ss.SetCollisionMode(Shape.CollisionMode.Volume);
ss.SetLayer(Shape.Layer.Sector);
ss.layerMask = -1;
ss.pointChecksOnly = true;
ss.radius = topCloudSize;
SphereShape SS = rulesetGO.AddComponent<SphereShape>();
SS.SetCollisionMode(Shape.CollisionMode.Volume);
SS.SetLayer(Shape.Layer.Sector);
SS.layerMask = -1;
SS.pointChecksOnly = true;
SS.radius = config.TopCloudSize;
/*OWTriggerVolume trigvol = */ruleset.AddComponent<OWTriggerVolume>();
/*OWTriggerVolume trigvol = */rulesetGO.AddComponent<OWTriggerVolume>();
PlanetoidRuleset prule = ruleset.AddComponent<PlanetoidRuleset>();
prule.SetValue("_altitudeFloor", groundSize);
prule.SetValue("_altitudeCeiling", topCloudSize);
PlanetoidRuleset PR = rulesetGO.AddComponent<PlanetoidRuleset>();
PR.SetValue("_altitudeFloor", config.GroundSize);
PR.SetValue("_altitudeCeiling", config.TopCloudSize);
EffectRuleset er = ruleset.AddComponent<EffectRuleset>();
er.SetValue("_type", EffectRuleset.BubbleType.Underwater);
er.SetValue("_material", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_material"));
er.SetValue("_cloudMaterial", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_cloudMaterial"));
EffectRuleset ER = rulesetGO.AddComponent<EffectRuleset>();
ER.SetValue("_type", EffectRuleset.BubbleType.Underwater);
ER.SetValue("_material", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_material"));
ER.SetValue("_cloudMaterial", GameObject.Find("RulesetVolumes_GD").GetComponent<RulesetVolume>().GetValue<Material>("_cloudMaterial"));
volumes.SetActive(true);
volumesGO.SetActive(true);
}
}
}

View File

@ -6,14 +6,12 @@ namespace Marshmallow.Body
{
public static void Make(GameObject body, float groundScale)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.parent = body.transform;
sphere.transform.localScale = new Vector3(groundScale / 2, groundScale / 2, groundScale / 2);
sphere.GetComponent<MeshFilter>().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
sphere.GetComponent<SphereCollider>().radius = 1f;
sphere.SetActive(true);
GameObject groundGO = GameObject.CreatePrimitive(PrimitiveType.Sphere);
groundGO.transform.parent = body.transform;
groundGO.transform.localScale = new Vector3(groundScale / 2, groundScale / 2, groundScale / 2);
groundGO.GetComponent<MeshFilter>().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent<MeshFilter>().mesh;
groundGO.GetComponent<SphereCollider>().radius = 1f;
groundGO.SetActive(true);
/*
GameObject sphere = new GameObject();

View File

@ -1,32 +1,33 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using OWML.ModHelper.Events;
using UnityEngine;
namespace Marshmallow.Body
{
static class MakeWater
{
public static void Make(GameObject body, float waterScale)
public static void Make(GameObject body, Sector sector, IPlanetConfig config)
{
GameObject waterBase = new GameObject();
waterBase.SetActive(false);
waterBase.layer = 15;
waterBase.transform.parent = body.transform;
waterBase.transform.localScale = new Vector3(waterScale / 2, waterScale / 2, waterScale / 2);
waterBase.DestroyAllComponents<SphereCollider>();
GameObject waterGO = new GameObject();
waterGO.SetActive(false);
waterGO.layer = 15;
waterGO.transform.parent = body.transform;
waterGO.transform.localScale = new Vector3(config.WaterSize / 2, config.WaterSize / 2, config.WaterSize / 2);
waterGO.DestroyAllComponents<SphereCollider>();
TessellatedSphereRenderer tsr = waterBase.AddComponent<TessellatedSphereRenderer>();
tsr.tessellationMeshGroup = GameObject.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
tsr.sharedMaterials = GameObject.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>().sharedMaterials;
tsr.maxLOD = 7;
tsr.LODBias = 2;
tsr.LODRadius = 2f;
TessellatedSphereRenderer TSR = waterGO.AddComponent<TessellatedSphereRenderer>();
TSR.tessellationMeshGroup = GameObject.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>().tessellationMeshGroup;
TSR.sharedMaterials = GameObject.Find("Ocean_GD").GetComponent<TessellatedSphereRenderer>().sharedMaterials;
TSR.maxLOD = 7;
TSR.LODBias = 2;
TSR.LODRadius = 2f;
TessSphereSectorToggle toggle = waterBase.AddComponent<TessSphereSectorToggle>();
toggle.SetValue("_sector", Main.SECTOR);
TessSphereSectorToggle TSST = waterGO.AddComponent<TessSphereSectorToggle>();
TSST.SetValue("_sector", sector);
OceanEffectController effectC = waterBase.AddComponent<OceanEffectController>();
effectC.SetValue("_sector", Main.SECTOR);
effectC.SetValue("_ocean", tsr);
OceanEffectController OEC = waterGO.AddComponent<OceanEffectController>();
OEC.SetValue("_sector", sector);
OEC.SetValue("_ocean", TSR);
// Because assetbundles were a bitch...
@ -55,9 +56,9 @@ namespace Marshmallow.Body
*/
waterBase.SetActive(true);
waterGO.SetActive(true);
//Main.Log("Water - waterScale : " + waterScale);
//Logger.Log("Water - waterScale : " + waterScale);
}
}
}

View File

@ -10,25 +10,26 @@ namespace Marshmallow.External
{
public interface IPlanetConfig
{
string name { get; }
MVector3 position { get; }
int orbitAngle { get; }
string primaryBody { get; }
bool hasSpawnPoint { get; }
bool hasClouds { get; }
float topCloudSize { get; }
float bottomCloudSize { get; }
MColor32 topCloudTint { get; }
MColor32 bottomCloudTint { get; }
bool hasWater { get; }
float waterSize { get; }
bool hasRain { get; }
bool hasGravity { get; }
float surfaceAcceleration { get; }
bool hasMapMarker { get; }
bool hasFog { get; }
MColor32 fogTint { get; }
float fogDensity { get; }
float groundSize { get; }
string Name { get; }
MVector3 Position { get; }
int OrbitAngle { get; }
string PrimaryBody { get; }
bool IsMoon { get; }
bool HasSpawnPoint { get; }
bool HasClouds { get; }
float TopCloudSize { get; }
float BottomCloudSize { get; }
MColor32 TopCloudTint { get; }
MColor32 BottomCloudTint { get; }
bool HasWater { get; }
float WaterSize { get; }
bool HasRain { get; }
bool HasGravity { get; }
float SurfaceAcceleration { get; }
bool HasMapMarker { get; }
bool HasFog { get; }
MColor32 FogTint { get; }
float FogDensity { get; }
float GroundSize { get; }
}
}

View File

@ -11,25 +11,26 @@ namespace Marshmallow.External
{
public class PlanetConfig : IPlanetConfig
{
public string name { get; set; }
public MVector3 position { get; set; }
public int orbitAngle { get; set; }
public string primaryBody { get; set; }
public bool hasSpawnPoint { get; set; }
public bool hasClouds { get; set; }
public float topCloudSize { get; set; }
public float bottomCloudSize { get; set; }
public MColor32 topCloudTint { get; set; }
public MColor32 bottomCloudTint { get; set; }
public bool hasWater { get; set; }
public float waterSize { get; set; }
public bool hasRain { get; set; }
public bool hasGravity { get; set; }
public float surfaceAcceleration { get; set; }
public bool hasMapMarker { get; set; }
public bool hasFog { get; set; }
public MColor32 fogTint { get; set; }
public float fogDensity { get; set; }
public float groundSize { get; set; }
public string Name { get; set; }
public MVector3 Position { get; set; }
public int OrbitAngle { get; set; }
public string PrimaryBody { get; set; }
public bool IsMoon { get; set; }
public bool HasSpawnPoint { get; set; }
public bool HasClouds { get; set; }
public float TopCloudSize { get; set; }
public float BottomCloudSize { get; set; }
public MColor32 TopCloudTint { get; set; }
public MColor32 BottomCloudTint { get; set; }
public bool HasWater { get; set; }
public float WaterSize { get; set; }
public bool HasRain { get; set; }
public bool HasGravity { get; set; }
public float SurfaceAcceleration { get; set; }
public bool HasMapMarker { get; set; }
public bool HasFog { get; set; }
public MColor32 FogTint { get; set; }
public float FogDensity { get; set; }
public float GroundSize { get; set; }
}
}

View File

@ -4,23 +4,24 @@ namespace Marshmallow.General
{
static class MakeAmbientLight
{
public static void Make(GameObject body)
public static void Make(GameObject body, Sector sector)
{
GameObject light = new GameObject();
light.SetActive(false);
light.transform.parent = body.transform;
Light l = light.AddComponent<Light>();
l.type = LightType.Point;
l.range = 700f;
l.color = Color.red;
l.intensity = 0.8f;
l.shadows = LightShadows.None;
l.cookie = GameObject.Find("AmbientLight_GD").GetComponent<Light>().cookie;
GameObject lightGO = new GameObject();
lightGO.SetActive(false);
lightGO.transform.parent = body.transform;
SectorLightsCullGroup cg = light.AddComponent<SectorLightsCullGroup>();
cg.SetSector(Main.SECTOR);
Light L = lightGO.AddComponent<Light>();
L.type = LightType.Point;
L.range = 700f;
L.color = Color.red;
L.intensity = 0.8f;
L.shadows = LightShadows.None;
L.cookie = GameObject.Find("AmbientLight_GD").GetComponent<Light>().cookie;
light.SetActive(true);
SectorLightsCullGroup SLCG = lightGO.AddComponent<SectorLightsCullGroup>();
SLCG.SetSector(sector);
lightGO.SetActive(true);
}
}
}

View File

@ -1,24 +1,26 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using OWML.ModHelper.Events;
using UnityEngine;
namespace Marshmallow.General
{
static class MakeFieldDetector
{
public static void Make(GameObject body)
public static void Make(GameObject body, AstroObject primaryBody, IPlanetConfig config)
{
GameObject FieldDetector = new GameObject();
FieldDetector.SetActive(false);
FieldDetector.name = "FieldDetector";
FieldDetector.transform.parent = body.transform;
FieldDetector.layer = 20;
GameObject detectorGO = new GameObject();
detectorGO.SetActive(false);
detectorGO.name = "FieldDetector";
detectorGO.transform.parent = body.transform;
detectorGO.layer = 20;
ConstantForceDetector CFD = FieldDetector.AddComponent<ConstantForceDetector>();
ConstantForceDetector CFD = detectorGO.AddComponent<ConstantForceDetector>();
ForceVolume[] temp = new ForceVolume[1];
temp[0] = Locator.GetAstroObject(AstroObject.Name.Sun).GetGravityVolume();
temp[0] = primaryBody.GetAttachedOWRigidbody().GetAttachedGravityVolume();
CFD.SetValue("_detectableFields", temp);
CFD.SetValue("_inheritElement0", false);
FieldDetector.SetActive(true);
CFD.SetValue("_inheritElement0", config.IsMoon);
detectorGO.SetActive(true);
}
}
}

View File

@ -8,13 +8,13 @@ namespace Marshmallow.General
{
public static GravityVolume Make(GameObject body, float surfaceAccel, float upperSurface, float lowerSurface)
{
GameObject GravityWell = new GameObject();
GravityWell.transform.parent = body.transform;
GravityWell.name = "GravityWell";
GravityWell.layer = 17;
GravityWell.SetActive(false);
GameObject gravityGO = new GameObject();
gravityGO.transform.parent = body.transform;
gravityGO.name = "GravityWell";
gravityGO.layer = 17;
gravityGO.SetActive(false);
GravityVolume GV = GravityWell.AddComponent<GravityVolume>();
GravityVolume GV = gravityGO.AddComponent<GravityVolume>();
GV.SetValue("_cutoffAcceleration", 0.1f);
GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("linear").GetValue(GV));
GV.SetValue("_alignmentRadius", 600f);
@ -28,13 +28,15 @@ namespace Marshmallow.General
GV.SetValue("_isPlanetGravityVolume", true);
GV.SetValue("_cutoffRadius", 55f);
SphereCollider GV_SC = GravityWell.AddComponent<SphereCollider>();
GV_SC.isTrigger = true;
GV_SC.radius = 4000;
SphereCollider SC = gravityGO.AddComponent<SphereCollider>();
SC.isTrigger = true;
SC.radius = 4000;
OWCollider OWC = gravityGO.AddComponent<OWCollider>();
OWC.SetLODActivationMask(DynamicOccupant.Player);
gravityGO.SetActive(true);
OWCollider GV_OWC = GravityWell.AddComponent<OWCollider>();
GV_OWC.SetLODActivationMask(DynamicOccupant.Player);
GravityWell.SetActive(true);
return GV;
}
}

View File

@ -1,4 +1,5 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using OWML.ModHelper.Events;
using System.Reflection;
using UnityEngine;
@ -6,13 +7,19 @@ namespace Marshmallow.General
{
static class MakeMapMarker
{
public static void Make(GameObject body, string name)
public static void Make(GameObject body, IPlanetConfig config)
{
var MM = body.AddComponent<MapMarker>();
MM.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(name));
MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM));
MapMarker MM = body.AddComponent<MapMarker>();
MM.SetValue("_labelID", (UITextType)Utility.AddToUITable.Add(config.Name));
Main.Log("Map Marker - body : " + body.name + ", labelID : " + name);
if (config.IsMoon)
{
MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Moon").GetValue(MM));
}
else
{
MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM));
}
}
}
}

View File

@ -1,9 +1,11 @@
using OWML.ModHelper.Events;
using Marshmallow.Utility;
using OWML.ModHelper.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Logger = Marshmallow.Utility.Logger;
namespace Marshmallow.General
{
@ -11,6 +13,8 @@ namespace Marshmallow.General
{
public static void Make(GameObject body, AstroObject astroobject)
{
Logger.Log("MakeOrbitLine not finished!", Logger.LogType.Todo);
GameObject orbit = new GameObject();
orbit.transform.parent = body.transform;

View File

@ -1,11 +1,13 @@
using OWML.ModHelper.Events;
using Marshmallow.External;
using Marshmallow.Utility;
using OWML.ModHelper.Events;
using UnityEngine;
namespace Marshmallow.General
{
static class MakeOrbitingAstroObject
{
public static AstroObject Make(GameObject body, float angularSpeed, float orbitAngle, bool hasGravity, float surfaceAccel, float groundSize)
public static OWRigidbody Make(GameObject body, AstroObject primaryBody, IPlanetConfig config)
{
Rigidbody RB = body.AddComponent<Rigidbody>();
RB.mass = 10000;
@ -16,36 +18,36 @@ namespace Marshmallow.General
RB.interpolation = RigidbodyInterpolation.None;
RB.collisionDetectionMode = CollisionDetectionMode.Discrete;
Main.OWRB = body.AddComponent<OWRigidbody>();
Main.OWRB.SetValue("_kinematicSimulation", true);
Main.OWRB.SetValue("_autoGenerateCenterOfMass", true);
Main.OWRB.SetIsTargetable(true);
Main.OWRB.SetValue("_maintainOriginalCenterOfMass", true);
Main.OWRB.SetValue("_rigidbody", RB);
OWRigidbody OWRB = body.AddComponent<OWRigidbody>();
OWRB.SetValue("_kinematicSimulation", true);
OWRB.SetValue("_autoGenerateCenterOfMass", true);
OWRB.SetIsTargetable(true);
OWRB.SetValue("_maintainOriginalCenterOfMass", true);
OWRB.SetValue("_rigidbody", RB);
InitialMotion IM = body.AddComponent<InitialMotion>();
IM.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun).GetAttachedOWRigidbody());
IM.SetValue("_orbitAngle", orbitAngle);
Main.Log("Got orbit angle as " + orbitAngle);
IM.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody());
IM.SetValue("_orbitAngle", config.OrbitAngle);
IM.SetValue("_isGlobalAxis", false);
IM.SetValue("_initAngularSpeed", angularSpeed);
IM.SetValue("_initAngularSpeed", 0.02f);
IM.SetValue("_initLinearSpeed", 0f);
IM.SetValue("_isGlobalAxis", false);
MakeFieldDetector.Make(body);
MakeFieldDetector.Make(body, primaryBody, config);
AstroObject AO = body.AddComponent<AstroObject>();
AO.SetValue("_type", AstroObject.Type.Planet);
AO.SetValue("_name", AstroObject.Name.None);
AO.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun));
if (hasGravity)
AO.SetPrimaryBody(primaryBody);
if (config.HasGravity)
{
GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize);
GravityVolume GV = MakeGravityWell.Make(body, config.SurfaceAcceleration, config.GroundSize, config.GroundSize);
AO.SetValue("_gravityVolume", GV);
}
MakeOrbitLine.Make(body, AO);
return AO;
//return new Tuple(AO, rigidbody);
return OWRB;
}
}
}

View File

@ -5,34 +5,37 @@ namespace Marshmallow.General
{
static class MakeRFVolume
{
public static void Make(GameObject body)
public static void Make(GameObject body, OWRigidbody rigidbody)
{
GameObject RFVolume = new GameObject("RFVolume");
RFVolume.transform.parent = body.transform;
RFVolume.layer = 19;
RFVolume.SetActive(false);
GameObject rfGO = new GameObject("RFVolume");
rfGO.transform.parent = body.transform;
rfGO.layer = 19;
rfGO.SetActive(false);
SphereCollider RF_SC = RFVolume.AddComponent<SphereCollider>();
RF_SC.isTrigger = true;
RF_SC.radius = 600f;
SphereCollider SC = rfGO.AddComponent<SphereCollider>();
SC.isTrigger = true;
SC.radius = 600f;
ReferenceFrameVolume RF_RFV = RFVolume.AddComponent<ReferenceFrameVolume>();
ReferenceFrame test = new ReferenceFrame(Main.OWRB);
test.SetValue("_minSuitTargetDistance", 300);
test.SetValue("_maxTargetDistance", 0);
test.SetValue("_autopilotArrivalDistance", 1000);
test.SetValue("_autoAlignmentDistance", 1000);
test.SetValue("_hideLandingModePrompt", false);
test.SetValue("_matchAngularVelocity", true);
test.SetValue("_minMatchAngularVelocityDistance", 70);
test.SetValue("_maxMatchAngularVelocityDistance", 400);
test.SetValue("_bracketsRadius", 300);
RF_RFV.SetValue("_referenceFrame", test);
RF_RFV.SetValue("_minColliderRadius", 300);
RF_RFV.SetValue("_maxColliderRadius", 2000);
RF_RFV.SetValue("_isPrimaryVolume", true);
RF_RFV.SetValue("_isCloseRangeVolume", false);
RFVolume.SetActive(true);
ReferenceFrameVolume RFV = rfGO.AddComponent<ReferenceFrameVolume>();
ReferenceFrame RV = new ReferenceFrame(rigidbody);
RV.SetValue("_minSuitTargetDistance", 300);
RV.SetValue("_maxTargetDistance", 0);
RV.SetValue("_autopilotArrivalDistance", 1000);
RV.SetValue("_autoAlignmentDistance", 1000);
RV.SetValue("_hideLandingModePrompt", false);
RV.SetValue("_matchAngularVelocity", true);
RV.SetValue("_minMatchAngularVelocityDistance", 70);
RV.SetValue("_maxMatchAngularVelocityDistance", 400);
RV.SetValue("_bracketsRadius", 300);
RFV.SetValue("_referenceFrame", RV);
RFV.SetValue("_minColliderRadius", 300);
RFV.SetValue("_maxColliderRadius", 2000);
RFV.SetValue("_isPrimaryVolume", true);
RFV.SetValue("_isCloseRangeVolume", false);
rfGO.SetActive(true);
}
}
}

View File

@ -6,30 +6,30 @@ namespace Marshmallow.Body
{
static class MakeSector
{
public static Sector Make(GameObject body, float sectorSize)
public static Sector Make(GameObject body, OWRigidbody rigidbody, float sectorSize)
{
GameObject sectorBase = new GameObject();
sectorBase.SetActive(false);
sectorBase.transform.parent = body.transform;
GameObject sectorGO = new GameObject();
sectorGO.SetActive(false);
sectorGO.transform.parent = body.transform;
SphereShape sphereshape = sectorBase.AddComponent<SphereShape>();
sphereshape.SetCollisionMode(Shape.CollisionMode.Volume);
sphereshape.SetLayer(Shape.Layer.Sector);
sphereshape.layerMask = -1;
sphereshape.pointChecksOnly = true;
sphereshape.radius = 700f;
sphereshape.center = Vector3.zero;
SphereShape SS = sectorGO.AddComponent<SphereShape>();
SS.SetCollisionMode(Shape.CollisionMode.Volume);
SS.SetLayer(Shape.Layer.Sector);
SS.layerMask = -1;
SS.pointChecksOnly = true;
SS.radius = 700f;
SS.center = Vector3.zero;
/*OWTriggerVolume trigVol = */sectorBase.AddComponent<OWTriggerVolume>();
/*OWTriggerVolume trigVol = */sectorGO.AddComponent<OWTriggerVolume>();
Sector sector = sectorBase.AddComponent<Sector>();
sector.SetValue("_name", Sector.Name.InvisiblePlanet);
sector.SetValue("__attachedOWRigidbody", Main.OWRB);
sector.SetValue("_subsectors", new List<Sector>());
Sector S = sectorGO.AddComponent<Sector>();
S.SetValue("_name", Sector.Name.InvisiblePlanet);
S.SetValue("__attachedOWRigidbody", rigidbody);
S.SetValue("_subsectors", new List<Sector>());
sectorBase.SetActive(true);
sectorGO.SetActive(true);
return sector;
return S;
}
}
}

View File

@ -6,15 +6,17 @@ namespace Marshmallow.General
{
public static SpawnPoint Make(GameObject body, Vector3 position)
{
GameObject spawn = new GameObject();
spawn.transform.parent = body.transform;
spawn.layer = 8;
GameObject spawnGO = new GameObject();
spawnGO.transform.parent = body.transform;
spawnGO.layer = 8;
spawn.transform.localPosition = position;
spawnGO.transform.localPosition = position;
//Main.Log("Made spawnpoint on [" + body.name + "] at " + position);
//Logger.Log("Made spawnpoint on [" + body.name + "] at " + position);
return spawn.AddComponent<SpawnPoint>();
var SS = spawnGO.AddComponent<SpawnPoint>();
return SS;
}
}
}

View File

@ -1,27 +1,22 @@
using Marshmallow.External;
using Marshmallow.Utility;
using Newtonsoft.Json.Linq;
using OWML.Common;
using OWML.ModHelper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using Logger = Marshmallow.Utility.Logger;
namespace Marshmallow
{
public class Main : ModBehaviour
{
public static OWRigidbody OWRB;
public static Sector SECTOR;
public static SpawnPoint SPAWN;
public static AstroObject ASTROOBJECT;
public static IModHelper helper;
GameObject planet;
static List<PlanetConfig> planetList = new List<PlanetConfig>();
public static List<MarshmallowBody> planetList = new List<MarshmallowBody>();
public override object GetApi()
{
@ -30,113 +25,98 @@ namespace Marshmallow
void Start()
{
base.ModHelper.Events.Subscribe<Flashlight>(Events.AfterStart);
IModEvents events = base.ModHelper.Events;
events.OnEvent = (Action<MonoBehaviour, Events>)Delegate.Combine(events.OnEvent, new Action<MonoBehaviour, Events>(this.OnEvent));
SceneManager.sceneLoaded += OnSceneLoaded;
helper = base.ModHelper;
Main.Log("Begin load of planet config...");
Logger.Log("Begin load of planet config...", Logger.LogType.Log);
try
{
foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\"))
{
PlanetConfig config = ModHelper.Storage.Load<PlanetConfig>(file.Replace(ModHelper.Manifest.ModFolderPath, ""));
planetList.Add(config);
planetList.Add(new MarshmallowBody(config));
Main.Log("* " + config.name + " at position " + config.position.ToVector3());
Logger.Log("* " + config.Name + " at position " + config.Position.ToVector3() + " relative to " + config.PrimaryBody + ". Moon? : " + config.IsMoon, Logger.LogType.Log);
}
}
catch (Exception ex)
{
Main.Log("Error! - " + ex.Message);
Logger.Log("Error! - " + ex.Message, Logger.LogType.Error);
}
if (planetList.Count != 0)
{
Main.Log("Loaded [" + planetList.Count + "] planet config files.");
Logger.Log("Loaded [" + planetList.Count + "] planet config files.", Logger.LogType.Log);
}
else
{
Main.Log("ERROR! - No planet config files found!");
Logger.Log("No planet config files found!", Logger.LogType.Warning);
}
}
private void OnEvent(MonoBehaviour behaviour, Events ev)
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
bool flag = behaviour.GetType() == typeof(Flashlight) && ev == Events.AfterStart;
if (flag)
foreach (var planet in planetList)
{
foreach (var config in planetList)
{
planet = GenerateBody(config);
var planetObject = GenerateBody(planet.Config);
planet.transform.parent = Locator.GetRootTransform();
planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).gameObject.transform.position + config.position.ToVector3();
planet.SetActive(true);
var primayBody = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(planet.Config.PrimaryBody));
try
{
OWRB.SetVelocity(Locator.GetCenterOfTheUniverse().GetOffsetVelocity());
var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).GetAttachedOWRigidbody();
var initialMotion = primary.GetComponent<InitialMotion>();
if (initialMotion != null)
{
OWRB.AddVelocityChange(-initialMotion.GetInitVelocity());
}
OWRB.AddVelocityChange(primary.GetVelocity());
}
catch { }
}
planetObject.transform.parent = Locator.GetRootTransform();
planetObject.transform.position = primayBody.gameObject.transform.position + planet.Config.Position.ToVector3();
planetObject.SetActive(true);
planet.Object = planetObject;
}
}
public static GameObject GenerateBody(IPlanetConfig config)
{
Main.Log("Begin generation sequence of planet [" + config.name + "] ...");
Logger.Log("Begin generation sequence of planet [" + config.Name + "] ...", Logger.LogType.Log);
GameObject body;
body = new GameObject(config.name);
body = new GameObject(config.Name);
body.SetActive(false);
Body.MakeGeometry.Make(body, config.groundSize);
Body.MakeGeometry.Make(body, config.GroundSize);
ASTROOBJECT = General.MakeOrbitingAstroObject.Make(body, 0.02f, config.orbitAngle, config.hasGravity, config.surfaceAcceleration, config.groundSize);
General.MakeRFVolume.Make(body);
var owRigidbody = General.MakeOrbitingAstroObject.Make(body, Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)), config);
General.MakeRFVolume.Make(body, owRigidbody);
if (config.hasMapMarker)
if (config.HasMapMarker)
{
General.MakeMapMarker.Make(body, config.name);
General.MakeMapMarker.Make(body, config);
}
SECTOR = Body.MakeSector.Make(body, config.topCloudSize);
var sector = Body.MakeSector.Make(body, owRigidbody, config.TopCloudSize);
if (config.hasClouds)
if (config.HasClouds)
{
Atmosphere.MakeClouds.Make(body, config.topCloudSize, config.bottomCloudSize, config.bottomCloudTint.ToColor32(), config.topCloudTint.ToColor32());
Atmosphere.MakeSunOverride.Make(body, config.topCloudSize, config.bottomCloudSize, config.waterSize);
Atmosphere.MakeClouds.Make(body, sector, config);
Atmosphere.MakeSunOverride.Make(body, sector, config);
}
Atmosphere.MakeAir.Make(body, config.topCloudSize / 2, config.hasRain);
Atmosphere.MakeAir.Make(body, config.TopCloudSize / 2, config.HasRain);
if (config.hasWater)
if (config.HasWater)
{
Body.MakeWater.Make(body, config.waterSize);
Body.MakeWater.Make(body, sector, config);
}
Atmosphere.MakeBaseEffects.Make(body);
Atmosphere.MakeVolumes.Make(body, config.groundSize, config.topCloudSize);
General.MakeAmbientLight.Make(body);
Atmosphere.MakeAtmosphere.Make(body, config.topCloudSize, config.hasFog, config.fogDensity, config.fogTint.ToColor32());
Atmosphere.MakeBaseEffects.Make(body, sector);
Atmosphere.MakeVolumes.Make(body, config);
General.MakeAmbientLight.Make(body, sector);
Atmosphere.MakeAtmosphere.Make(body, config);
if (config.hasSpawnPoint)
if (config.HasSpawnPoint)
{
SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, config.groundSize + 10, 0));
General.MakeSpawnPoint.Make(body, new Vector3(0, config.GroundSize + 10, 0));
}
Main.Log("Generation of planet [" + config.name + "] completed.");
Logger.Log("Generation of planet [" + config.Name + "] completed.", Logger.LogType.Log);
return body;
}
@ -146,12 +126,12 @@ namespace Marshmallow
var planet = Main.GenerateBody(config);
planet.transform.parent = Locator.GetRootTransform();
planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).gameObject.transform.position + config.position.ToVector3();
planet.transform.position = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)).gameObject.transform.position + config.Position.ToVector3();
planet.SetActive(true);
planet.GetComponent<OWRigidbody>().SetVelocity(Locator.GetCenterOfTheUniverse().GetOffsetVelocity());
var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.primaryBody)).GetAttachedOWRigidbody();
var primary = Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)).GetAttachedOWRigidbody();
var initialMotion = primary.GetComponent<InitialMotion>();
if (initialMotion != null)
{
@ -159,11 +139,6 @@ namespace Marshmallow
planet.GetComponent<OWRigidbody>().AddVelocityChange(primary.GetVelocity());
}
}
public static void Log(string text)
{
helper.Console.WriteLine(text);
}
}
public class MarshmallowApi
@ -172,29 +147,35 @@ namespace Marshmallow
{
var planetConfig = new PlanetConfig
{
name = (string)config["name"],
position = (MVector3)config["position"],
orbitAngle = (int)config["orbitAngle"],
primaryBody = (string)config["primaryBody"],
hasSpawnPoint = (bool)config["hasSpawnPoint"],
hasClouds = (bool)config["hasClouds"],
topCloudSize = (float)config["topCloudSize"],
bottomCloudSize = (float)config["bottomCloudSize"],
topCloudTint = (MColor32)config["topCloudTint"],
bottomCloudTint = (MColor32)config["bottomCloudTint"],
hasWater = (bool)config["hasWater"],
waterSize = (float)config["waterSize"],
hasRain = (bool)config["hasRain"],
hasGravity = (bool)config["hasGravity"],
surfaceAcceleration = (float)config["surfaceAcceleration"],
hasMapMarker = (bool)config["hasMapMarker"],
hasFog = (bool)config["hasFog"],
fogTint = (MColor32)config["fogTint"],
fogDensity = (float)config["fogDensity"],
groundSize = (float)config["groundScale"]
Name = (string)config["name"],
Position = (MVector3)config["position"],
OrbitAngle = (int)config["orbitAngle"],
IsMoon = (bool)config["isMoon"],
PrimaryBody = (string)config["primaryBody"],
HasSpawnPoint = (bool)config["hasSpawnPoint"],
HasClouds = (bool)config["hasClouds"],
TopCloudSize = (float)config["topCloudSize"],
BottomCloudSize = (float)config["bottomCloudSize"],
TopCloudTint = (MColor32)config["topCloudTint"],
BottomCloudTint = (MColor32)config["bottomCloudTint"],
HasWater = (bool)config["hasWater"],
WaterSize = (float)config["waterSize"],
HasRain = (bool)config["hasRain"],
HasGravity = (bool)config["hasGravity"],
SurfaceAcceleration = (float)config["surfaceAcceleration"],
HasMapMarker = (bool)config["hasMapMarker"],
HasFog = (bool)config["hasFog"],
FogTint = (MColor32)config["fogTint"],
FogDensity = (float)config["fogDensity"],
GroundSize = (float)config["groundScale"]
};
Main.CreateBody(planetConfig);
}
public GameObject GetPlanet(string name)
{
return Main.planetList.FirstOrDefault(x => x.Config.Name == name).Object;
}
}
}

View File

@ -106,9 +106,12 @@
<Compile Include="Atmosphere\MakeVolumes.cs" />
<Compile Include="Body\MakeWater.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utility\Logger.cs" />
<Compile Include="Utility\MarshmallowExtensions.cs" />
<Compile Include="Utility\MVector3.cs" />
<Compile Include="Utility\MColor32.cs" />
<Compile Include="Utility\MarshmallowBody.cs" />
<Compile Include="Utility\Tuple.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />

View File

@ -12,7 +12,7 @@ namespace Marshmallow.Utility
instance.Insert_UI(instance.theUITable.Keys.Max() + 1, text);
Main.Log($"Added [{text}] to UI table with key [{instance.theUITable.Keys.Max()}]");
Logger.Log($"Added [{text}] to UI table with key [{instance.theUITable.Keys.Max()}]", Logger.LogType.Log);
return instance.theUITable.Keys.Max();
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Marshmallow.Utility
{
public class Logger
{
public static void Log(string text, LogType type)
{
Main.helper.Console.WriteLine(Enum.GetName(typeof(LogType), type) + " : " + text);
}
public enum LogType
{
Log,
Error,
Warning,
Todo
}
}
}

View File

@ -0,0 +1,21 @@
using Marshmallow.External;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Marshmallow.Utility
{
public class MarshmallowBody
{
public MarshmallowBody(IPlanetConfig config)
{
Config = config;
}
public IPlanetConfig Config;
public GameObject Object;
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Marshmallow.Utility
{
public class Tuple
{
public Tuple(params object[] _items)
{
Items = _items.ToList();
}
public List<object> Items { get; }
}
}