更改文件架构
This commit is contained in:
8
Packages/Common~/Scripts/SubSystems/Assets.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Assets.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6495019c42543b049b5843de77d33765
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
19
Packages/Common~/Scripts/SubSystems/Assets/AssetsProfile.cs
Normal file
19
Packages/Common~/Scripts/SubSystems/Assets/AssetsProfile.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Sirenix.OdinInspector;
|
||||
namespace BITKit
|
||||
{
|
||||
public class BITKitSO : ScriptableObject, IAssetsRegister
|
||||
{
|
||||
public virtual void RegisterAssets() { }
|
||||
}
|
||||
}
|
||||
namespace BITKit.SubSystems.Assets
|
||||
{
|
||||
public class AssetsProfile : ScriptableObject
|
||||
{
|
||||
[DisplayAsString] public string createTime;
|
||||
public List<BITKitSO> assets = new();
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce2dbb6c3b14e164c94eec5be450d73e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
51
Packages/Common~/Scripts/SubSystems/Assets/AssetsRegister.cs
Normal file
51
Packages/Common~/Scripts/SubSystems/Assets/AssetsRegister.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
namespace BITKit
|
||||
{
|
||||
public interface IAssetsRegister
|
||||
{
|
||||
void RegisterAssets();
|
||||
}
|
||||
}
|
||||
namespace BITKit.SubSystems.Assets
|
||||
{
|
||||
[SubSystemConfig(isMainThread = true)]
|
||||
public class AssetsRegister : SubBITSystem
|
||||
{
|
||||
AssetsProfile assetsProfile;
|
||||
/* #if UNITY_EDITOR
|
||||
public override void OnCreate()
|
||||
{
|
||||
var scriptableObjects = AssetDatabase
|
||||
.FindAssets($"t:{nameof(BITKitSO)}")
|
||||
.Select(x => AssetDatabase.GUIDToAssetPath(x))
|
||||
.Select(x => AssetDatabase.LoadAssetAtPath<BITKitSO>(x));
|
||||
|
||||
|
||||
assetsProfile = ScriptableObjectHelper.Get<AssetsProfile>();
|
||||
assetsProfile.createTime = System.DateTime.Now.ToString();
|
||||
assetsProfile.assets.Clear();
|
||||
scriptableObjects.ForEach(x =>
|
||||
{
|
||||
assetsProfile.assets.Add(x);
|
||||
});
|
||||
EditorUtility.SetDirty(assetsProfile);
|
||||
}
|
||||
#endif */
|
||||
public override void OnStart()
|
||||
{
|
||||
assetsProfile = ScriptableObjectHelper.Get<AssetsProfile>();
|
||||
assetsProfile.assets.ForEach(x =>
|
||||
{
|
||||
x.RegisterAssets();
|
||||
});
|
||||
BIT4Log.Log<AssetsRegister>($"已注册{nameof(AssetsProfile)}:{assetsProfile.assets.Count}个");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1199141e5baf6fc4cb2e365446cef053
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Core.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Core.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b09b4d8c4b5bbc4885b3da7fa334cff
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Input.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Input.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fcbcf3c9c4e793e47a8c6111fcbeeae2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
187
Packages/Common~/Scripts/SubSystems/Input/BITInputSystem.cs
Normal file
187
Packages/Common~/Scripts/SubSystems/Input/BITInputSystem.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
/* using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using BITKit.BITInputSystem;
|
||||
using BITKit;
|
||||
namespace BITKit.SubSystems.Input
|
||||
{
|
||||
[SubSystemConfig(isMainThread = true)]
|
||||
public class BITInputSystem : SubBITSystem, BITController.IGameplayActions, BITController.IUIActions
|
||||
{
|
||||
[ExcuteOnStart]
|
||||
static void Reload()
|
||||
{
|
||||
BITSystems.GetOrCreate<BITInputSystem>();
|
||||
}
|
||||
public const string _inputSystem_enabled = "InputSystem_Enabled";
|
||||
ValidHandle enabled = new();
|
||||
BITController controller;
|
||||
public override void OnCreate()
|
||||
{
|
||||
controller = new();
|
||||
|
||||
enabled.AddListener(SetActive);
|
||||
|
||||
Data.AddListener<bool>(_inputSystem_enabled, x =>
|
||||
{
|
||||
enabled.SetElements(this, x);
|
||||
}, true);
|
||||
}
|
||||
public virtual void OnMovement(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnMovement), context);
|
||||
}
|
||||
public virtual void OnView(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnView), context);
|
||||
}
|
||||
public virtual void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnJump), context);
|
||||
}
|
||||
public virtual void OnCrouch(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnCrouch), context);
|
||||
}
|
||||
public virtual void OnHoldCrouch(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnHoldCrouch), context);
|
||||
}
|
||||
public virtual void OnFire(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnFire), context);
|
||||
}
|
||||
public virtual void OnAim(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnAim), context);
|
||||
}
|
||||
public virtual void OnInteractive(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnInteractive), context);
|
||||
}
|
||||
public virtual void OnAbility(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnAbility), context);
|
||||
}
|
||||
public virtual void OnMelee(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnMelee), context);
|
||||
}
|
||||
public virtual void OnRun(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnRun), context);
|
||||
}
|
||||
public virtual void OnRunHold(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnRunHold), context);
|
||||
}
|
||||
public virtual void OnReload(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnReload), context);
|
||||
}
|
||||
public virtual void OnPrimary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnPrimary), context);
|
||||
}
|
||||
public virtual void OnSecondary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnSecondary), context);
|
||||
}
|
||||
public virtual void OnTertiary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnTertiary), context);
|
||||
}
|
||||
public virtual void OnQuaternary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnQuaternary), context);
|
||||
}
|
||||
public virtual void OnQuinary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnQuinary), context);
|
||||
}
|
||||
public virtual void OnSenary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnSenary), context);
|
||||
}
|
||||
public virtual void OnSeptenary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnSeptenary), context);
|
||||
}
|
||||
public virtual void OnOctonary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnOctonary), context);
|
||||
}
|
||||
public virtual void OnNonary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnNonary), context);
|
||||
}
|
||||
public virtual void OnDenary(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnDenary), context);
|
||||
}
|
||||
|
||||
public virtual void OnPoint(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnPoint), context);
|
||||
}
|
||||
public virtual void OnLeftClick(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnLeftClick), context);
|
||||
}
|
||||
public virtual void OnMiddleClick(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnMiddleClick), context);
|
||||
}
|
||||
public virtual void OnRightClick(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnRightClick), context);
|
||||
}
|
||||
public virtual void OnScrollWheel(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnScrollWheel), context);
|
||||
}
|
||||
public virtual void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnMove), context);
|
||||
}
|
||||
public virtual void OnSubmit(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnSubmit), context);
|
||||
}
|
||||
public virtual void OnCancel(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnCancel), context);
|
||||
}
|
||||
public virtual void OnTrackedPosition(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnTrackedPosition), context);
|
||||
}
|
||||
public virtual void OnTrackedOrientation(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnTrackedOrientation), context);
|
||||
}
|
||||
public virtual void OnInventory(InputAction.CallbackContext context)
|
||||
{
|
||||
Data.Set<InputAction.CallbackContext>(nameof(OnInventory), context);
|
||||
}
|
||||
void SetActive(bool active)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
controller.Gameplay.Enable();
|
||||
controller.UI.Enable();
|
||||
controller.Gameplay.SetCallbacks(this);
|
||||
controller.UI.SetCallbacks(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
controller.Gameplay.Disable();
|
||||
controller.UI.Disable();
|
||||
Data.Clear<InputAction.CallbackContext>();
|
||||
}
|
||||
BIT4Log.Log<BITInputSystem>(active);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d57e5a7fac4bb15499b1805805ef7327
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Quest.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Quest.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 920ef8e0b6ce4c44e97c2eab25ce6f0f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
73
Packages/Common~/Scripts/SubSystems/Quest/QuestSystem.cs
Normal file
73
Packages/Common~/Scripts/SubSystems/Quest/QuestSystem.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit.SubSystems.Quest
|
||||
{
|
||||
public class QuestSystem : SubBITSystem
|
||||
{
|
||||
public enum State
|
||||
{
|
||||
None,
|
||||
InProcess,
|
||||
Complete,
|
||||
Canceled,
|
||||
}
|
||||
public class Info
|
||||
{
|
||||
public static implicit operator Guid(Info self)
|
||||
{
|
||||
return self.id;
|
||||
}
|
||||
public static implicit operator string(Info self)
|
||||
{
|
||||
return self.name;
|
||||
}
|
||||
internal Info(string name, string description)
|
||||
{
|
||||
id = Guid.NewGuid();
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
public readonly Guid id;
|
||||
public State state { get; internal set; }
|
||||
public string name { get; internal set; }
|
||||
public string description { get; internal set; }
|
||||
//public List<Func<bool>> condition = new();
|
||||
}
|
||||
public static Dictionary<Guid, Info> quests { get; private set; } = new();
|
||||
public static event Action<Info> OnQuestCreated;
|
||||
public static event Action<Info> OnQuestCompleted;
|
||||
public static event Action<Info> OnQuestCanceled;
|
||||
public static Info Create(string name = "New Quest", string description = "Quest in progress")
|
||||
{
|
||||
Info info = new(name, description);
|
||||
info.state = State.InProcess;
|
||||
quests.Add(info, info);
|
||||
OnQuestCreated?.Invoke(info);
|
||||
return info;
|
||||
}
|
||||
public static void Complete(Info quest)
|
||||
{
|
||||
quest.state = State.Complete;
|
||||
OnQuestCompleted?.Invoke(quest);
|
||||
}
|
||||
public static void Cancel(Info quest)
|
||||
{
|
||||
if (quests.ContainsKey(quest.id))
|
||||
{
|
||||
quests.Remove(quest.id);
|
||||
quest.state = State.Canceled;
|
||||
OnQuestCanceled?.Invoke(quest);
|
||||
}
|
||||
}
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void Reload()
|
||||
{
|
||||
quests.Clear();
|
||||
OnQuestCreated = null;
|
||||
OnQuestCompleted = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b634dd120417a3409ba123b900bec56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Save.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Save.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f65ec757b7256694e816d590f3e91134
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Packages/Common~/Scripts/SubSystems/Save/SaveSystem.cs
Normal file
52
Packages/Common~/Scripts/SubSystems/Save/SaveSystem.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BITKit.SubSystems.Save
|
||||
{
|
||||
public class SaveSystem : SubBITSystem
|
||||
{
|
||||
[BITCommand]
|
||||
public static void Save()
|
||||
{
|
||||
lock (saveInfos)
|
||||
{
|
||||
saveInfos.ForEach(x =>
|
||||
{
|
||||
x.Invoke(default, default);
|
||||
});
|
||||
}
|
||||
}
|
||||
[BITCommand]
|
||||
public static void Load()
|
||||
{
|
||||
lock (loadInfos)
|
||||
{
|
||||
loadInfos.ForEach(x =>
|
||||
{
|
||||
x.Invoke(default, default);
|
||||
});
|
||||
}
|
||||
}
|
||||
static IEnumerable<MethodInfo> saveInfos;
|
||||
static IEnumerable<MethodInfo> loadInfos;
|
||||
public override void OnCreate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnDestory()
|
||||
{
|
||||
//Save();
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/SubSystems/Save/SaveSystem.cs.meta
Normal file
11
Packages/Common~/Scripts/SubSystems/Save/SaveSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c184421b3aec3b4db062385b51d954a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Time.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Time.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0fa23f41731af64a896e7b66effb442
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Packages/Common~/Scripts/SubSystems/Time/TimeSystem.cs
Normal file
33
Packages/Common~/Scripts/SubSystems/Time/TimeSystem.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit
|
||||
{
|
||||
public static partial class Utility
|
||||
{
|
||||
public static class Time
|
||||
{
|
||||
public static float time;
|
||||
public static double timeAsDouble;
|
||||
public static float deltaTime = 1f / 30;
|
||||
public static float fixedDeltaTime = 1f / 60;
|
||||
public static float unscaledDeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
namespace BITKit.SubSystems
|
||||
{
|
||||
[SubSystemConfig(isMainThread = true)]
|
||||
public class TimeSystem : SubBITSystem
|
||||
{
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
Utility.Time.time = Time.time;
|
||||
Utility.Time.timeAsDouble = Time.timeAsDouble;
|
||||
Utility.Time.deltaTime = Time.deltaTime;
|
||||
Utility.Time.unscaledDeltaTime = Time.unscaledDeltaTime;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/SubSystems/Time/TimeSystem.cs.meta
Normal file
11
Packages/Common~/Scripts/SubSystems/Time/TimeSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d2e15ca6473ce1459573e583f2921d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Packages/Common~/Scripts/SubSystems/Timer.meta
Normal file
8
Packages/Common~/Scripts/SubSystems/Timer.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f2233dc53cfde3458cc0d76f9534745
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
61
Packages/Common~/Scripts/SubSystems/Timer/TimerSystem.cs
Normal file
61
Packages/Common~/Scripts/SubSystems/Timer/TimerSystem.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.TestTools;
|
||||
namespace BITKit
|
||||
{
|
||||
using SubSystems;
|
||||
public class BITTimer
|
||||
{
|
||||
internal BITTimer() { }
|
||||
public static BITTimer Create(float addTime = 1, UnityAction action = null)
|
||||
{
|
||||
BITTimer timer = new();
|
||||
timer.excuteTime = Utility.Time.time + addTime;
|
||||
timer.onExcute = action;
|
||||
TimerSystem.queue.Enqueue(timer);
|
||||
return timer;
|
||||
}
|
||||
public float excuteTime;
|
||||
public bool isActive { get; internal set; }
|
||||
public UnityAction onExcute;
|
||||
public void Cancel()
|
||||
{
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace BITKit.SubSystems
|
||||
{
|
||||
public class TimerSystem : SubBITSystem
|
||||
{
|
||||
internal static List<BITTimer> timers = new();
|
||||
internal static ConcurrentQueue<BITTimer> queue = new();
|
||||
public override void OnUpdate(float deltaTime)
|
||||
{
|
||||
List<BITTimer> nexts = new();
|
||||
lock (timers)
|
||||
{
|
||||
timers.ForEach(x =>
|
||||
{
|
||||
if (x.excuteTime > Utility.Time.time)
|
||||
{
|
||||
if (x.onExcute is not null) x.onExcute();
|
||||
x.isActive = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nexts.Add(x);
|
||||
}
|
||||
});
|
||||
while (queue.TryDequeue(out var timer))
|
||||
{
|
||||
nexts.Add(timer);
|
||||
}
|
||||
timers = nexts;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f5d87ad298669f4dbf822bb7031b7f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user