file scoped namespace

This commit is contained in:
JohnCorby 2023-02-03 18:58:34 -08:00
parent 9546b52a5e
commit 6e97449c2b

View File

@ -1,51 +1,50 @@
using System.Collections; using System.Collections;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Components namespace NewHorizons.Components;
/// <summary>
/// properly add physics to a detail
/// </summary>
public class AddPhysics : MonoBehaviour
{ {
/// <summary> public Sector Sector;
/// properly add physics to a detail public float Mass = 1f;
/// </summary> public float Radius = 1f;
public class AddPhysics : MonoBehaviour
private IEnumerator Start()
{ {
public Sector Sector; yield return new WaitForSeconds(.1f);
public float Mass = 1f;
public float Radius = 1f;
private IEnumerator Start() var parentBody = GetComponentInParent<OWRigidbody>();
{
yield return new WaitForSeconds(.1f);
var parentBody = GetComponentInParent<OWRigidbody>(); // hack: make all mesh colliders convex
// triggers are already convex
// prints errors for non readable meshes but whatever
foreach (var meshCollider in GetComponentsInChildren<MeshCollider>(true))
meshCollider.convex = true;
// hack: make all mesh colliders convex var bodyGo = new GameObject($"{name}_Body");
// triggers are already convex bodyGo.SetActive(false);
// prints errors for non readable meshes but whatever bodyGo.transform.position = transform.position;
foreach (var meshCollider in GetComponentsInChildren<MeshCollider>(true)) bodyGo.transform.rotation = transform.rotation;
meshCollider.convex = true;
var bodyGo = new GameObject($"{name}_Body"); var owRigidbody = bodyGo.AddComponent<OWRigidbody>();
bodyGo.SetActive(false); owRigidbody._simulateInSector = Sector;
bodyGo.transform.position = transform.position;
bodyGo.transform.rotation = transform.rotation;
var owRigidbody = bodyGo.AddComponent<OWRigidbody>(); bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector");
owRigidbody._simulateInSector = Sector; bodyGo.tag = "DynamicPropDetector";
// this collider is not included in groups. oh well
bodyGo.AddComponent<SphereCollider>().radius = Radius;
bodyGo.AddComponent<DynamicForceDetector>();
bodyGo.AddComponent<DynamicFluidDetector>();
bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector"); bodyGo.SetActive(true);
bodyGo.tag = "DynamicPropDetector";
// this collider is not included in groups. oh well
bodyGo.AddComponent<SphereCollider>().radius = Radius;
bodyGo.AddComponent<DynamicForceDetector>();
bodyGo.AddComponent<DynamicFluidDetector>();
bodyGo.SetActive(true); transform.parent = bodyGo.transform;
owRigidbody.SetMass(Mass);
owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position));
transform.parent = bodyGo.transform; Destroy(this);
owRigidbody.SetMass(Mass);
owRigidbody.SetVelocity(parentBody.GetPointVelocity(transform.position));
Destroy(this);
}
} }
} }