namespace Zinnia.Tracking.Collision.Event.Proxy
{
using System;
using UnityEngine;
using UnityEngine.Events;
using Zinnia.Event.Proxy;
using Zinnia.Extension;
///
/// Emits a UnityEvent with a payload whenever is called.
///
public class CollisionNotifierEventProxyEmitter : RestrictableSingleEventProxyEmitter
{
///
/// The types of that can be used for the rule source.
///
public enum RuleSourceType
{
///
/// Use the for the rule.
///
ForwardSource,
///
/// Use the containing for the rule.
///
CollidingSource
}
[Tooltip("The source GameObject to apply to the RestrictableSingleEventProxyEmitter.ReceiveValidity.")]
[SerializeField]
private RuleSourceType ruleSource;
///
/// The source to apply to the .
///
public RuleSourceType RuleSource
{
get
{
return ruleSource;
}
set
{
ruleSource = value;
}
}
///
/// Defines the event with the specified state.
///
[Serializable]
public class UnityEvent : UnityEvent { }
///
/// Sets the .
///
/// The index of the .
public virtual void SetRuleSource(int index)
{
RuleSource = EnumExtensions.GetByIndex(index);
}
///
protected override object GetTargetToCheck()
{
switch (RuleSource)
{
case RuleSourceType.ForwardSource:
return Payload.ForwardSource.gameObject;
case RuleSourceType.CollidingSource:
Transform containingTransform = Payload.ColliderData.GetContainingTransform();
return containingTransform != null ? containingTransform.gameObject : null;
}
return null;
}
}
}