1
This commit is contained in:
19
Unity/Scripts/SubSystems/Assets/AssetsProfile.cs
Normal file
19
Unity/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();
|
||||
}
|
||||
}
|
51
Unity/Scripts/SubSystems/Assets/AssetsRegister.cs
Normal file
51
Unity/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}个");
|
||||
}
|
||||
}
|
||||
}
|
187
Unity/Scripts/SubSystems/Input/BITInputSystem.cs
Normal file
187
Unity/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
73
Unity/Scripts/SubSystems/Quest/QuestSystem.cs
Normal file
73
Unity/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;
|
||||
}
|
||||
}
|
||||
}
|
52
Unity/Scripts/SubSystems/Save/SaveSystem.cs
Normal file
52
Unity/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();
|
||||
}
|
||||
}
|
||||
}
|
33
Unity/Scripts/SubSystems/Time/TimeSystem.cs
Normal file
33
Unity/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;
|
||||
}
|
||||
}
|
||||
}
|
61
Unity/Scripts/SubSystems/Timer/TimerSystem.cs
Normal file
61
Unity/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user