目录结构调整
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b1ed97690b508a34eb0403c02ede8823
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public struct CommandArgsStruct
|
|
||||||
{
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
return obj is CommandArgsStruct other && Equals(other);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return (Value != null ? Value.GetHashCode() : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string Value { get; set; }
|
|
||||||
|
|
||||||
public CommandArgsStruct(string val = "")
|
|
||||||
{
|
|
||||||
Value = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Equals(CommandArgsStruct other)
|
|
||||||
{
|
|
||||||
return Value == other.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator ==(CommandArgsStruct a, CommandArgsStruct b) => a.Value == b.Value;
|
|
||||||
public static bool operator !=(CommandArgsStruct a, CommandArgsStruct b) => a.Value != b.Value;
|
|
||||||
|
|
||||||
public override string ToString() => Value;
|
|
||||||
|
|
||||||
public int ToInt()
|
|
||||||
{
|
|
||||||
return int.TryParse(Value, out var i) ? i : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float ToFloat()
|
|
||||||
{
|
|
||||||
return float.TryParse(Value, out var i) ? i : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T[] ToArr<T>(string split = ",") where T : IConvertible
|
|
||||||
{
|
|
||||||
var arr = Value.Split(split);
|
|
||||||
return arr.Select(a => (T)Convert.ChangeType(a, typeof(T))).ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CommandArgs
|
|
||||||
{
|
|
||||||
public string Command { get; private set; }
|
|
||||||
|
|
||||||
private readonly List<CommandArgsStruct> _args = new List<CommandArgsStruct>();
|
|
||||||
|
|
||||||
|
|
||||||
public CommandArgs(string str)
|
|
||||||
{
|
|
||||||
_args.Clear();
|
|
||||||
var args = str.Split(' ');
|
|
||||||
for (var i = 0; i < args.Length; i++)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
Command = args[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_args.Add(new CommandArgsStruct(args[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandArgsStruct this[int index] => Get(index);
|
|
||||||
|
|
||||||
public CommandArgsStruct Get(int index)
|
|
||||||
{
|
|
||||||
if (index < _args.Count && index >= 0)
|
|
||||||
{
|
|
||||||
return _args[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CommandArgsStruct();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b0a16abd7e144cbf8d1f9fbce9abbedc
|
|
||||||
timeCreated: 1687225439
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public struct CommandArgsRule
|
|
||||||
{
|
|
||||||
public string Sample;
|
|
||||||
|
|
||||||
public string Tips;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 9d1ccdbc0664467fa7f357204f86ba35
|
|
||||||
timeCreated: 1687161149
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public interface ICommand
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 名字
|
|
||||||
/// </summary>
|
|
||||||
string Name { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 命令
|
|
||||||
/// </summary>
|
|
||||||
string Command { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 参数说明
|
|
||||||
/// </summary>
|
|
||||||
string ArgsTips { get; }
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
bool Execute(CommandArgs args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: c3245582eb204c4abb7a0aa1eb05a276
|
|
||||||
timeCreated: 1687156371
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using NBC;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class Command
|
|
||||||
{
|
|
||||||
public enum LogType
|
|
||||||
{
|
|
||||||
Info,
|
|
||||||
Warn,
|
|
||||||
Error
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct LogData
|
|
||||||
{
|
|
||||||
public string Log;
|
|
||||||
public LogType Type;
|
|
||||||
|
|
||||||
public LogData(string log, LogType type)
|
|
||||||
{
|
|
||||||
Log = log;
|
|
||||||
Type = type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly Dictionary<string, ICommand> _commands = new Dictionary<string, ICommand>();
|
|
||||||
|
|
||||||
#region Log
|
|
||||||
|
|
||||||
public static readonly List<LogData> Logs = new List<LogData>();
|
|
||||||
private const int MaxLog = 1000;
|
|
||||||
|
|
||||||
public static Action OnLogChange;
|
|
||||||
|
|
||||||
public static void LogInfo(string log)
|
|
||||||
{
|
|
||||||
AddLog(log, LogType.Info);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogWarn(string log)
|
|
||||||
{
|
|
||||||
AddLog(log, LogType.Warn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void LogError(string log)
|
|
||||||
{
|
|
||||||
AddLog(log, LogType.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AddLog(string log, LogType type)
|
|
||||||
{
|
|
||||||
if (Logs.Count > MaxLog)
|
|
||||||
{
|
|
||||||
var sub = Logs.Count - MaxLog;
|
|
||||||
for (int i = 0; i < sub; i++)
|
|
||||||
{
|
|
||||||
Logs.RemoveAt(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logs.Add(new LogData(log, type));
|
|
||||||
OnLogChange?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 反射所有GM命令
|
|
||||||
/// </summary>
|
|
||||||
public static void Init()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var assembly = AppDomain.CurrentDomain.GetAssemblies()
|
|
||||||
.First(a => a.GetName().Name == "Assembly-CSharp");
|
|
||||||
var type = typeof(ICommand);
|
|
||||||
var types = assembly.GetTypes();
|
|
||||||
Log.Info("command 6");
|
|
||||||
var commandTypes =
|
|
||||||
types.Where(u => type.IsAssignableFrom(u) && u.IsClass && !u.IsAbstract && !u.IsGenericType);
|
|
||||||
foreach (var c in commandTypes)
|
|
||||||
{
|
|
||||||
if (Activator.CreateInstance(c) is ICommand command)
|
|
||||||
{
|
|
||||||
_commands[command.Command] = command;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Open()
|
|
||||||
{
|
|
||||||
// UI.Inst.OpenUI<CommandPanel>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Close()
|
|
||||||
{
|
|
||||||
// UI.Inst.DestroyUI<CommandPanel>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Has(string command)
|
|
||||||
{
|
|
||||||
return _commands.ContainsKey(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取所有指令实例
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static List<ICommand> GetAll()
|
|
||||||
{
|
|
||||||
return _commands.Values.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ICommand Get(string command)
|
|
||||||
{
|
|
||||||
return _commands.GetValueOrDefault(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 执行命令
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static bool Run(string command)
|
|
||||||
{
|
|
||||||
var args = new CommandArgs(command);
|
|
||||||
var inst = Get(args.Command);
|
|
||||||
return inst?.Execute(args) ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 匹配相识的命令
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public static List<ICommand> Match(string command)
|
|
||||||
{
|
|
||||||
var list = new List<ICommand>();
|
|
||||||
foreach (var key in _commands.Keys)
|
|
||||||
{
|
|
||||||
if (key.Contains(command))
|
|
||||||
{
|
|
||||||
list.Add(_commands[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 18773de7af9f49208a6ff95a79c012c1
|
|
||||||
timeCreated: 1732715884
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: d5d78b5261ae4df48915147b01803839
|
|
||||||
timeCreated: 1742568116
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using NBC;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 默认任务运行器
|
|
||||||
/// </summary>
|
|
||||||
public class DefRunner : Runner
|
|
||||||
{
|
|
||||||
private static DefRunner mUpdateRunner;
|
|
||||||
public static DefRunner Scheduler => mUpdateRunner ??= new DefRunner();
|
|
||||||
|
|
||||||
private readonly List<IProcess> _updateRoutines = new List<IProcess>();
|
|
||||||
|
|
||||||
private static bool _pause;
|
|
||||||
|
|
||||||
public event Action OnUpdate;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 暂停运行器
|
|
||||||
/// </summary>
|
|
||||||
public static bool Pause
|
|
||||||
{
|
|
||||||
get => _pause;
|
|
||||||
set => _pause = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefRunner()
|
|
||||||
{
|
|
||||||
App.OnUpdate += Update;
|
|
||||||
StartCoroutine(new RunnerProcess("DefRunner", Coroutines, ReadyTask, FlushingOperation));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartCoroutine(IProcess process)
|
|
||||||
{
|
|
||||||
var routines = _updateRoutines;
|
|
||||||
if (!routines.Contains(process))
|
|
||||||
{
|
|
||||||
routines.Add(process);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update()
|
|
||||||
{
|
|
||||||
if (Pause) return;
|
|
||||||
ExecuteRoutines(_updateRoutines);
|
|
||||||
OnUpdate?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ExecuteRoutines(List<IProcess> arr)
|
|
||||||
{
|
|
||||||
if (arr != null && arr.Count > 0)
|
|
||||||
{
|
|
||||||
for (var index = 0; index < arr.Count; index++)
|
|
||||||
{
|
|
||||||
var task = arr[index];
|
|
||||||
var st = task.Process();
|
|
||||||
if (st == NTaskStatus.Success)
|
|
||||||
{
|
|
||||||
arr.RemoveAt(index);
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: b32a3d1556f74b3390f54b8e355199c0
|
|
||||||
timeCreated: 1742568119
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
using System;
|
|
||||||
using NBC;
|
|
||||||
using NBC.Asset;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class LoadSceneTask : NTask
|
|
||||||
{
|
|
||||||
public LoadSceneTask(string sceneName, Action<SceneProvider> addAssetCallback = null)
|
|
||||||
{
|
|
||||||
_sceneName = sceneName;
|
|
||||||
_addAssetCallback = addAssetCallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Action<SceneProvider> _addAssetCallback;
|
|
||||||
private readonly string _sceneName;
|
|
||||||
// private SceneProvider _sceneAsset;
|
|
||||||
private AsyncOperation _asyncOperation;
|
|
||||||
|
|
||||||
protected override void OnStart()
|
|
||||||
{
|
|
||||||
Log.Info($"加载场景=={_sceneName}");
|
|
||||||
// var scenePath = $"scene/{_sceneName}";
|
|
||||||
_asyncOperation = SceneManager.LoadSceneAsync(_sceneName);
|
|
||||||
// _sceneAsset = NBC.Asset.Assets.LoadScene(scenePath);
|
|
||||||
// Assets.StompyRobot.SRDebugger.Scripts.Services.Implementation.ConsoleFilterStateService
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override NTaskStatus OnProcess()
|
|
||||||
{
|
|
||||||
// if (_sceneAsset != null)
|
|
||||||
// {
|
|
||||||
// if (_sceneAsset.IsDone)
|
|
||||||
// {
|
|
||||||
// if (_addAssetCallback != null)
|
|
||||||
// {
|
|
||||||
// _addAssetCallback(_sceneAsset); //加入缓存,以便离开战斗释放
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _addAssetCallback?.Invoke(_sceneAsset);
|
|
||||||
// return NTaskStatus.Success;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (_asyncOperation != null)
|
|
||||||
{
|
|
||||||
if (_asyncOperation.isDone)
|
|
||||||
{
|
|
||||||
// if (_addAssetCallback != null)
|
|
||||||
// {
|
|
||||||
// _addAssetCallback(_sceneAsset); //加入缓存,以便离开战斗释放
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// _addAssetCallback?.Invoke(_sceneAsset);
|
|
||||||
return NTaskStatus.Success;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NTaskStatus.Running;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: dc1ed1d2970444c2ba57d03aa15ab745
|
|
||||||
timeCreated: 1742568127
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using NBC;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class RunFunTask : NTask
|
|
||||||
{
|
|
||||||
private readonly Action _action;
|
|
||||||
|
|
||||||
public RunFunTask(Action action)
|
|
||||||
{
|
|
||||||
_action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnStart()
|
|
||||||
{
|
|
||||||
_action?.Invoke();
|
|
||||||
Finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 16e933b27204495bbb32d82177abb975
|
|
||||||
timeCreated: 1742568135
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
using NBC;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class TimeStopTask : NTask
|
|
||||||
{
|
|
||||||
//public float ProcessTime = 0;
|
|
||||||
public float EndTime = 0;
|
|
||||||
|
|
||||||
public float StartTime = 0;
|
|
||||||
|
|
||||||
private float _time;
|
|
||||||
|
|
||||||
public TimeStopTask(float time)
|
|
||||||
{
|
|
||||||
_time = time;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Reset()
|
|
||||||
{
|
|
||||||
// EndTime = 0;
|
|
||||||
// StartTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Stop()
|
|
||||||
{
|
|
||||||
// ProcessTime = EndTime;
|
|
||||||
|
|
||||||
EndTime = 0;
|
|
||||||
StartTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnStart()
|
|
||||||
{
|
|
||||||
StartTime = Time.time;
|
|
||||||
EndTime = StartTime + _time;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override NTaskStatus OnProcess()
|
|
||||||
{
|
|
||||||
return Time.time > EndTime ? NTaskStatus.Success : NTaskStatus.Running;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: aeb0973aa0bd4cdf9f025faed8a48959
|
|
||||||
timeCreated: 1742568141
|
|
||||||
3
Assets/Scripts/Fishing2/Entity.meta
Normal file
3
Assets/Scripts/Fishing2/Entity.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 664b8188498e48b7875266cd768c4b23
|
||||||
|
timeCreated: 1756305288
|
||||||
3
Assets/Scripts/Fishing2/Entity/Data.meta
Normal file
3
Assets/Scripts/Fishing2/Entity/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3aca1b3b8c2e4ef38cb2c4e0759f5620
|
||||||
|
timeCreated: 1756305296
|
||||||
3
Assets/Scripts/Fishing2/Entity/View.meta
Normal file
3
Assets/Scripts/Fishing2/Entity/View.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 944bb9e5d3fe4517bc6d12f723f98f87
|
||||||
|
timeCreated: 1756305300
|
||||||
3
Assets/Scripts/Fishing2/Event.meta
Normal file
3
Assets/Scripts/Fishing2/Event.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 958c7de8b9234f129e1ce439a961d540
|
||||||
|
timeCreated: 1756305421
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: fe99d0fb1bfc4912a205bb00911c1132
|
guid: 78d510036c864fc6a7840f354a743ce0
|
||||||
timeCreated: 1756047069
|
timeCreated: 1756305355
|
||||||
9
Assets/Scripts/Fishing2/Model/MapManageComponent.cs
Normal file
9
Assets/Scripts/Fishing2/Model/MapManageComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using NBC.Entitas;
|
||||||
|
|
||||||
|
namespace NBF.Fishing2
|
||||||
|
{
|
||||||
|
public class MapManageComponent : Entity
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/Fishing2/Model/MapManageComponent.cs.meta
Normal file
3
Assets/Scripts/Fishing2/Model/MapManageComponent.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 226c840e80f840ae8a4ff54bc7c6645a
|
||||||
|
timeCreated: 1756304063
|
||||||
3
Assets/Scripts/Fishing2/Model/Module.meta
Normal file
3
Assets/Scripts/Fishing2/Model/Module.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e4e83bf905244f99b0c583bf307cdbca
|
||||||
|
timeCreated: 1756310423
|
||||||
3
Assets/Scripts/Fishing2/Model/Module/Numeric.meta
Normal file
3
Assets/Scripts/Fishing2/Model/Module/Numeric.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ddc41e806352498aad45983600bdce6d
|
||||||
|
timeCreated: 1756310441
|
||||||
3
Assets/Scripts/Fishing2/Model/Module/ObjectWait.meta
Normal file
3
Assets/Scripts/Fishing2/Model/Module/ObjectWait.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3c2510352b1145bcaedaddbce324c10d
|
||||||
|
timeCreated: 1756310429
|
||||||
144
Assets/Scripts/Fishing2/Model/Module/ObjectWait/ObjectWait.cs
Normal file
144
Assets/Scripts/Fishing2/Model/Module/ObjectWait/ObjectWait.cs
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NBC;
|
||||||
|
using NBC.Entitas;
|
||||||
|
using NBC.Entitas.Interface;
|
||||||
|
|
||||||
|
namespace NBF.Fishing2
|
||||||
|
{
|
||||||
|
public static class WaitTypeError
|
||||||
|
{
|
||||||
|
public const int Success = 0;
|
||||||
|
public const int Destroy = 1;
|
||||||
|
public const int Cancel = 2;
|
||||||
|
public const int Timeout = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface IWaitType
|
||||||
|
{
|
||||||
|
int Error { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class ObjectWait : Entity
|
||||||
|
{
|
||||||
|
public Dictionary<Type, List<object>> tcsDict = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class ObjectWaitSystem
|
||||||
|
{
|
||||||
|
public class ObjectWaitAwakeSystem : AwakeSystem<ObjectWait>
|
||||||
|
{
|
||||||
|
protected override void Awake(ObjectWait self)
|
||||||
|
{
|
||||||
|
self.tcsDict.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ObjectWaitDestroySystem : DestroySystem<ObjectWait>
|
||||||
|
{
|
||||||
|
protected override void Destroy(ObjectWait self)
|
||||||
|
{
|
||||||
|
foreach (var p in self.tcsDict)
|
||||||
|
{
|
||||||
|
foreach (object v in p.Value)
|
||||||
|
{
|
||||||
|
((IDestroyRun)v).SetResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.tcsDict.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface IDestroyRun
|
||||||
|
{
|
||||||
|
void SetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResultCallback<K> : IDestroyRun where K : struct, IWaitType
|
||||||
|
{
|
||||||
|
private FTask<K> tcs;
|
||||||
|
|
||||||
|
public ResultCallback()
|
||||||
|
{
|
||||||
|
this.tcs = FTask<K>.Create(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsDisposed
|
||||||
|
{
|
||||||
|
get { return this.tcs == null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public FTask<K> Task => this.tcs;
|
||||||
|
|
||||||
|
public void SetResult(K k)
|
||||||
|
{
|
||||||
|
var t = tcs;
|
||||||
|
this.tcs = null;
|
||||||
|
t.SetResult(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetResult()
|
||||||
|
{
|
||||||
|
var t = tcs;
|
||||||
|
this.tcs = null;
|
||||||
|
t.SetResult(new K() { Error = WaitTypeError.Destroy });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async FTask<T> Wait<T>(this ObjectWait self) where T : struct, IWaitType
|
||||||
|
{
|
||||||
|
ResultCallback<T> tcs = new ResultCallback<T>();
|
||||||
|
FCancellationToken cancellationToken = FCancellationToken.ToKen;
|
||||||
|
self.Add(typeof(T), tcs);
|
||||||
|
|
||||||
|
T ret;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cancellationToken?.Add(CancelAction);
|
||||||
|
ret = await tcs.Task;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
cancellationToken?.Remove(CancelAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
void CancelAction()
|
||||||
|
{
|
||||||
|
self.Notify(new T() { Error = WaitTypeError.Cancel });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Notify<T>(this ObjectWait self, T obj) where T : struct, IWaitType
|
||||||
|
{
|
||||||
|
Type type = typeof(T);
|
||||||
|
if (!self.tcsDict.TryGetValue(type, out var tcsList) || tcsList.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var tcs in tcsList)
|
||||||
|
{
|
||||||
|
((ResultCallback<T>)tcs).SetResult(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
tcsList.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Add(this ObjectWait self, Type type, object obj)
|
||||||
|
{
|
||||||
|
if (self.tcsDict.TryGetValue(type, out var list))
|
||||||
|
{
|
||||||
|
list.Add(obj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.tcsDict.Add(type, new List<object> { obj });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a79150f39b424a1c82eef6b04bc0a7c1
|
||||||
|
timeCreated: 1756310098
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user