Merge pull request #6 from kafeijao/triggers-with-particles

Added CVR Pointer particle system support
This commit is contained in:
SDraw 2023-10-30 19:13:47 +00:00 committed by GitHub
commit c37d3a6842
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 11 deletions

View file

@ -1,49 +1,90 @@
using ABI.CCK.Components; using ABI.CCK.Components;
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using UnityEngine; using UnityEngine;
namespace ml_prm namespace ml_prm
{ {
[DisallowMultipleComponent] [DisallowMultipleComponent]
class RagdollTrigger : MonoBehaviour public class RagdollTrigger : MonoBehaviour
{ {
const string c_ragdollPointerType = "ragdoll";
Collider m_collider = null; Collider m_collider = null;
Collider m_lastTrigger = null; Collider m_lastColliderTrigger = null;
ParticleSystem m_lastParticleSystemTrigger = null;
bool m_triggered = false; bool m_triggered = false;
void Start() void Start()
{ {
m_collider = this.GetComponent<Collider>(); m_collider = this.GetComponent<Collider>();
CVRParticlePointerManager.volumes.Add(new RagdollTriggerVolume() {
collider = m_collider,
trigger = this,
});
CVRParticlePointerManager.UpdateParticleSystems();
}
void OnDestroy() {
CVRParticlePointerManager.RemoveTrigger(m_collider);
} }
void Update() void Update()
{ {
if(!ReferenceEquals(m_lastTrigger, null)) if(!ReferenceEquals(m_lastColliderTrigger, null))
{ {
if(m_lastTrigger != null) if(m_lastColliderTrigger != null)
{ {
if(!m_collider.bounds.Intersects(m_lastTrigger.bounds)) if(!m_collider.bounds.Intersects(m_lastColliderTrigger.bounds))
m_lastTrigger = null; m_lastColliderTrigger = null;
} }
else else
m_lastTrigger = null; m_lastColliderTrigger = null;
}
if(!ReferenceEquals(m_lastParticleSystemTrigger, null))
{
if(m_lastParticleSystemTrigger != null)
{
if (m_lastParticleSystemTrigger.particleCount == 0)
m_lastParticleSystemTrigger = null;
}
else
m_lastParticleSystemTrigger = null;
} }
} }
void OnTriggerEnter(Collider p_other) void OnTriggerEnter(Collider p_other)
{ {
CVRPointer l_pointer = p_other.GetComponent<CVRPointer>(); CVRPointer l_pointer = p_other.GetComponent<CVRPointer>();
if((l_pointer != null) && (l_pointer.type == "ragdoll") && !IsIgnored(l_pointer.transform) && (m_lastTrigger != p_other)) if((l_pointer != null) && (l_pointer.type == c_ragdollPointerType) && !IsIgnored(l_pointer.transform) && (m_lastColliderTrigger != p_other))
{ {
m_lastTrigger = p_other; m_lastColliderTrigger = p_other;
m_triggered = true; m_triggered = true;
} }
} }
void OnTriggerExit(Collider p_other) void OnTriggerExit(Collider p_other)
{ {
if(m_lastTrigger == p_other) if(m_lastColliderTrigger == p_other)
m_lastTrigger = null; m_lastColliderTrigger = null;
}
public void OnPointerParticleEnter(CVRPointer p_pointer)
{
if (!gameObject.activeInHierarchy) return;
if ((p_pointer.type == c_ragdollPointerType) && !IsIgnored(p_pointer.transform) && (m_lastParticleSystemTrigger != p_pointer.particleSystem))
{
m_lastParticleSystemTrigger = p_pointer.particleSystem;
m_triggered = true;
}
}
public void OnPointerParticleExit(CVRPointer p_pointer)
{
// This seems to be very unreliable, and it's causing weird behavior
// if (!gameObject.activeInHierarchy) return;
// if(m_lastParticleSystemTrigger == p_pointer.particleSystem)
// m_lastParticleSystemTrigger = null;
} }
public bool GetStateWithReset() public bool GetStateWithReset()

View file

@ -0,0 +1,14 @@
using ABI_RC.Core.Savior;
using ABI.CCK.Components;
using UnityEngine;
namespace ml_prm {
public class RagdollTriggerVolume : CVRTriggerVolume
{
public Collider collider { get; set; }
public RagdollTrigger trigger { get; set; }
public void TriggerEnter(CVRPointer pointer) => trigger.OnPointerParticleEnter(pointer);
public void TriggerExit(CVRPointer pointer) => trigger.OnPointerParticleExit(pointer);
}
}

View file

@ -65,6 +65,10 @@
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath> <HintPath>D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
<Private>false</Private> <Private>false</Private>
</Reference> </Reference>
<Reference Include="UnityEngine.ParticleSystemModule">
<HintPath>D:\games\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.ParticleSystemModule.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">