This commit is contained in:
CortexCore
2023-09-01 14:33:54 +08:00
parent 4fadd3a530
commit 8ef5c7ec0a
451 changed files with 1048940 additions and 2028 deletions

View File

@@ -0,0 +1,21 @@
{
"name": "BITFALL.Player.Survival.Runtime",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:26fc13cbbc427414f9af2143d581330a",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using BITKit;
using BITKit.Entities;
using UnityEngine;
namespace BITFALL.Player.Survival
{
[CustomType(typeof(IPlayerSurvival))]
public class PlayerSurvival : EntityComponent, IPlayerSurvival
{
[SerializeReference, SubclassSelector] private IPlayerSurvivalState[] survivalStates;
private readonly IntervalUpdate interval = new(1);
private bool initialized;
private CancellationToken _cancellationToken;
public override void OnAwake()
{
_cancellationToken = entity.Get<CancellationToken>();
foreach (var x in survivalStates)
{
x.OnStateInitialize();
}
}
public override async void OnStart()
{
foreach (var x in survivalStates)
{
await x.OnStateInitializeAsync(_cancellationToken);
}
foreach (var x in survivalStates)
{
x.OnStateInitialized();
}
initialized = true;
}
public override void OnFixedUpdate(float deltaTime)
{
if (interval.AllowUpdate is false || initialized is false) return;
foreach (var x in survivalStates)
{
x.ProcessState();
if(x.TryGetNewEvent(out var newEvent))
OnSurvivalEventOpened?.Invoke(newEvent);
if(x.TryGetClosedEvent(out var closedEvent))
OnSurvivalEventClosed?.Invoke(closedEvent);
}
}
public event Action<IPlayerSurvivalState> OnSurvivalStateChanged;
public event Action<IPlayerSurvivalEvent> OnSurvivalEventOpened;
public event Action<IPlayerSurvivalEvent> OnSurvivalEventClosed;
}
}