// Copyright (c) Pixel Crushers. All rights reserved.
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
///
/// Deprecated by DialogueSystemTrigger.
/// This is the abstract base class for all dialogue event handler components (e.g.,
/// SetActiveOnDialogueEvent, StartConversationOnDialogueEvent, etc). Dialogue events occur
/// when a bark, conversation, or sequence starts and ends. Subclasses implement
/// TryStartActions() and TryEndActions().
///
[AddComponentMenu("")] // Deprecated
public abstract class ActOnDialogueEvent : MonoBehaviour
{
///
/// The base class for actions that will run at the start or end of dialogue events.
///
[System.Serializable]
public class Action
{
public Condition condition = new Condition();
}
///
/// The dialogue event that triggers the actions.
///
[Tooltip("Trigger when this dialogue event occurs.")]
public DialogueEvent trigger;
///
/// Set true if this should only happen once.
///
[Tooltip("Destroy this component after triggering. If you need to remember across scene changes and saved games, use a Condition instead.")]
public bool once = false;
[HideInInspector]
public DialogueDatabase selectedDatabase = null;
///
/// Handles OnBarkStart events.
///
///
/// Actor that barked.
///
public void OnBarkStart(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnBark)) TryStartActions(actor);
}
///
/// Handles OnBarkEnd events.
///
///
/// Actor that barked.
///
public void OnBarkEnd(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnBark))
{
TryEndActions(actor);
DestroyIfOnce();
}
}
///
/// Handles OnConversationStart events.
///
///
/// Actor that initiated the conversation.
///
public void OnConversationStart(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnConversation)) TryStartActions(actor);
}
///
/// Handles OnConversationEnd events.
///
///
/// Actor that initiated the conversation.
///
public void OnConversationEnd(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnConversation))
{
TryEndActions(actor);
DestroyIfOnce();
}
}
///
/// Handles OnSequenceStart events.
///
///
/// The primary actor in the sequence.
///
public void OnSequenceStart(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnSequence)) TryStartActions(actor);
}
///
/// Handles OnSequenceEnd events.
///
///
/// The primary actor in the sequence.
///
public void OnSequenceEnd(Transform actor)
{
if (enabled && (trigger == DialogueEvent.OnSequence))
{
TryEndActions(actor);
DestroyIfOnce();
}
}
///
/// Tries the actions that should run when the event starts (e.g., OnBarkStart).
///
///
/// Actor.
///
public abstract void TryStartActions(Transform actor);
///
/// Tries the actions that should run when the event ends (e.g., OnBarkEnd).
///
///
/// Actor.
///
public abstract void TryEndActions(Transform actor);
private void DestroyIfOnce()
{
if (once) Destroy(this);
}
}
}