This commit is contained in:
CortexCore
2024-03-31 23:31:00 +08:00
parent e179d2eb53
commit b7b89ee71a
641 changed files with 31286 additions and 22134 deletions

View File

@@ -1,88 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.Events;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Collections.Concurrent;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public class BehaviourHelper : MonoBehaviour, IMainTicker
{
public static Action OnStop;
public static bool Actived;
static BehaviourHelper Singleton;
ConcurrentQueue<Action> queue = new();
List<Action<float>> Updates = new();
List<Action<float>> FixedUpdates = new();
public void Add(Action action)
{
queue.Enqueue(action);
}
public void AddAsUpdate(Action<float> action)
{
Updates.Add(action);
}
public void AddAsFixedUpdate(Action<float> action)
{
FixedUpdates.Add(action);
}
public void RemoveAsUpdate(Action<float> action)
{
Updates.Remove(action);
}
public void RemoveAsFixedUpdate(Action<float> action)
{
FixedUpdates.Remove(action);
}
void Update()
{
lock (queue)
{
while (queue.TryDequeue(out var action))
{
try
{
action.Invoke();
}
catch (System.Exception e)
{
Debug.LogError(e);
}
}
}
foreach (var update in Updates.ToArray())
{
update.Invoke(Time.deltaTime);
}
}
void FixedUpdate()
{
foreach (var fixedUpdate in FixedUpdates.ToArray())
{
fixedUpdate.Invoke(Time.fixedDeltaTime);
}
}
void OnDestroy()
{
OnStop?.Invoke();
}
[RuntimeInitializeOnLoadMethod]
static void Initialize()
{
GameObject go = new();
GameObject.DontDestroyOnLoad(go);
var behaviourHelper = go.AddComponent<BehaviourHelper>();
Singleton = behaviourHelper;
DI.Register<IMainTicker>(behaviourHelper);
Debug.Log($"{nameof(IMainTicker)}已创建");
go.name = nameof(BehaviourHelper);
go.hideFlags = HideFlags.NotEditable;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: d40f7cbccced56a44913d38b56e9810c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: