using System.Collections; using System.Collections.Generic; using UnityEngine; namespace ShotSimulator.Target { public enum ShotTargetInteractiveType { OnEnter, OnHovering, OnUpdate, OnFixedUpdate, OnClick, OnExit, OnNotEntering } public abstract class BaseShotTarget : MonoBehaviour { protected List shotTargetComponents = new List(); public bool IsRunning { get; set; } public virtual void OnEnter() { ExecuteInteractive(ShotTargetInteractiveType.OnEnter); } public virtual void OnHovering() { ExecuteInteractive(ShotTargetInteractiveType.OnHovering); } public virtual void FixedUpdate() { ExecuteInteractive(ShotTargetInteractiveType.OnFixedUpdate); } public virtual void OnClick() { ExecuteInteractive(ShotTargetInteractiveType.OnClick); } public virtual void OnExit() { ExecuteInteractive(ShotTargetInteractiveType.OnExit); } private void ExecuteInteractive(ShotTargetInteractiveType type) { if (IsRunning) { foreach (var component in shotTargetComponents) { if (component.enable) { switch (type) { case ShotTargetInteractiveType.OnEnter: component.OnEnter(); break; case ShotTargetInteractiveType.OnHovering: component.OnHovering(); break; case ShotTargetInteractiveType.OnClick: component.OnClick(); break; case ShotTargetInteractiveType.OnFixedUpdate: component.OnFixedUpdate(); break; case ShotTargetInteractiveType.OnUpdate: component.OnUpdate(); break; case ShotTargetInteractiveType.OnExit: component.OnExit(); break; } } } } } } }