Use custom destruction volume

This commit is contained in:
Noah Pilarski 2022-08-18 05:06:06 -04:00
parent 667beec858
commit 3f4785600e
2 changed files with 73 additions and 1 deletions

View File

@ -104,7 +104,7 @@ namespace NewHorizons.Builder.Body
planetSphereCollider.isTrigger = true;
planetDestructionVolume.AddComponent<OWCollider>();
planetDestructionVolume.AddComponent<OWTriggerVolume>();
planetDestructionVolume.AddComponent<DestructionVolume>()._deathType = DeathType.Energy;
planetDestructionVolume.AddComponent<StarDestructionVolume>()._deathType = DeathType.Energy;
var sunLight = new GameObject("StarLight");
sunLight.transform.parent = starGO.transform;

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components
{
public class StarDestructionVolume : DestructionVolume
{
public override void Vanish(OWRigidbody bodyToVanish, RelativeLocationData entryLocation)
{
// Don't vanish other stars
if (bodyToVanish.GetComponent<StarController>() != null) return;
base.Vanish(bodyToVanish, entryLocation);
}
public new void OnTriggerEnter(Collider hitCollider)
{
if (hitCollider.attachedRigidbody == null) return;
if (hitCollider.attachedRigidbody.CompareTag("Player"))
{
_playerBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_playerLocation = new RelativeLocationData(_playerBody, transform);
}
else if (hitCollider.attachedRigidbody.CompareTag("Ship"))
{
_shipBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_shipLocation = new RelativeLocationData(_shipBody, transform);
}
else if (hitCollider.attachedRigidbody.CompareTag("ShipCockpit"))
{
_shipCockpitBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_shipCockpitLocation = new RelativeLocationData(_shipCockpitBody, transform);
}
else if (hitCollider.attachedRigidbody.CompareTag("Probe"))
{
_probeBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_probeLocation = new RelativeLocationData(_probeBody, transform);
}
else if (hitCollider.attachedRigidbody.CompareTag("ModelRocketShipBody"))
{
_modelShipBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_modelShipLocation = new RelativeLocationData(_modelShipBody, transform);
}
else if (hitCollider.attachedRigidbody.CompareTag("NomaiShuttleBody"))
{
_nomaiShuttleBody = hitCollider.attachedRigidbody.GetRequiredComponent<OWRigidbody>();
_nomaiShuttleLocation = new RelativeLocationData(_nomaiShuttleBody, transform);
}
else
{
if (_onlyAffectsPlayerAndShip) return;
OWRigidbody owrb = hitCollider.attachedRigidbody.GetComponent<OWRigidbody>();
if (owrb != null)
{
// Don't shrink/vanish other stars
if (owrb.GetComponent<StarController>() != null) return;
if (_shrinkBodies)
Shrink(owrb);
else
Vanish(owrb, new RelativeLocationData(owrb, transform));
}
}
if (_vanishEffectPool != null) _vanishEffectPool.Instantiate(transform, hitCollider.transform.position, Quaternion.FromToRotation(transform.forward, hitCollider.transform.position - transform.position) * transform.rotation);
}
}
}