54 lines
1.1 KiB
C#
54 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace XED.ComponentSystem
|
|
{
|
|
public abstract class ActionComponent
|
|
{
|
|
public enum EventType
|
|
{
|
|
Start,
|
|
Complete,
|
|
}
|
|
|
|
public bool isStarted;
|
|
|
|
public Action<ActionComponent> onStart;
|
|
public Action<ActionComponent> onComplete;
|
|
|
|
public Dictionary<EventType, List<ActionComponent>> subscribers = new();
|
|
public abstract void Start();
|
|
public abstract void Run();
|
|
|
|
public void Subscribe(EventType et, ActionComponent ac)
|
|
{
|
|
if (!subscribers.ContainsKey(et))
|
|
{
|
|
subscribers.Add(et, new List<ActionComponent>());
|
|
}
|
|
|
|
subscribers[et].Add(ac);
|
|
}
|
|
|
|
}
|
|
|
|
public class Timer : ActionComponent
|
|
{
|
|
public float timer;
|
|
public float duration;
|
|
|
|
public override void Run()
|
|
{
|
|
timer += Time.deltaTime;
|
|
}
|
|
|
|
public override void Start()
|
|
{
|
|
timer = 0f;
|
|
onStart?.Invoke(this);
|
|
}
|
|
|
|
}
|
|
}
|