// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved.
// This code can only be used under the standard Unity Asset Store End User License Agreement
// A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms
using Doozy.Runtime.Common.Utils;
using UnityEngine;
// ReSharper disable MemberCanBeProtected.Global
namespace Doozy.Runtime.Signals.Components
{
///
/// Specialized component used to send a signal, or a meta signal (if a payload value is provided)
///
[AddComponentMenu("Doozy/Signals/Signal Sender")]
public partial class SignalSender : MonoBehaviour
{
#if UNITY_EDITOR
[UnityEditor.MenuItem("GameObject/Doozy/Signals/Signal Sender", false, 8)]
private static void CreateComponent(UnityEditor.MenuCommand menuCommand)
{
GameObjectUtils.AddToScene("Signal Sender", false, true);
}
#endif
/// Payload to send with the signal
public SignalPayload Payload = new SignalPayload();
/// Automatically send a signal on Start
public bool SendOnStart;
/// Automatically send a signal on OnEnable
public bool SendOnEnable;
/// Automatically send a signal on OnDisable
public bool SendOnDisable;
/// Automatically send a signal on OnDestroy
public bool SendOnDestroy;
protected virtual void Start()
{
if (SendOnStart) SendSignal();
}
protected virtual void OnEnable()
{
if (SendOnEnable) SendSignal();
}
protected virtual void OnDisable()
{
if (SendOnDisable) SendSignal();
}
protected virtual void OnDestroy()
{
if (SendOnDestroy) SendSignal();
}
/// Send a Signal with the set payload value to the stream with the given stream id
public virtual void SendSignal()
{
Payload?.SendSignal();
}
}
}