public static GravityVolume Make(GameObject body, float surfaceAccel, float upperSurface, float lowerSurface) { GameObject gravityGO = new GameObject(); gravityGO.transform.parent = body.transform; gravityGO.name = "GravityWell"; gravityGO.layer = 17; gravityGO.SetActive(false); 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", 1.5f * upperSurface); //Utility.AddDebugShape.AddSphere(gravityGO, 1.5f * upperSurface, new Color32(255, 0, 0, 128)); GV.SetValue("_upperSurfaceRadius", upperSurface); GV.SetValue("_lowerSurfaceRadius", lowerSurface); GV.SetValue("_layer", 3); GV.SetValue("_priority", 0); GV.SetValue("_alignmentPriority", 0); GV.SetValue("_surfaceAcceleration", surfaceAccel); GV.SetValue("_inheritable", false); GV.SetValue("_isPlanetGravityVolume", true); GV.SetValue("_cutoffRadius", 55f); SphereCollider SC = gravityGO.AddComponent<SphereCollider>(); SC.isTrigger = true; SC.radius = 4 * upperSurface; OWCollider OWC = gravityGO.AddComponent<OWCollider>(); OWC.SetLODActivationMask(DynamicOccupant.Player); gravityGO.SetActive(true); Logger.Log("Finished building gravity", Logger.LogType.Log); return GV; }
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); GravityVolume GV = GravityWell.AddComponent <GravityVolume>(); GV.SetValue("_cutoffAcceleration", 0.1f); GV.SetValue("_falloffType", GV.GetType().GetNestedType("FalloffType", BindingFlags.NonPublic).GetField("linear").GetValue(GV)); GV.SetValue("_alignmentRadius", 600f); GV.SetValue("_upperSurfaceRadius", upperSurface); GV.SetValue("_lowerSurfaceRadius", lowerSurface); GV.SetValue("_layer", 3); GV.SetValue("_priority", 0); GV.SetValue("_alignmentPriority", 0); GV.SetValue("_surfaceAcceleration", surfaceAccel); GV.SetValue("_inheritable", false); GV.SetValue("_isPlanetGravityVolume", true); GV.SetValue("_cutoffRadius", 55f); SphereCollider GV_SC = GravityWell.AddComponent <SphereCollider>(); GV_SC.isTrigger = true; GV_SC.radius = 4000; OWCollider GV_OWC = GravityWell.AddComponent <OWCollider>(); GV_OWC.SetLODActivationMask(DynamicOccupant.Player); GravityWell.SetActive(true); return(GV); }
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 void Make(GameObject body, AstroObject primaryBody, float angularSpeed, bool hasGravity, float surfaceAccel, float groundSize, bool hasOrbit) { if (hasOrbit) { 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; MainClass.OWRB = body.AddComponent <OWRigidbody>(); MainClass.OWRB.SetValue("_kinematicSimulation", true); MainClass.OWRB.SetValue("_autoGenerateCenterOfMass", true); MainClass.OWRB.SetIsTargetable(true); MainClass.OWRB.SetValue("_maintainOriginalCenterOfMass", true); InitialMotion IM = body.AddComponent <InitialMotion>(); IM.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody()); IM.SetValue("_orbitAngle", 0f); IM.SetValue("_isGlobalAxis", false); IM.SetValue("_initAngularSpeed", angularSpeed); IM.SetValue("_initLinearSpeed", 0f); IM.SetValue("_isGlobalAxis", false); MakeFieldDetector.Make(body); } if (hasGravity) { GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize); } AstroObject AO = body.AddComponent <AstroObject>(); AO.SetValue("_type", AstroObject.Type.Planet); AO.SetValue("_name", AstroObject.Name.InvisiblePlanet); AO.SetPrimaryBody(primaryBody); if (hasGravity) { GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize); AO.SetValue("_gravityVolume", GV); } }