UI工具翻新
1. 增加UI工具 2. 增加设置页面 3. GameLoop更新 4. 导入ActionKit工具
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8f93e286b584fe5896c9e5b438ee7cd
|
||||
timeCreated: 1744888695
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e6e41d0e8ab41bd8422fe4383840a37
|
||||
timeCreated: 1744888862
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class Callback : IAction
|
||||
{
|
||||
private Callback()
|
||||
{
|
||||
}
|
||||
|
||||
private Action _callback;
|
||||
|
||||
private static readonly SimpleObjectPool<Callback> SimpleObjectPool = new(() => new Callback(), null, 10);
|
||||
|
||||
public static Callback Allocate(Action callback)
|
||||
{
|
||||
var callbackAction = SimpleObjectPool.Allocate();
|
||||
callbackAction.ActionID = ActionKit.IDGenerator++;
|
||||
callbackAction.Reset();
|
||||
callbackAction.IsFinalized = false;
|
||||
callbackAction._callback = callback;
|
||||
return callbackAction;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
_callback?.Invoke();
|
||||
this.Finish();
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_callback = null;
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Callback>(SimpleObjectPool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Paused = false;
|
||||
Status = ActionStatus.NotStart;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CallbackExtension
|
||||
{
|
||||
public static ISequence Callback(this ISequence self, Action callback)
|
||||
{
|
||||
return self.Append(Kit.Callback.Allocate(callback));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8c25272de21437a9f6b2b73c2a636c7
|
||||
timeCreated: 1745052326
|
||||
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public class Condition : IAction
|
||||
{
|
||||
private Func<bool> _condition;
|
||||
|
||||
private static readonly SimpleObjectPool<Condition> SimpleObjectPool = new(() => new Condition(), null, 10);
|
||||
|
||||
private Condition(){}
|
||||
|
||||
public static Condition Allocate(Func<bool> condition)
|
||||
{
|
||||
var conditionAction = SimpleObjectPool.Allocate();
|
||||
conditionAction.ActionID = ActionKit.IDGenerator++;
|
||||
conditionAction.IsFinalized = false;
|
||||
conditionAction.Reset();
|
||||
conditionAction._condition = condition;
|
||||
return conditionAction;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
public void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (_condition.Invoke())
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_condition = null;
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Condition>(SimpleObjectPool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Paused = false;
|
||||
Status = ActionStatus.NotStart;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConditionExtension
|
||||
{
|
||||
public static ISequence Condition(this ISequence self, Func<bool> condition)
|
||||
{
|
||||
return self.Append(Kit.Condition.Allocate(condition));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d76197e1c1c34e7480a7081b04c03909
|
||||
timeCreated: 1745052436
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class CoroutineAction : IAction
|
||||
{
|
||||
private static readonly SimpleObjectPool<CoroutineAction> Pool = new(() => new CoroutineAction(), null, 10);
|
||||
|
||||
private Func<IEnumerator> _coroutineGetter;
|
||||
|
||||
private CoroutineAction(){}
|
||||
|
||||
public static CoroutineAction Allocate(Func<IEnumerator> coroutineGetter)
|
||||
{
|
||||
var coroutineAction = Pool.Allocate();
|
||||
coroutineAction.ActionID = ActionKit.IDGenerator++;
|
||||
coroutineAction.IsFinalized = false;
|
||||
coroutineAction.Reset();
|
||||
coroutineAction._coroutineGetter = coroutineGetter;
|
||||
return coroutineAction;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_coroutineGetter = null;
|
||||
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<CoroutineAction>(Pool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Paused = false;
|
||||
Status = ActionStatus.NotStart;
|
||||
}
|
||||
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
public void OnStart()
|
||||
{
|
||||
ActionKitMonoBehaviourEvents.Instance.ExecuteCoroutine(_coroutineGetter(), () =>
|
||||
{
|
||||
Status = ActionStatus.Finished;
|
||||
});
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class CoroutineExtension
|
||||
{
|
||||
public static ISequence Coroutine(this ISequence self, Func<IEnumerator> coroutineGetter)
|
||||
{
|
||||
return self.Append(CoroutineAction.Allocate(coroutineGetter));
|
||||
}
|
||||
|
||||
public static IAction ToAction(this IEnumerator self)
|
||||
{
|
||||
return CoroutineAction.Allocate(() => self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4608e63a25d342b4b502d1a4cdc61fec
|
||||
timeCreated: 1745052510
|
||||
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class Delay : IAction
|
||||
{
|
||||
public float delayTime;
|
||||
|
||||
public Func<float> delayTimeFactory;
|
||||
|
||||
public Action OnDelayFinish { get; set; }
|
||||
|
||||
public float CurrentSeconds { get; set; }
|
||||
|
||||
private Delay()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly SimpleObjectPool<Delay> Pool = new(() => new Delay(), null, 10);
|
||||
|
||||
public static Delay Allocate(float delayTime, Action onDelayFinish = null)
|
||||
{
|
||||
var retNode = Pool.Allocate();
|
||||
retNode.ActionID = ActionKit.IDGenerator++;
|
||||
retNode.IsFinalized = false;
|
||||
retNode.Reset();
|
||||
retNode.delayTime = delayTime;
|
||||
retNode.OnDelayFinish = onDelayFinish;
|
||||
retNode.CurrentSeconds = 0.0f;
|
||||
return retNode;
|
||||
}
|
||||
|
||||
public static Delay Allocate(Func<float> delayTimeFactory, Action onDelayFinish = null)
|
||||
{
|
||||
var retNode = Pool.Allocate();
|
||||
retNode.IsFinalized = false;
|
||||
retNode.Reset();
|
||||
retNode.delayTimeFactory = delayTimeFactory;
|
||||
retNode.OnDelayFinish = onDelayFinish;
|
||||
retNode.CurrentSeconds = 0.0f;
|
||||
return retNode;
|
||||
}
|
||||
|
||||
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
if (delayTimeFactory != null)
|
||||
{
|
||||
delayTime = delayTimeFactory();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (CurrentSeconds >= delayTime)
|
||||
{
|
||||
this.Finish();
|
||||
OnDelayFinish?.Invoke();
|
||||
}
|
||||
|
||||
CurrentSeconds += dt;
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
CurrentSeconds = 0.0f;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
OnDelayFinish = null;
|
||||
IsFinalized = true;
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Delay>(Pool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFinalized { get; set; }
|
||||
}
|
||||
|
||||
public static class DelayExtension
|
||||
{
|
||||
public static ISequence Delay(this ISequence self, float seconds,Action onDelayFinish = null)
|
||||
{
|
||||
return self.Append(Kit.Delay.Allocate(seconds,onDelayFinish));
|
||||
}
|
||||
|
||||
public static ISequence Delay(this ISequence self,Func<float> delayTimeFactory,Action onDelayFinish = null)
|
||||
{
|
||||
return self.Append(Kit.Delay.Allocate(delayTimeFactory,onDelayFinish));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c70afd801db24bd08b8083ba1e2a03a2
|
||||
timeCreated: 1744891140
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class DelayFrame : IAction
|
||||
{
|
||||
public bool Paused { get; set; }
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
private static SimpleObjectPool<DelayFrame> _simpleObjectPool = new(() => new DelayFrame(), null, 10);
|
||||
|
||||
private Action _onDelayFinish;
|
||||
|
||||
public static DelayFrame Allocate(int frameCount, Action onDelayFinish = null)
|
||||
{
|
||||
var delayFrame = _simpleObjectPool.Allocate();
|
||||
delayFrame.ActionID = ActionKit.IDGenerator++;
|
||||
delayFrame.Reset();
|
||||
delayFrame.IsFinalized = false;
|
||||
delayFrame._delayedFrameCount = frameCount;
|
||||
delayFrame._onDelayFinish = onDelayFinish;
|
||||
|
||||
return delayFrame;
|
||||
}
|
||||
|
||||
private int _startFrameCount;
|
||||
private int _delayedFrameCount;
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
_startFrameCount = Time.frameCount;
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (Time.frameCount >= _startFrameCount + _delayedFrameCount)
|
||||
{
|
||||
_onDelayFinish?.Invoke();
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_onDelayFinish = null;
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<DelayFrame>(_simpleObjectPool, this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
_startFrameCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DelayFrameExtension
|
||||
{
|
||||
public static ISequence DelayFrame(this ISequence self, int frameCount)
|
||||
{
|
||||
return self.Append(Kit.DelayFrame.Allocate(frameCount));
|
||||
}
|
||||
|
||||
public static ISequence NextFrame(this ISequence self)
|
||||
{
|
||||
return self.Append(Kit.DelayFrame.Allocate(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b23ca3b053c944c09084046dd1ecd022
|
||||
timeCreated: 1745052136
|
||||
@@ -0,0 +1,106 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2016 - 2024 liangxiegame UNDER MIT License
|
||||
*
|
||||
* https://qframework.cn
|
||||
* https://github.com/liangxiegame/QFramework
|
||||
* https://gitee.com/liangxiegame/QFramework
|
||||
****************************************************************************/
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public class Lerp : IAction
|
||||
{
|
||||
private static readonly SimpleObjectPool<Lerp> Pool = new(() => new Lerp(), null, 10);
|
||||
|
||||
private float _target;
|
||||
private float _source;
|
||||
private float _duration;
|
||||
private Action<float> _onLerp;
|
||||
private Action _onLerpFinish;
|
||||
|
||||
private float _currentTime;
|
||||
|
||||
public static Lerp Allocate(float source, float target, float duration, Action<float> onLerp = null,
|
||||
Action onLerpFinish = null)
|
||||
{
|
||||
var retNode = Pool.Allocate();
|
||||
retNode.ActionID = ActionKit.IDGenerator++;
|
||||
retNode.IsFinalized = false;
|
||||
retNode.Reset();
|
||||
retNode._target = target;
|
||||
retNode._source = source;
|
||||
retNode._duration = duration;
|
||||
retNode._onLerp = onLerp;
|
||||
retNode._onLerpFinish = onLerpFinish;
|
||||
return retNode;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
_currentTime = 0.0f;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_onLerp = null;
|
||||
_onLerpFinish = null;
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Lerp>(Pool, this));
|
||||
}
|
||||
}
|
||||
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
_currentTime = 0.0f;
|
||||
_onLerp?.Invoke(Mathf.Lerp(_source, _target, 0));
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
_currentTime += dt;
|
||||
if (_currentTime < _duration)
|
||||
{
|
||||
_onLerp?.Invoke(Mathf.Lerp(_source, _target, _currentTime / _duration));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
_onLerp?.Invoke(Mathf.Lerp(_source, _target, 1.0f));
|
||||
_onLerpFinish?.Invoke();
|
||||
}
|
||||
|
||||
public bool IsFinalized { get; set; }
|
||||
}
|
||||
|
||||
public static class LerpExtension
|
||||
{
|
||||
public static ISequence Lerp(this ISequence self, float a, float b, float duration, Action<float> onLerp = null,
|
||||
Action onLerpFinish = null)
|
||||
{
|
||||
return self.Append(Kit.Lerp.Allocate(a, b, duration, onLerp, onLerpFinish));
|
||||
}
|
||||
|
||||
public static ISequence Lerp01(this ISequence self, float duration, Action<float> onLerp = null,
|
||||
Action onLerpFinish = null)
|
||||
{
|
||||
return self.Append(Kit.Lerp.Allocate(0, 1, duration, onLerp, onLerpFinish));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7002810d8a141d996834cec3569ab15
|
||||
timeCreated: 1745053095
|
||||
@@ -0,0 +1,117 @@
|
||||
/****************************************************************************
|
||||
* Copyright (c) 2015 - 2024 liangxiegame UNDER MIT License
|
||||
*
|
||||
* https://qframework.cn
|
||||
* https://github.com/liangxiegame/QFramework
|
||||
* https://gitee.com/liangxiegame/QFramework
|
||||
****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public interface IParallel : ISequence
|
||||
{
|
||||
|
||||
}
|
||||
internal class Parallel : IParallel
|
||||
{
|
||||
private Parallel(){}
|
||||
|
||||
private static readonly SimpleObjectPool<Parallel> SimpleObjectPool = new(() => new Parallel(), null, 5);
|
||||
|
||||
private readonly List<IAction> _actions = ListPool<IAction>.Get();
|
||||
|
||||
private int _finishedCount;
|
||||
|
||||
public static Parallel Allocate()
|
||||
{
|
||||
var parallel = SimpleObjectPool.Allocate();
|
||||
parallel.ActionID = ActionKit.IDGenerator++;
|
||||
parallel.IsFinalized = false;
|
||||
parallel.Reset();
|
||||
return parallel;
|
||||
}
|
||||
public bool Paused { get; set; }
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
public void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
for (var i = _finishedCount; i < _actions.Count; i++)
|
||||
{
|
||||
if (!_actions[i].Execute(dt)) continue;
|
||||
|
||||
_finishedCount++;
|
||||
|
||||
if (_finishedCount >= _actions.Count)
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
// swap
|
||||
(_actions[i], _actions[_finishedCount - 1]) = (_actions[_finishedCount - 1], _actions[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public ISequence Append(IAction action)
|
||||
{
|
||||
_actions.Add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.Deinit();
|
||||
}
|
||||
|
||||
|
||||
_actions.Clear();
|
||||
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Parallel>(SimpleObjectPool,this));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Status = ActionStatus.NotStart;
|
||||
_finishedCount = 0;
|
||||
Paused = false;
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.Reset();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class ParallelExtension
|
||||
{
|
||||
public static ISequence Parallel(this ISequence self, Action<ISequence> parallelSetting)
|
||||
{
|
||||
var parallel = Kit.Parallel.Allocate();
|
||||
parallelSetting(parallel);
|
||||
return self.Append(parallel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0c3a11ccace8454092e15087aa98c03a
|
||||
timeCreated: 1745053353
|
||||
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public interface IRepeat : ISequence
|
||||
{
|
||||
}
|
||||
|
||||
public class Repeat : IRepeat
|
||||
{
|
||||
private Sequence _sequence;
|
||||
|
||||
private int _repeatCount = -1;
|
||||
private int _currentRepeatCount;
|
||||
|
||||
private static readonly SimpleObjectPool<Repeat> SimpleObjectPool = new(() => new Repeat(), null, 5);
|
||||
|
||||
private Repeat()
|
||||
{
|
||||
}
|
||||
|
||||
public static Repeat Allocate(int repeatCount = -1)
|
||||
{
|
||||
var repeat = SimpleObjectPool.Allocate();
|
||||
repeat.ActionID = ActionKit.IDGenerator++;
|
||||
repeat._sequence = Sequence.Allocate();
|
||||
repeat.IsFinalized = false;
|
||||
repeat.Reset();
|
||||
repeat._repeatCount = repeatCount;
|
||||
return repeat;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
_currentRepeatCount = 0;
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (_repeatCount == -1 || _repeatCount == 0)
|
||||
{
|
||||
if (_sequence.Execute(dt))
|
||||
{
|
||||
_sequence.Reset();
|
||||
}
|
||||
}
|
||||
else if (_currentRepeatCount < _repeatCount)
|
||||
{
|
||||
if (_sequence.Execute(dt))
|
||||
{
|
||||
_currentRepeatCount++;
|
||||
|
||||
if (_currentRepeatCount >= _repeatCount)
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
_sequence.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public ISequence Append(IAction action)
|
||||
{
|
||||
_sequence.Append(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
|
||||
_sequence.Deinit();
|
||||
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Repeat>(SimpleObjectPool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_currentRepeatCount = 0;
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
_sequence.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public static class RepeatExtension
|
||||
{
|
||||
public static ISequence Repeat(this ISequence self,Action<IRepeat> repeatSetting)
|
||||
{
|
||||
var repeat = Kit.Repeat.Allocate();
|
||||
repeatSetting(repeat);
|
||||
return self.Append(repeat);
|
||||
}
|
||||
|
||||
public static ISequence Repeat(this ISequence self,int repeatCount, Action<IRepeat> repeatSetting)
|
||||
{
|
||||
var repeat = Kit.Repeat.Allocate(repeatCount);
|
||||
repeatSetting(repeat);
|
||||
return self.Append(repeat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 982c23ba869f4f1197aa5c34f94585af
|
||||
timeCreated: 1745053479
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public interface ISequence : IAction
|
||||
{
|
||||
ISequence Append(IAction action);
|
||||
}
|
||||
|
||||
internal class Sequence : ISequence
|
||||
{
|
||||
private IAction _currentAction;
|
||||
private int _currentActionIndex;
|
||||
private readonly List<IAction> _actions = ListPool<IAction>.Get();
|
||||
|
||||
private Sequence()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly SimpleObjectPool<Sequence> SimpleObjectPool = new(() => new Sequence(), null, 10);
|
||||
|
||||
public static Sequence Allocate()
|
||||
{
|
||||
var sequence = SimpleObjectPool.Allocate();
|
||||
sequence.ActionID = ActionKit.IDGenerator++;
|
||||
sequence.Reset();
|
||||
sequence.IsFinalized = false;
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
|
||||
public bool IsFinalized { get; set; }
|
||||
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
if (_actions.Count > 0)
|
||||
{
|
||||
_currentActionIndex = 0;
|
||||
_currentAction = _actions[_currentActionIndex];
|
||||
_currentAction.Reset();
|
||||
TryExecuteUntilNextNotFinished();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
void TryExecuteUntilNextNotFinished()
|
||||
{
|
||||
while (_currentAction != null && _currentAction.Execute(0))
|
||||
{
|
||||
_currentActionIndex++;
|
||||
|
||||
if (_currentActionIndex < _actions.Count)
|
||||
{
|
||||
_currentAction = _actions[_currentActionIndex];
|
||||
_currentAction.Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentAction = null;
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
if (_currentAction != null)
|
||||
{
|
||||
if (_currentAction.Execute(dt))
|
||||
{
|
||||
_currentActionIndex++;
|
||||
|
||||
if (_currentActionIndex < _actions.Count)
|
||||
{
|
||||
_currentAction = _actions[_currentActionIndex];
|
||||
_currentAction.Reset();
|
||||
|
||||
TryExecuteUntilNextNotFinished();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Finish();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
|
||||
public ISequence Append(IAction action)
|
||||
{
|
||||
_actions.Add(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.Deinit();
|
||||
}
|
||||
|
||||
_actions.Clear();
|
||||
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<Sequence>(SimpleObjectPool,this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_currentActionIndex = 0;
|
||||
Status = ActionStatus.NotStart;
|
||||
Paused = false;
|
||||
foreach (var action in _actions)
|
||||
{
|
||||
action.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SequenceExtension
|
||||
{
|
||||
public static ISequence Sequence(this ISequence self, Action<ISequence> sequenceSetting)
|
||||
{
|
||||
var repeat = Kit.Sequence.Allocate();
|
||||
sequenceSetting(repeat);
|
||||
return self.Append(repeat);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07d5775265fe4976b0c4c299775774e4
|
||||
timeCreated: 1744890986
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public class TaskAction : IAction
|
||||
{
|
||||
private static readonly SimpleObjectPool<TaskAction> Pool = new(() => new TaskAction(), null, 10);
|
||||
|
||||
private Func<Task> _taskGetter;
|
||||
private Task _executingTask;
|
||||
|
||||
private TaskAction()
|
||||
{
|
||||
}
|
||||
|
||||
public static TaskAction Allocate(Func<Task> taskGetter)
|
||||
{
|
||||
var coroutineAction = Pool.Allocate();
|
||||
coroutineAction.ActionID = ActionKit.IDGenerator++;
|
||||
coroutineAction.IsFinalized = false;
|
||||
coroutineAction.Reset();
|
||||
coroutineAction._taskGetter = taskGetter;
|
||||
return coroutineAction;
|
||||
}
|
||||
|
||||
public bool Paused { get; set; }
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (!IsFinalized)
|
||||
{
|
||||
IsFinalized = true;
|
||||
_taskGetter = null;
|
||||
if (_executingTask != null)
|
||||
{
|
||||
_executingTask.Dispose();
|
||||
_executingTask = null;
|
||||
}
|
||||
|
||||
ActionQueue.AddCallback(new ActionQueueRecycleCallback<TaskAction>(Pool, this));
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Paused = false;
|
||||
Status = ActionStatus.NotStart;
|
||||
}
|
||||
|
||||
public bool IsFinalized { get; set; }
|
||||
public ulong ActionID { get; set; }
|
||||
public ActionStatus Status { get; set; }
|
||||
|
||||
public void OnStart()
|
||||
{
|
||||
StartTask();
|
||||
}
|
||||
|
||||
async void StartTask()
|
||||
{
|
||||
_executingTask = _taskGetter();
|
||||
await _executingTask;
|
||||
Status = ActionStatus.Finished;
|
||||
_executingTask = null;
|
||||
}
|
||||
|
||||
public void OnExecute(float dt)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnFinish()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static class TaskExtension
|
||||
{
|
||||
public static ISequence Task(this ISequence self, Func<Task> taskGetter)
|
||||
{
|
||||
return self.Append(TaskAction.Allocate(taskGetter));
|
||||
}
|
||||
|
||||
public static IAction ToAction(this Task self)
|
||||
{
|
||||
return TaskAction.Allocate(() => self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67237f6ffaf4400c9aa58b59255996c5
|
||||
timeCreated: 1744891275
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public class ActionKit
|
||||
{
|
||||
public static ulong IDGenerator = 0;
|
||||
|
||||
public static IAction Delay(float seconds, Action callback)
|
||||
{
|
||||
return Kit.Delay.Allocate(seconds, callback);
|
||||
}
|
||||
|
||||
public static ISequence Sequence()
|
||||
{
|
||||
return Kit.Sequence.Allocate();
|
||||
}
|
||||
|
||||
public static IAction DelayFrame(int frameCount, Action onDelayFinish)
|
||||
{
|
||||
return Kit.DelayFrame.Allocate(frameCount, onDelayFinish);
|
||||
}
|
||||
|
||||
public static IAction NextFrame(Action onNextFrame)
|
||||
{
|
||||
return Kit.DelayFrame.Allocate(1, onNextFrame);
|
||||
}
|
||||
|
||||
public static IAction Lerp(float a,float b,float duration,Action<float> onLerp,Action onLerpFinish = null)
|
||||
{
|
||||
return Kit.Lerp.Allocate(a, b, duration, onLerp, onLerpFinish);
|
||||
}
|
||||
|
||||
public static IAction Callback(Action callback)
|
||||
{
|
||||
return Kit.Callback.Allocate(callback);
|
||||
}
|
||||
|
||||
public static IRepeat Repeat(int repeatCount = -1)
|
||||
{
|
||||
return Kit.Repeat.Allocate(repeatCount);
|
||||
}
|
||||
|
||||
public static IParallel Parallel()
|
||||
{
|
||||
return Kit.Parallel.Allocate();
|
||||
}
|
||||
|
||||
public void ComplexAPI()
|
||||
{
|
||||
}
|
||||
|
||||
public static IAction Coroutine(Func<IEnumerator> coroutineGetter)
|
||||
{
|
||||
return CoroutineAction.Allocate(coroutineGetter);
|
||||
}
|
||||
|
||||
public static IAction Task(Func<Task> taskGetter)
|
||||
{
|
||||
return TaskAction.Allocate(taskGetter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a5e4d15506047819281d5e7f59b7662
|
||||
timeCreated: 1744888755
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class ActionKitMonoBehaviourEvents : Singleton<ActionKitMonoBehaviourEvents>
|
||||
{
|
||||
private readonly EasyEvent _onUpdate = new();
|
||||
private readonly EasyEvent _onFixedUpdate = new();
|
||||
private readonly EasyEvent _onLateUpdate = new();
|
||||
private readonly EasyEvent _onGUIEvent = new();
|
||||
private readonly EasyEvent<bool> _onApplicationFocusEvent = new();
|
||||
private readonly EasyEvent<bool> _onApplicationPauseEvent = new();
|
||||
private readonly EasyEvent _onApplicationQuitEvent = new();
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
hideFlags = HideFlags.HideInHierarchy;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_onUpdate?.Trigger();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
_onGUIEvent?.Trigger();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
_onFixedUpdate?.Trigger();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
_onLateUpdate?.Trigger();
|
||||
}
|
||||
|
||||
private void OnApplicationFocus(bool hasFocus)
|
||||
{
|
||||
_onApplicationFocusEvent?.Trigger(hasFocus);
|
||||
}
|
||||
|
||||
private void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
_onApplicationPauseEvent?.Trigger(pauseStatus);
|
||||
}
|
||||
|
||||
// protected override void OnApplicationQuit()
|
||||
// {
|
||||
// OnApplicationQuitEvent?.Trigger();
|
||||
// base.OnApplicationQuit();
|
||||
// }
|
||||
|
||||
public void ExecuteCoroutine(IEnumerator coroutine, Action onFinish)
|
||||
{
|
||||
StartCoroutine(DoExecuteCoroutine(coroutine, onFinish));
|
||||
}
|
||||
|
||||
IEnumerator DoExecuteCoroutine(IEnumerator coroutine, Action onFinish)
|
||||
{
|
||||
yield return coroutine;
|
||||
onFinish?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d27b19f645194effb1d4a5b6f0920168
|
||||
timeCreated: 1745052634
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 859bc81acef44679a9915b0cc7e25685
|
||||
timeCreated: 1744888950
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal class MonoUpdateActionExecutor : MonoBehaviour, IActionExecutor
|
||||
{
|
||||
public class ActionTask
|
||||
{
|
||||
public IAction action;
|
||||
public IActionController controller;
|
||||
public Action<IActionController> onFinish;
|
||||
}
|
||||
|
||||
private List<ActionTask> _prepareExecutionActions = new();
|
||||
|
||||
private Dictionary<IAction, ActionTask> _executingActions = new();
|
||||
|
||||
private static SimpleObjectPool<ActionTask> _actionTaskPool = new(
|
||||
() => new ActionTask(), (task) =>
|
||||
{
|
||||
task.action = null;
|
||||
task.controller = null;
|
||||
task.onFinish = null;
|
||||
}, 50);
|
||||
|
||||
public void Execute(IActionController controller, Action<IActionController> onFinish = null)
|
||||
{
|
||||
if (controller.Action.Status == ActionStatus.Finished) controller.Action.Reset();
|
||||
if (this.UpdateAction(controller, 0, onFinish)) return;
|
||||
|
||||
var actionTask = _actionTaskPool.Allocate();
|
||||
actionTask.action = controller.Action;
|
||||
actionTask.controller = controller;
|
||||
actionTask.onFinish = onFinish;
|
||||
_prepareExecutionActions.Add(actionTask);
|
||||
}
|
||||
|
||||
private List<IActionController> _toActionRemove = new();
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_prepareExecutionActions.Count > 0)
|
||||
{
|
||||
foreach (var prepareExecutionAction in _prepareExecutionActions)
|
||||
{
|
||||
_executingActions[prepareExecutionAction.action] = prepareExecutionAction;
|
||||
}
|
||||
|
||||
_prepareExecutionActions.Clear();
|
||||
}
|
||||
|
||||
foreach (var actionAndFinishCallback in _executingActions)
|
||||
{
|
||||
if (actionAndFinishCallback.Value.controller.UpdateMode == ActionUpdateModes.ScaledDeltaTime)
|
||||
{
|
||||
if (this.UpdateAction(actionAndFinishCallback.Value.controller, Time.deltaTime,
|
||||
actionAndFinishCallback.Value.onFinish))
|
||||
{
|
||||
_toActionRemove.Add(actionAndFinishCallback.Value.controller);
|
||||
}
|
||||
}
|
||||
else if (actionAndFinishCallback.Value.controller.UpdateMode == ActionUpdateModes.UnscaledDeltaTime)
|
||||
{
|
||||
if (this.UpdateAction(actionAndFinishCallback.Value.controller, Time.unscaledDeltaTime,
|
||||
actionAndFinishCallback.Value.onFinish))
|
||||
{
|
||||
_toActionRemove.Add(actionAndFinishCallback.Value.controller);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_toActionRemove.Count > 0)
|
||||
{
|
||||
foreach (var controller in _toActionRemove)
|
||||
{
|
||||
_executingActions.Remove(controller.Action);
|
||||
controller.Recycle();
|
||||
}
|
||||
|
||||
_toActionRemove.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class MonoUpdateActionExecutorExtension
|
||||
{
|
||||
public static IAction ExecuteByUpdate<T>(this T self, IAction action, IActionController controller,
|
||||
Action<IActionController> onFinish = null)
|
||||
where T : MonoBehaviour
|
||||
{
|
||||
if (action.Status == ActionStatus.Finished) action.Reset();
|
||||
self.gameObject.GetOrAddComponent<MonoUpdateActionExecutor>().Execute(controller, onFinish);
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d24053c8e8e40c3a09184e719926842
|
||||
timeCreated: 1744889336
|
||||
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public enum ActionStatus
|
||||
{
|
||||
NotStart,
|
||||
Started,
|
||||
Finished,
|
||||
}
|
||||
|
||||
public enum ActionUpdateModes
|
||||
{
|
||||
ScaledDeltaTime,
|
||||
UnscaledDeltaTime,
|
||||
}
|
||||
|
||||
public interface IActionController
|
||||
{
|
||||
ulong ActionID { get; set; }
|
||||
|
||||
IAction Action { get; set; }
|
||||
|
||||
ActionUpdateModes UpdateMode { get; set; }
|
||||
|
||||
bool Paused { get; set; }
|
||||
void Reset();
|
||||
void Deinit();
|
||||
void Recycle();
|
||||
}
|
||||
|
||||
public interface IAction
|
||||
{
|
||||
ulong ActionID { get; set; }
|
||||
ActionStatus Status { get; set; }
|
||||
|
||||
void OnStart();
|
||||
void OnExecute(float dt);
|
||||
void OnFinish();
|
||||
|
||||
bool IsFinalized { get; set; }
|
||||
|
||||
bool Paused { get; set; }
|
||||
void Reset();
|
||||
void Deinit();
|
||||
}
|
||||
|
||||
public class ActionController : IActionController
|
||||
{
|
||||
private static readonly SimpleObjectPool<ActionController> Pool = new(
|
||||
() => new ActionController(), controller =>
|
||||
{
|
||||
controller.UpdateMode = ActionUpdateModes.ScaledDeltaTime;
|
||||
controller.ActionID = 0;
|
||||
controller.Action = null;
|
||||
}, 50);
|
||||
|
||||
public ulong ActionID { get; set; }
|
||||
public IAction Action { get; set; }
|
||||
|
||||
public ActionUpdateModes UpdateMode { get; set; }
|
||||
|
||||
private bool _recycled;
|
||||
|
||||
public bool Paused
|
||||
{
|
||||
get => Action.Paused;
|
||||
set => Action.Paused = value;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (Action.ActionID == ActionID)
|
||||
{
|
||||
Action.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public static IActionController Allocate()
|
||||
{
|
||||
var controller = Pool.Allocate();
|
||||
controller._recycled = false;
|
||||
return controller;
|
||||
}
|
||||
|
||||
public void Deinit()
|
||||
{
|
||||
if (Action != null && Action.ActionID == ActionID)
|
||||
{
|
||||
Action.Deinit();
|
||||
}
|
||||
}
|
||||
|
||||
public void Recycle()
|
||||
{
|
||||
Pool.Recycle(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class IActionExtensions
|
||||
{
|
||||
public static IActionController Start(this IAction self, MonoBehaviour monoBehaviour,
|
||||
Action<IActionController> onFinish = null)
|
||||
{
|
||||
var controller = ActionController.Allocate();
|
||||
controller.ActionID = self.ActionID;
|
||||
controller.Action = self;
|
||||
controller.UpdateMode = ActionUpdateModes.ScaledDeltaTime;
|
||||
monoBehaviour.ExecuteByUpdate(self, controller, onFinish);
|
||||
return controller;
|
||||
}
|
||||
|
||||
public static IActionController Start(this IAction self, MonoBehaviour monoBehaviour,
|
||||
Action onFinish)
|
||||
{
|
||||
var controller = ActionController.Allocate();
|
||||
controller.ActionID = self.ActionID;
|
||||
controller.Action = self;
|
||||
controller.UpdateMode = ActionUpdateModes.ScaledDeltaTime;
|
||||
monoBehaviour.ExecuteByUpdate(self, controller, _ => onFinish());
|
||||
return controller;
|
||||
}
|
||||
|
||||
// public static IActionController StartCurrentScene(this IAction self, Action<IActionController> onFinish = null)
|
||||
// {
|
||||
// return self.Start(ActionKitCurrentScene.SceneComponent, onFinish);
|
||||
// }
|
||||
//
|
||||
// public static IActionController StartCurrentScene(this IAction self, Action onFinish)
|
||||
// {
|
||||
// return self.Start(ActionKitCurrentScene.SceneComponent, onFinish);
|
||||
// }
|
||||
//
|
||||
// public static IActionController StartGlobal(this IAction self, Action<IActionController> onFinish = null)
|
||||
// {
|
||||
// return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
// }
|
||||
//
|
||||
// public static IActionController StartGlobal(this IAction self, Action onFinish)
|
||||
// {
|
||||
// return self.Start(ActionKitMonoBehaviourEvents.Instance, onFinish);
|
||||
// }
|
||||
|
||||
|
||||
public static void Pause(this IActionController self)
|
||||
{
|
||||
if (self.ActionID == self.Action.ActionID)
|
||||
{
|
||||
self.Action.Paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Resume(this IActionController self)
|
||||
{
|
||||
if (self.ActionID == self.Action.ActionID)
|
||||
{
|
||||
self.Action.Paused = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Finish(this IAction self)
|
||||
{
|
||||
self.Status = ActionStatus.Finished;
|
||||
}
|
||||
|
||||
public static bool Execute(this IAction self, float dt)
|
||||
{
|
||||
if (self.Status == ActionStatus.NotStart)
|
||||
{
|
||||
self.OnStart();
|
||||
|
||||
if (self.Status == ActionStatus.Finished)
|
||||
{
|
||||
self.OnFinish();
|
||||
return true;
|
||||
}
|
||||
|
||||
self.Status = ActionStatus.Started;
|
||||
}
|
||||
else if (self.Status == ActionStatus.Started)
|
||||
{
|
||||
if (self.Paused) return false;
|
||||
|
||||
self.OnExecute(dt);
|
||||
|
||||
if (self.Status == ActionStatus.Finished)
|
||||
{
|
||||
self.OnFinish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (self.Status == ActionStatus.Finished)
|
||||
{
|
||||
self.OnFinish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static class IActionControllerExtensions
|
||||
{
|
||||
public static IActionController IgnoreTimeScale(this IActionController self)
|
||||
{
|
||||
self.UpdateMode = ActionUpdateModes.UnscaledDeltaTime;
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IActionExecutor
|
||||
{
|
||||
void Execute(IActionController controller, Action<IActionController> onFinish = null);
|
||||
}
|
||||
|
||||
public static class IActionExecutorExtensions
|
||||
{
|
||||
public static bool UpdateAction(this IActionExecutor self, IActionController controller, float dt,
|
||||
Action<IActionController> onFinish = null)
|
||||
{
|
||||
if (!controller.Action.IsFinalized && controller.Action.Execute(dt))
|
||||
{
|
||||
onFinish?.Invoke(controller);
|
||||
controller.Deinit();
|
||||
return true;
|
||||
}
|
||||
|
||||
return controller.Action.IsFinalized;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a1f8142356f44a288ccc903195366cf4
|
||||
timeCreated: 1744888970
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00b12731cd0d48c7b1497b5e4c60bb1e
|
||||
timeCreated: 1744888872
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
internal interface IActionQueueCallback
|
||||
{
|
||||
void Call();
|
||||
}
|
||||
|
||||
internal struct ActionQueueRecycleCallback<T> : IActionQueueCallback
|
||||
{
|
||||
public SimpleObjectPool<T> pool;
|
||||
public T action;
|
||||
|
||||
public ActionQueueRecycleCallback(SimpleObjectPool<T> pool, T action)
|
||||
{
|
||||
this.pool = pool;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void Call()
|
||||
{
|
||||
pool.Recycle(action);
|
||||
pool = null;
|
||||
action = default;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ActionQueue : Singleton<ActionQueue>
|
||||
{
|
||||
private readonly List<IActionQueueCallback> _actionQueueCallbacks = new();
|
||||
|
||||
public static void AddCallback(IActionQueueCallback actionQueueCallback)
|
||||
{
|
||||
Instance._actionQueueCallbacks.Add(actionQueueCallback);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (_actionQueueCallbacks.Count > 0)
|
||||
{
|
||||
foreach (var actionQueueCallback in _actionQueueCallbacks)
|
||||
{
|
||||
actionQueueCallback.Call();
|
||||
}
|
||||
|
||||
_actionQueueCallbacks.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 086caf33452541fb8296dc009b6df232
|
||||
timeCreated: 1744889518
|
||||
@@ -50,7 +50,7 @@ namespace AibisDream.Kit
|
||||
// 场景切换相关
|
||||
EnumEventSystem.Global.Register<EventEnum, string>(EventEnum.SceneLoad, OnSceneLoad);
|
||||
EnumEventSystem.Global.Register<EventEnum, FixState>(EventEnum.FixStateSwitch, OnFixStateChange);
|
||||
EnumEventSystem.Global.Register(EventEnum.SceneUnload, OnSceneUnload);
|
||||
EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, OnGameQuit);
|
||||
}
|
||||
|
||||
private void RegisterData()
|
||||
@@ -62,6 +62,16 @@ namespace AibisDream.Kit
|
||||
|
||||
private void LoadData(AudioData data)
|
||||
{
|
||||
foreach (var musicEvent in _musicDict.Values)
|
||||
{
|
||||
musicEvent.release();
|
||||
}
|
||||
|
||||
foreach (var sfxEvent in _sfxDict.Values)
|
||||
{
|
||||
sfxEvent.release();
|
||||
}
|
||||
|
||||
foreach (var music in data.musicNames)
|
||||
{
|
||||
var instance = RuntimeManager.CreateInstance(music.Value);
|
||||
@@ -77,6 +87,38 @@ namespace AibisDream.Kit
|
||||
}
|
||||
}
|
||||
|
||||
public void PauseAll()
|
||||
{
|
||||
foreach (var music in _musicDict.Values)
|
||||
{
|
||||
music.setPaused(true);
|
||||
}
|
||||
|
||||
foreach (var sfx in _sfxDict.Values)
|
||||
{
|
||||
sfx.setPaused(true);
|
||||
}
|
||||
|
||||
_ambInstance.setPaused(true);
|
||||
_voiceInstance.setPaused(true);
|
||||
}
|
||||
|
||||
public void UnPauseAll()
|
||||
{
|
||||
foreach (var music in _musicDict.Values)
|
||||
{
|
||||
music.setPaused(false);
|
||||
}
|
||||
|
||||
foreach (var sfx in _sfxDict.Values)
|
||||
{
|
||||
sfx.setPaused(false);
|
||||
}
|
||||
|
||||
_ambInstance.setPaused(false);
|
||||
_voiceInstance.setPaused(false);
|
||||
}
|
||||
|
||||
#region AMB相关
|
||||
|
||||
private void InitAmb()
|
||||
@@ -102,7 +144,7 @@ namespace AibisDream.Kit
|
||||
ChangeAmb(state);
|
||||
}
|
||||
|
||||
private void OnSceneUnload()
|
||||
private void OnGameQuit()
|
||||
{
|
||||
ChangeAmb(AmbState.Main);
|
||||
// 清除当前播放的所有东西
|
||||
@@ -269,6 +311,16 @@ namespace AibisDream.Kit
|
||||
_audioData.sfxNames[key] = path;
|
||||
}
|
||||
|
||||
#region 调整音量
|
||||
|
||||
public void SetVolume(float volumeValue)
|
||||
{
|
||||
var masterVca = RuntimeManager.GetBus("bus:/");
|
||||
masterVca.setVolume(volumeValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 一些静态方法
|
||||
|
||||
private static string FormatEventPath(string eventName)
|
||||
@@ -329,6 +381,10 @@ namespace AibisDream.Kit
|
||||
public void PlaySfx(string eventName, string audioKey);
|
||||
public void StopSfx(string eventName, STOP_MODE stopMode);
|
||||
public void SetSfxParam(string eventName, string paramName, float paramValue);
|
||||
|
||||
// 暂停
|
||||
public void PauseAll();
|
||||
public void UnPauseAll();
|
||||
}
|
||||
|
||||
public class AudioData : IData
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Utility;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置项容器
|
||||
/// 1. 读取时可以直接从文件读取
|
||||
/// 2. 保存时可以直接保存到文件
|
||||
/// 3. 修改时会触发回调函数
|
||||
/// </summary>
|
||||
public class ConfigContainer
|
||||
{
|
||||
private readonly string _configPath;
|
||||
private JObject Data => JsonUtil.ReadJObject(_configPath);
|
||||
|
||||
public event Action<string, string> OnWrite;
|
||||
|
||||
public ConfigContainer(string configPath)
|
||||
{
|
||||
_configPath = configPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
public void Write(string key, string value)
|
||||
{
|
||||
var data = Data;
|
||||
data[key] = value;
|
||||
JsonUtil.SaveJObject(data, _configPath);
|
||||
OnWrite?.Invoke(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取配置项
|
||||
/// </summary>
|
||||
/// <param name="key">键</param>
|
||||
/// <param name="value">值</param>
|
||||
/// <returns>是否读取完成</returns>
|
||||
public bool TryRead(string key, out string value)
|
||||
{
|
||||
var res = Data.TryGetValue(key, out var jsValue);
|
||||
|
||||
value = jsValue?.ToString();
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取全部配置项为Dict
|
||||
/// </summary>
|
||||
/// <returns>配置项字典</returns>
|
||||
public Dictionary<string, string> ReadAll()
|
||||
{
|
||||
var data = Data;
|
||||
|
||||
var res = new Dictionary<string, string>();
|
||||
foreach (var pair in data)
|
||||
{
|
||||
res[pair.Key] = pair.Value.ToString();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8ca56ae1e7f40baa0f0141032dca60e
|
||||
timeCreated: 1744630397
|
||||
@@ -11,10 +11,8 @@ namespace AibisDream.Kit
|
||||
public class ConfigUtil : SingletonBase<ConfigUtil>
|
||||
{
|
||||
private const string CharacterConfigPath = "/Config/character.csv";
|
||||
private const string BaseConfigPath = "/Config/base_config.csv";
|
||||
private const string SpriteGroupPath = "/Config/sprite_group.json";
|
||||
|
||||
private Dictionary<string, string> _baseConfigDic;
|
||||
|
||||
private Dictionary<string, Character> _characters;
|
||||
private Dictionary<string, SpriteGroupConfig> _spriteConfigDict;
|
||||
|
||||
@@ -30,27 +28,10 @@ namespace AibisDream.Kit
|
||||
/// </summary>
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
InitBaseConfig();
|
||||
InitCharacterConfig();
|
||||
InitSpriteGroupConfig();
|
||||
}
|
||||
|
||||
private void InitBaseConfig()
|
||||
{
|
||||
var baseList = CsvUtil.Read(Application.streamingAssetsPath + BaseConfigPath);
|
||||
if (baseList.Count <= 0)
|
||||
{
|
||||
Debug.Log("基础配置不存在");
|
||||
}
|
||||
|
||||
// 基础配置只有key和value
|
||||
_baseConfigDic = new Dictionary<string, string>();
|
||||
foreach (var arr in baseList)
|
||||
{
|
||||
_baseConfigDic.Add(arr[0], arr[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitCharacterConfig()
|
||||
{
|
||||
var characterList = CsvUtil.ReadAsBean<Character>(Application.streamingAssetsPath + CharacterConfigPath);
|
||||
@@ -74,17 +55,6 @@ namespace AibisDream.Kit
|
||||
return _characters.TryGetValue(key, out character);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按key获取基础配置
|
||||
/// </summary>
|
||||
/// <param name="key">key</param>
|
||||
/// <param name="value">配置项</param>
|
||||
/// <returns>是否能获取</returns>
|
||||
public bool TryGetBaseConfig(string key, out string value)
|
||||
{
|
||||
return _baseConfigDic.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存SpriteGroupConfig
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
public static class FadeKit
|
||||
{
|
||||
public static IEnumerator FadeInAsync(this Image image, float duration)
|
||||
{
|
||||
image.gameObject.SetActive(true);
|
||||
var tweener = image.DOBlendableColor(Color.white, duration);
|
||||
yield return tweener.WaitForCompletion();
|
||||
}
|
||||
|
||||
public static void FadeIn(this Image image, float duration)
|
||||
{
|
||||
image.gameObject.SetActive(true);
|
||||
var tweener = image.DOBlendableColor(Color.white, duration);
|
||||
}
|
||||
|
||||
public static IEnumerator FadeOutAsync(this Image image, float duration)
|
||||
{
|
||||
image.gameObject.SetActive(true);
|
||||
var tweener = image.DOBlendableColor(Color.clear, duration);
|
||||
yield return tweener.WaitForCompletion();
|
||||
image.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public static void FadeOut(this Image image, float duration)
|
||||
{
|
||||
image.gameObject.SetActive(true);
|
||||
image.DOBlendableColor(Color.clear, duration).onComplete += () =>
|
||||
{
|
||||
image.gameObject.SetActive(false);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09319533608646369f9418994e9c8ae1
|
||||
timeCreated: 1744781879
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AibisDream.Kit
|
||||
{
|
||||
public static class ListPool<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 栈对象:存储多个List
|
||||
/// </summary>
|
||||
static readonly Stack<List<T>> ListStack = new(8);
|
||||
|
||||
/// <summary>
|
||||
/// 出栈:获取某个List对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<T> Get()
|
||||
{
|
||||
return ListStack.Count == 0 ? new List<T>(8) : ListStack.Pop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 入栈:将List对象添加到栈中
|
||||
/// </summary>
|
||||
/// <param name="toRelease"></param>
|
||||
public static void Release(List<T> toRelease)
|
||||
{
|
||||
if (ListStack.Contains(toRelease))
|
||||
{
|
||||
throw new System.InvalidOperationException(
|
||||
"重复回收 List,The List is released even though it is in the pool");
|
||||
}
|
||||
|
||||
toRelease.Clear();
|
||||
ListStack.Push(toRelease);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ListPoolExtensions
|
||||
{
|
||||
public static void Release2Pool<T>(this List<T> self)
|
||||
{
|
||||
ListPool<T>.Release(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89941b90c44f437dbdda9030f43dd912
|
||||
timeCreated: 1744888603
|
||||
Reference in New Issue
Block a user