forked from cgvr/DeltaVR
refactor NPCController script, make it abstract, extendable; separate AlienNPC and CafeWaiterNPC
This commit is contained in:
8
Assets/_PROJECT/Scripts/ModeGeneration/NPCs.meta
Normal file
8
Assets/_PROJECT/Scripts/ModeGeneration/NPCs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8993dd48830472642b4b2c8a4c6e291c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/AlienNPC.cs
Normal file
15
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/AlienNPC.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
11
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/AlienNPC.cs.meta
Normal file
11
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/AlienNPC.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea1b6453c1ef8e24d921a6dbaa549eba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/CafeWaiterNPC.cs
Normal file
16
Assets/_PROJECT/Scripts/ModeGeneration/NPCs/CafeWaiterNPC.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a215290e2c2e1d43983b61cb160e241
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user