void Start() { SceneManager.sceneLoaded += OnSceneLoaded; helper = base.ModHelper; Logger.Log("Begin load of config files...", Logger.LogType.Log); try { foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\")) { var config = ModHelper.Storage.Load <PlanetConfig>(file.Replace(ModHelper.Manifest.ModFolderPath, "")); BodyList.Add(new MarshmallowBody(config)); Logger.Log("* " + config.Name + " at position " + config.Position.ToVector3() + " relative to " + config.PrimaryBody + ". Moon? : " + config.IsMoon, Logger.LogType.Log); } } catch (Exception ex) { Logger.Log("Error! - " + ex.Message, Logger.LogType.Error); } if (BodyList.Count != 0) { Logger.Log("Loaded [" + BodyList.Count + "] config files.", Logger.LogType.Log); } else { Logger.Log("No config files found!", Logger.LogType.Warning); } }
public void Create(Dictionary <string, object> config) { Logger.Log("Recieved API request to create planet " + (string)config["Name"] + " at position " + (Vector3)config["Position"], Logger.LogType.Log); var planetConfig = new PlanetConfig { Name = (string)config["Name"], Position = new MVector3(((Vector3)config["Position"]).x, ((Vector3)config["Position"]).y, ((Vector3)config["Position"]).z), OrbitAngle = (int)config["OrbitAngle"], IsMoon = (bool)config["IsMoon"], AtmoEndSize = (float)config["AtmoEndSize"], PrimaryBody = (string)config["PrimaryBody"], HasClouds = (bool)config["HasClouds"], TopCloudSize = (float)config["TopCloudSize"], BottomCloudSize = (float)config["BottomCloudSize"], TopCloudTint = new MColor32(((Color32)config["TopCloudTint"]).r, ((Color32)config["TopCloudTint"]).g, ((Color32)config["TopCloudTint"]).b, ((Color32)config["TopCloudTint"]).a), BottomCloudTint = new MColor32(((Color32)config["BottomCloudTint"]).r, ((Color32)config["BottomCloudTint"]).g, ((Color32)config["BottomCloudTint"]).b, ((Color32)config["BottomCloudTint"]).a), 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 = new MColor32(((Color32)config["FogTint"]).r, ((Color32)config["FogTint"]).g, ((Color32)config["FogTint"]).b, ((Color32)config["FogTint"]).a), FogDensity = (float)config["FogDensity"], HasGround = (bool)config["HasGround"], GroundSize = (float)config["GroundSize"], IsTidallyLocked = (bool)config["IsTidallyLocked"], LightTint = new MColor32(((Color32)config["LightTint"]).r, ((Color32)config["LightTint"]).g, ((Color32)config["LightTint"]).b, ((Color32)config["LightTint"]).a), }; Main.BodyList.Add(new MarshmallowBody(planetConfig)); Main.helper.Events.Unity.RunWhen(() => Locator.GetCenterOfTheUniverse() != null, () => Main.CreateBody(planetConfig)); }
public static MTuple Make(GameObject body, AstroObject primaryBody, IPlanetConfig config) { Rigidbody RB = body.AddComponent <Rigidbody>(); RB.mass = 10000; RB.drag = 0f; RB.angularDrag = 0f; RB.useGravity = false; RB.isKinematic = true; RB.interpolation = RigidbodyInterpolation.None; RB.collisionDetectionMode = CollisionDetectionMode.Discrete; 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(primaryBody.GetAttachedOWRigidbody()); IM.SetValue("_orbitAngle", config.OrbitAngle); IM.SetValue("_isGlobalAxis", false); IM.SetValue("_initAngularSpeed", 0.02f); IM.SetValue("_initLinearSpeed", 0f); DetectorBuilder.Make(body, primaryBody); AstroObject AO = body.AddComponent <AstroObject>(); AO.SetValue("_type", AstroObject.Type.Planet); AO.SetValue("_name", AstroObject.Name.None); AO.SetValue("_primaryBody", primaryBody); if (config.HasGravity) { GravityVolume GV = GravityBuilder.Make(body, config.SurfaceAcceleration, config.GroundSize, config.GroundSize); AO.SetValue("_gravityVolume", GV); } if (config.IsTidallyLocked) { RotateToAstroObject RTAO = body.AddComponent <RotateToAstroObject>(); RTAO.SetValue("_astroObjectLock", primaryBody); } Logger.Log("Finished building base", Logger.LogType.Log); return(new MTuple(AO, OWRB)); }
public static GameObject GenerateBody(IPlanetConfig config) { Logger.Log("Begin generation sequence of [" + config.Name + "] ...", Logger.LogType.Log); var body = new GameObject(config.Name); body.SetActive(false); GeometryBuilder.Make(body, config.GroundSize); var outputTuple = BaseBuilder.Make(body, Locator.GetAstroObject(AstroObject.StringIDToAstroObjectName(config.PrimaryBody)), config); var owRigidbody = (OWRigidbody)outputTuple.Items[1]; RFVolumeBuilder.Make(body, owRigidbody, config); if (config.HasMapMarker) { MarkerBuilder.Make(body, config); } var sector = MakeSector.Make(body, owRigidbody, config); if (config.HasClouds) { CloudsBuilder.Make(body, sector, config); SunOverrideBuilder.Make(body, sector, config); } AirBuilder.Make(body, config.TopCloudSize / 2, config.HasRain); if (config.HasWater) { WaterBuilder.Make(body, sector, config); } EffectsBuilder.Make(body, sector); VolumesBuilder.Make(body, config); AmbientLightBuilder.Make(body, sector, config); AtmosphereBuilder.Make(body, config); Logger.Log("Generation of [" + config.Name + "] completed.", Logger.LogType.Log); return(body); }
public static void Make(GameObject body, AstroObject astroobject) { GameObject orbit = new GameObject(); orbit.transform.parent = body.transform; var LR = orbit.AddComponent <LineRenderer>(); //LR.material = GameObject.Find("OrbitLine_TH").GetComponent<LineRenderer>().material; LR.useWorldSpace = false; LR.loop = false; Logger.Log("AO primary body is " + astroobject.GetPrimaryBody().name, Logger.LogType.Log); var ol = orbit.AddComponent <OrbitLine>(); ol.SetValue("_astroObject", astroobject); ol.SetValue("_fade", false); ol.SetValue("_lineWidth", 5); Logger.Log("Finished building orbit line", Logger.LogType.Log); }
public static void Make(GameObject body, Sector sector, IPlanetConfig config) { GameObject cloudsMainGO = new GameObject(); cloudsMainGO.SetActive(false); cloudsMainGO.transform.parent = body.transform; 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); //AddDebugShape.AddSphere(cloudsTopGO, config.TopCloudSize/2, new Color32(255, 0, 255, 128)); MeshFilter topMF = cloudsTopGO.AddComponent <MeshFilter>(); topMF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent <MeshFilter>().mesh; var tempArray = new Material[2]; MeshRenderer topMR = cloudsTopGO.AddComponent <MeshRenderer>(); for (int i = 0; i < 2; i++) { tempArray[i] = GameObject.Instantiate(GameObject.Find("CloudsTopLayer_GD").GetComponent <MeshRenderer>().sharedMaterials[i]); } topMR.sharedMaterials = tempArray; foreach (var material in topMR.sharedMaterials) { material.SetColor("_Color", config.TopCloudTint.ToColor32()); var image = ImageUtilities.LoadImage(Main.helper.Manifest.ModFolderPath + "clouds_top.png"); image = ImageUtilities.TintImage(image, config.TopCloudTint.ToColor32()); material.SetTexture("_MainTex", image); image = ImageUtilities.LoadImage(Main.helper.Manifest.ModFolderPath + "clouds_top_ramp.png"); image = ImageUtilities.TintImage(image, config.TopCloudTint.ToColor32()); material.SetTexture("_RampTex", image); image = ImageUtilities.LoadImage(Main.helper.Manifest.ModFolderPath + "clouds_cap.png"); image = ImageUtilities.TintImage(image, config.TopCloudTint.ToColor32()); material.SetTexture("_CapTex", image); } RotateTransform topRT = cloudsTopGO.AddComponent <RotateTransform>(); topRT.SetValue("_localAxis", Vector3.up); topRT.SetValue("degreesPerSecond", 10); topRT.SetValue("randomizeRotationRate", false); /* * SectorCullGroup scg = cloudsTop.AddComponent<SectorCullGroup>(); * scg.SetValue("_sector", MainClass.SECTOR); * scg.SetValue("_occlusionCulling", true); * scg.SetValue("_dynamicCullingBounds", false); * scg.SetValue("_particleSystemSuspendMode", CullGroup.ParticleSystemSuspendMode.Pause); * scg.SetValue("_waitForStreaming", false); */ 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 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 (Material material in bottomTSR.sharedMaterials) { material.SetColor("_Color", config.BottomCloudTint.ToColor32()); } TessSphereSectorToggle bottomTSST = cloudsBottomGO.AddComponent <TessSphereSectorToggle>(); bottomTSST.SetValue("_sector", sector); GameObject cloudsFluidGO = new GameObject(); cloudsFluidGO.SetActive(false); cloudsFluidGO.layer = 17; cloudsFluidGO.transform.parent = cloudsMainGO.transform; SphereCollider fluidSC = cloudsFluidGO.AddComponent <SphereCollider>(); fluidSC.isTrigger = true; fluidSC.radius = config.TopCloudSize / 2; OWShellCollider fluidOWSC = cloudsFluidGO.AddComponent <OWShellCollider>(); fluidOWSC.SetValue("_innerRadius", config.BottomCloudSize); 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); cloudsTopGO.SetActive(true); cloudsBottomGO.SetActive(true); cloudsFluidGO.SetActive(true); cloudsMainGO.SetActive(true); Logger.Log("Finished building clouds.", Logger.LogType.Log); }