107 lines
2.8 KiB
C#
107 lines
2.8 KiB
C#
using System;
|
|
using PixelCrushers.DialogueSystem;
|
|
using PixelCrushers.DialogueSystem.Wrappers;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Beyond;
|
|
using PixelCrushers;
|
|
using UnityEngine;
|
|
|
|
[RequireComponent(typeof(AudioSource))]
|
|
public class QuestTriggerBase : Saver
|
|
{
|
|
AudioSource m_audioSource;
|
|
Transform m_player;
|
|
public bool m_fireOnce = true;
|
|
public bool m_wasFired = false;
|
|
[Serializable]
|
|
public class SaveData
|
|
{
|
|
public bool wasFired;
|
|
}
|
|
// Start is called before the first frame update
|
|
public override void Awake()
|
|
{
|
|
base.Awake();
|
|
m_audioSource = GetComponent<AudioSource>();
|
|
m_audioSource.playOnAwake = false;
|
|
gameObject.layer = LayerMask.NameToLayer("Triggers");
|
|
var collider = GetComponent<Collider>();
|
|
if (collider != null)
|
|
{
|
|
collider.isTrigger = true;
|
|
}
|
|
if (Player.Instance == null)
|
|
{
|
|
Debug.LogError("No player found!");
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
m_player = Player.Instance.transform;
|
|
|
|
}
|
|
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
Player.Instance.ThirdPersonController.onDead.AddListener(OnDead);
|
|
}
|
|
|
|
public override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
if (Player.Instance != null && Player.Instance.ThirdPersonController != null)
|
|
Player.Instance.ThirdPersonController.onDead.RemoveListener(OnDead);
|
|
}
|
|
|
|
private void OnDead(GameObject arg0)
|
|
{
|
|
if (m_audioSource.isPlaying)
|
|
{
|
|
m_audioSource.Stop();
|
|
}
|
|
}
|
|
|
|
public override string RecordData()
|
|
{
|
|
SaveData data = new SaveData();
|
|
data.wasFired = m_wasFired;
|
|
return SaveSystem.Serialize(data);
|
|
}
|
|
|
|
public override void ApplyData(string s)
|
|
{
|
|
var data = SaveSystem.Deserialize<SaveData>(s);
|
|
if (data == null)
|
|
data = new SaveData();
|
|
m_wasFired = data.wasFired;
|
|
}
|
|
|
|
private IEnumerator ResponseCoroutine(ActionResponse action)
|
|
{
|
|
if (action.delay > 0f)
|
|
yield return new WaitForSeconds(action.delay);
|
|
if (action.audioClip != null)
|
|
{
|
|
m_audioSource.clip = action.audioClip;
|
|
m_audioSource.Play();
|
|
}
|
|
if (action.barkConversation != null && action.barkConversation != "")
|
|
{
|
|
//DialogueManager.BarkString(action.barkText, m_player);
|
|
BarkManager.Instance.PlayBark(action.barkConversation);
|
|
}
|
|
if (action.responseEvent != null)
|
|
{
|
|
action.responseEvent?.Invoke();
|
|
}
|
|
|
|
|
|
yield return null;
|
|
}
|
|
public virtual void OnActionResponse(ActionResponse action)
|
|
{
|
|
StartCoroutine(ResponseCoroutine(action));
|
|
}
|
|
}
|