mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
move to separate component
This commit is contained in:
parent
a6e190ffd8
commit
cb2b8815fd
@ -1,10 +1,10 @@
|
||||
using NewHorizons.Builder.General;
|
||||
using NewHorizons.Components;
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.Handlers;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
@ -415,48 +415,5 @@ namespace NewHorizons.Builder.Props
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
// detector collider is not included in groups. oh well
|
||||
private class AddPhysics : MonoBehaviour
|
||||
{
|
||||
public Sector Sector;
|
||||
public float Mass;
|
||||
public float Radius;
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
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;
|
||||
|
||||
var bodyGo = new GameObject($"{name}_Body");
|
||||
bodyGo.SetActive(false);
|
||||
bodyGo.transform.position = transform.position;
|
||||
bodyGo.transform.rotation = transform.rotation;
|
||||
|
||||
var owRigidbody = bodyGo.AddComponent<OWRigidbody>();
|
||||
owRigidbody._simulateInSector = Sector;
|
||||
|
||||
bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector");
|
||||
bodyGo.tag = "DynamicPropDetector";
|
||||
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));
|
||||
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
NewHorizons/Components/AddPhysics.cs
Normal file
51
NewHorizons/Components/AddPhysics.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NewHorizons.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// properly add physics to a detail
|
||||
/// </summary>
|
||||
public class AddPhysics : MonoBehaviour
|
||||
{
|
||||
public Sector Sector;
|
||||
public float Mass;
|
||||
public float Radius;
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
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;
|
||||
|
||||
var bodyGo = new GameObject($"{name}_Body");
|
||||
bodyGo.SetActive(false);
|
||||
bodyGo.transform.position = transform.position;
|
||||
bodyGo.transform.rotation = transform.rotation;
|
||||
|
||||
var owRigidbody = bodyGo.AddComponent<OWRigidbody>();
|
||||
owRigidbody._simulateInSector = Sector;
|
||||
|
||||
bodyGo.layer = LayerMask.NameToLayer("PhysicalDetector");
|
||||
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));
|
||||
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user