From 6e97449c2bf1d21bfccfe6210a4f305b96b51b46 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 3 Feb 2023 18:58:34 -0800 Subject: [PATCH] file scoped namespace --- NewHorizons/Components/AddPhysics.cs | 71 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/NewHorizons/Components/AddPhysics.cs b/NewHorizons/Components/AddPhysics.cs index 38caaa9c..c4571326 100644 --- a/NewHorizons/Components/AddPhysics.cs +++ b/NewHorizons/Components/AddPhysics.cs @@ -1,51 +1,50 @@ using System.Collections; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components; + +/// +/// properly add physics to a detail +/// +public class AddPhysics : MonoBehaviour { - /// - /// properly add physics to a detail - /// - public class AddPhysics : MonoBehaviour + public Sector Sector; + public float Mass = 1f; + public float Radius = 1f; + + private IEnumerator Start() { - public Sector Sector; - public float Mass = 1f; - public float Radius = 1f; + yield return new WaitForSeconds(.1f); - private IEnumerator Start() - { - yield return new WaitForSeconds(.1f); + var parentBody = GetComponentInParent(); - var parentBody = GetComponentInParent(); + // hack: make all mesh colliders convex + // triggers are already convex + // prints errors for non readable meshes but whatever + foreach (var meshCollider in GetComponentsInChildren(true)) + meshCollider.convex = true; - // hack: make all mesh colliders convex - // triggers are already convex - // prints errors for non readable meshes but whatever - foreach (var meshCollider in GetComponentsInChildren(true)) - meshCollider.convex = true; + var bodyGo = new GameObject($"{name}_Body"); + bodyGo.SetActive(false); + bodyGo.transform.position = transform.position; + bodyGo.transform.rotation = transform.rotation; - var bodyGo = new GameObject($"{name}_Body"); - bodyGo.SetActive(false); - bodyGo.transform.position = transform.position; - bodyGo.transform.rotation = transform.rotation; + var owRigidbody = bodyGo.AddComponent(); + owRigidbody._simulateInSector = Sector; - var owRigidbody = bodyGo.AddComponent(); - owRigidbody._simulateInSector = Sector; + bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector"); + bodyGo.tag = "DynamicPropDetector"; + // this collider is not included in groups. oh well + bodyGo.AddComponent().radius = Radius; + bodyGo.AddComponent(); + bodyGo.AddComponent(); - bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector"); - bodyGo.tag = "DynamicPropDetector"; - // this collider is not included in groups. oh well - bodyGo.AddComponent().radius = Radius; - bodyGo.AddComponent(); - bodyGo.AddComponent(); + bodyGo.SetActive(true); - bodyGo.SetActive(true); + transform.parent = bodyGo.transform; + owRigidbody.SetMass(Mass); + owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position)); - transform.parent = bodyGo.transform; - owRigidbody.SetMass(Mass); - owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position)); - - Destroy(this); - } + Destroy(this); } } \ No newline at end of file