BITFALL/Assets/Artists/Scripts/Player/Survival/PlayerSurvival.cs

33 lines
834 B
C#
Raw Normal View History

2023-09-01 14:33:54 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.Player.Survival
{
2023-10-02 23:24:56 +08:00
[CustomType(typeof(IPlayerSurvivalService))]
public class PlayerSurvivalService : EntityComponent, IPlayerSurvivalService
2023-09-01 14:33:54 +08:00
{
2023-10-02 23:24:56 +08:00
public IPlayerSurvivalElement[] Elements { get; set; } = Array.Empty<IPlayerSurvivalElement>();
[SerializeReference, SubclassSelector] private IPlayerSurvivalElement[] initialElements = Array.Empty<IPlayerSurvivalElement>();
private IntervalUpdate _interval = new(1);
2023-09-01 14:33:54 +08:00
public override void OnAwake()
{
2023-10-02 23:24:56 +08:00
Elements = initialElements;
2023-09-01 14:33:54 +08:00
}
2023-10-02 23:24:56 +08:00
public override void OnUpdate(float deltaTime)
2023-09-01 14:33:54 +08:00
{
2023-10-02 23:24:56 +08:00
if (_interval.AllowUpdate is false) return;
foreach (var x in Elements)
2023-09-01 14:33:54 +08:00
{
2023-10-02 23:24:56 +08:00
x.Value -= 1;
2023-09-01 14:33:54 +08:00
}
}
}
}