| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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<BaseShotTargetComponent> shotTargetComponents = new List<BaseShotTargetComponent>();
- 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;
- }
- }
- }
- }
- }
- }
- }
|