1
0
forked from cgvr/DeltaVR

refactor NPCController script, make it abstract, extendable; separate AlienNPC and CafeWaiterNPC

This commit is contained in:
2026-01-28 14:23:16 +02:00
parent eb8e33bb3d
commit a8e65514f4
15 changed files with 823 additions and 41 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8993dd48830472642b4b2c8a4c6e291c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
using UnityEngine;
public class AlienNPC : NPCController
{
protected override void OnPlayerApproach()
{
Debug.Log("Alien NPC: player approached");
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
}
protected override void OnPlayerLeave()
{
Debug.Log("Alien NPC: player left");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea1b6453c1ef8e24d921a6dbaa549eba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CafeWaiterNPC : NPCController
{
protected override void OnPlayerApproach()
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
}
protected override void OnPlayerLeave()
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a215290e2c2e1d43983b61cb160e241
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,14 +1,12 @@
using DG.Tweening;
using System.Collections;
using Unity.XR.CoreUtils;
using UnityEngine;
public class NPCController : MonoBehaviour
public abstract class NPCController : MonoBehaviour
{
private Vector3 mouthClosedScale;
private Vector3 mouthOpenScale;
private bool isTalking;
private Transform playerTransform;
protected Transform playerTransform;
public Transform mouthTransform;
public float mouthScalingMultiplier = 2.5f;
@@ -43,33 +41,26 @@ public class NPCController : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
KbmController controller = other.GetComponent<KbmController>();
XROrigin playerOrigin = other.GetComponent<XROrigin>();
if (controller != null)
if (other.gameObject.tag == "Player Head")
{
playerTransform = controller.transform;
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
} else if (playerOrigin != null)
{
playerTransform = playerOrigin.transform;
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
playerTransform = other.transform;
OnPlayerApproach();
}
}
protected virtual void OnPlayerApproach() {}
private void OnTriggerExit(Collider other)
{
KbmController controller = other.GetComponent<KbmController>();
XROrigin playerOrigin = other.GetComponent<XROrigin>();
if (controller != null)
{
playerTransform = null;
}
else if (playerOrigin != null)
if (other.gameObject.tag == "Player Head")
{
playerTransform = null;
OnPlayerLeave();
}
}
protected virtual void OnPlayerLeave() {}
public void SpeakVoiceLine(int voiceLineId)
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[voiceLineId], gameObject);