Skip to content

Commit e8e769e

Browse files
author
wanderer
committed
增加dotween插件,修改UITween让动画使用更流畅
1 parent 55dbba3 commit e8e769e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+5214
-91
lines changed

Base/DefaultConfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"ResourceUpdateType":3,"DebugEnable":true,"PathType":1,"ResTestUpdatePath":"","ResOfficialUpdatePath":"","DefaultInStreamingAsset":true,"LogMaxLine":100}
1+
{"ResourceUpdateType":0,"DebugEnable":true,"PathType":1,"ResTestUpdatePath":"","ResOfficialUpdatePath":"","DefaultInStreamingAsset":true,"LogMaxLine":100}

Base/GameMode.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ public JsonData ConfigJsonData
8383
IEnumerator Start()
8484
{
8585
GameMode.Self = this;
86-
87-
8886
//默认不销毁
8987
DontDestroyOnLoad(gameObject);
9088

@@ -145,24 +143,17 @@ IEnumerator Start()
145143
WebRequest.SetWebDownloadHelper(webDownloadHelper.AddComponent<WebDownloadMonoHelper>());
146144
#endregion
147145

148-
// #region Setting
149-
// GameObject debugHelper = transform.Find("[Graphy]").gameObject;
150-
// Setting.SetDebuger(debugHelper);
151-
// Setting.DebugEnable = DebugEnable;
152-
// #endregion
153-
154146
#region state
155147
//开启整个项目的流程
156148
Assembly = typeof(GameMode).Assembly;
157149
FSM.AddFSM<GameStateContext>();
158-
// GameState.CreateContext();
159-
yield return new WaitForEndOfFrame();
150+
// yield return new WaitForEndOfFrame();
160151
GameFrameworkMode.Init();
161-
// yield return new WaitForEndOfFrame();
162-
// GameState.SetStateStart();
163152
FSM.GetFSM<GameStateContext>().OnBegin();
164153
#endregion
165154

155+
yield return new WaitForEndOfFrame();
156+
166157
}
167158

168159
private void Update()

GameFramework/Runtime/Debugger/DebuggerManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class DebuggerManager : GameFrameworkModule, IImGui, IUpdate
1010
/// <summary>
1111
/// 窗口缩放
1212
/// </summary>
13-
public float WindowScale = 1.0f;
13+
public float WindowScale = 1.5f;
1414
private bool _showFullWindow = false;
1515
//皮肤
1616
private GUISkin _consoleSkin;

GameFramework/Runtime/UI/UIManager.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public sealed class UIManager : GameFrameworkModule
2626
private UIResumeEventArgs _uiResumeArgs;
2727
private UITween _uiTweener;
2828

29+
//uiview的父物体
30+
private Transform _uiViewParent;
2931
//资源管理器
3032
private ResourceManager _resource;
3133
//ui 列表
@@ -54,14 +56,15 @@ public UIManager()
5456
#endregion
5557

5658
#region 外部接口
57-
59+
5860
/// <summary>
59-
/// 推送UI
61+
/// 推送UI
6062
/// </summary>
6163
/// <param name="uiContext"></param>
64+
/// <param name="callBack"></param>
6265
/// <param name="parameters"></param>
6366
/// <returns></returns>
64-
public IUITween Push(IUIContext uiContext, params object[] parameters)
67+
public IUITween Push(IUIContext uiContext, Action<string> callBack=null, params object[] parameters)
6568
{
6669
_uiTweener.Flush();
6770
if (uiContext == null)
@@ -94,28 +97,28 @@ public IUITween Push(IUIContext uiContext, params object[] parameters)
9497
//处理新的ui
9598
_activeUIContextList.Add(uiContext);
9699
UIView newUiView = GetUIView(uiContext);
97-
newUiView.OnEnter(uiContext, parameters);
100+
newUiView.OnEnter(uiContext, callBack,parameters);
98101
//触发打开事件
99102
_uiEnterArgs.UIView = newUiView;
100103
_event.Trigger(this, _uiEnterArgs);
101104
//设置打开的uiview
102105
_uiTweener.SetNextUIView(newUiView);
103-
104106
return _uiTweener;
105107
}
106108

107109
/// <summary>
108110
/// 推送UI
109111
/// </summary>
110112
/// <param name="assetPath"></param>
113+
/// <param name="callBack"></param>
111114
/// <param name="parameters"></param>
112115
/// <returns></returns>
113-
public IUITween Push(string assetPath, params object[] parameters)
116+
public IUITween Push(string assetPath, Action<string> callBack=null, params object[] parameters)
114117
{
115118
IUIContext uiContext = UIContextMgr[assetPath];
116119
if (uiContext != null)
117120
{
118-
IUITween uiTween = Push(uiContext);
121+
IUITween uiTween = Push(uiContext, callBack, parameters);
119122
return uiTween;
120123
}
121124
return null;
@@ -254,6 +257,15 @@ public UIView GetActiveUIView(string assetPath)
254257
return null;
255258
}
256259

260+
/// <summary>
261+
/// 设置UIView的父级物体
262+
/// </summary>
263+
/// <param name="parent"></param>
264+
public void SetUIViewParent(Transform viewParent)
265+
{
266+
_uiViewParent = viewParent;
267+
}
268+
257269
#endregion
258270

259271
#region 内部函数
@@ -267,7 +279,7 @@ private UIView GetUIView(IUIContext uiContext)
267279
if (uiViewSource == null)
268280
throw new GameException("uiview path not found:" + uiContext.AssetPath);
269281

270-
GameObject uiViewClone = GameObject.Instantiate(uiViewSource);
282+
GameObject uiViewClone = GameObject.Instantiate(uiViewSource, _uiViewParent);
271283
uiView = uiViewClone.GetComponent<UIView>();
272284
if (uiView == null)
273285
return null;

GameFramework/Runtime/UI/UITween.cs

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ public interface IUITween
1111
UIView LastUIView { get; }
1212

1313
UIView NextUIView { get; }
14+
//UITween准备好
15+
IUITween OnUITweenReady(Action<UIView,UIView> onUITweenReady);
1416
//动画开始回调
15-
IUITween OnAnimationStart(Action OnAnimStart);
17+
IUITween OnAnimationStart(Action<UIView, UIView> onAnimStart);
1618
//动画结束
17-
IUITween OnAnimationComplete(Action OnAnimComplete);
19+
IUITween OnAnimationComplete(Action<UIView, UIView> onAnimComplete);
1820
//动画切换
19-
IUITween OnAnimationChanged(Action<IUIAnimation, IUIAnimation> OnAnimChanged);
21+
IUITween OnAnimationChanged(Action<IUIAnimation, IUIAnimation> onAnimChanged);
2022
//设置动画数组
2123
IUITween SetAnimations(IUIAnimation[] anims);
22-
//设置动画队列
23-
IUITween SetAnimations(Queue<IUIAnimation> anims);
2424
//播放动画
25-
IUITween RunAnimation();
25+
IUITween RunAnimation(bool isQueue = false);
2626
}
2727

2828
internal class UITween : IUITween
2929
{
30-
private Action _onAnimStart;
31-
private Action _onAnimComplete;
30+
private Action<UIView,UIView> _onUITweenReady;
31+
private Action<UIView, UIView> _onAnimStart;
32+
private Action<UIView, UIView> _onAnimComplete;
3233
private Action<IUIAnimation, IUIAnimation> _onAnimChanged;
33-
private IUIAnimation[] _arrayAnims;
34-
private Queue<IUIAnimation> _queueAnims;
34+
private List<IUIAnimation> _anims=new List<IUIAnimation>();
3535

3636
/// <summary>
3737
/// 上一个UIView
@@ -44,14 +44,13 @@ internal class UITween : IUITween
4444

4545
public UITween Flush()
4646
{
47+
_onUITweenReady = null;
4748
_onAnimStart = null;
4849
_onAnimComplete = null;
4950
_onAnimChanged = null;
5051
LastUIView = null;
5152
NextUIView = null;
52-
_arrayAnims = null;
53-
_queueAnims = null;
54-
53+
_anims.Clear();
5554
return this;
5655
}
5756

@@ -65,14 +64,19 @@ public void SetNextUIView(UIView uiView)
6564
NextUIView = uiView;
6665
}
6766

67+
private void SetUITweenReady()
68+
{
69+
_onUITweenReady?.Invoke(LastUIView,NextUIView);
70+
}
71+
6872
private void SetAnimationStart()
6973
{
70-
_onAnimStart?.Invoke();
74+
_onAnimStart?.Invoke(LastUIView, NextUIView);
7175
}
7276

7377
private void SetAnimationComplete()
7478
{
75-
_onAnimComplete?.Invoke();
79+
_onAnimComplete?.Invoke(LastUIView, NextUIView);
7680
Flush();
7781
}
7882

@@ -81,89 +85,95 @@ private void SetAnimationChanged(IUIAnimation lastAnim, IUIAnimation nextAnim)
8185
_onAnimChanged?.Invoke(lastAnim, nextAnim);
8286
}
8387

84-
public IUITween OnAnimationChanged(Action<IUIAnimation, IUIAnimation> OnAnimChanged)
88+
public IUITween OnUITweenReady(Action<UIView, UIView> onUITweenReady)
8589
{
86-
_onAnimChanged += OnAnimChanged;
90+
_onUITweenReady = onUITweenReady;
8791
return this;
8892
}
8993

90-
public IUITween OnAnimationComplete(Action OnAnimComplete)
94+
public IUITween OnAnimationChanged(Action<IUIAnimation, IUIAnimation> onAnimChanged)
9195
{
92-
_onAnimComplete += OnAnimComplete;
96+
_onAnimChanged += onAnimChanged;
9397
return this;
9498
}
9599

96-
public IUITween OnAnimationStart(Action OnAnimStart)
100+
public IUITween OnAnimationComplete(Action<UIView, UIView> onAnimComplete)
97101
{
98-
_onAnimStart += OnAnimStart;
102+
_onAnimComplete += onAnimComplete;
99103
return this;
100104
}
101105

102-
public IUITween SetAnimations(IUIAnimation[] anims)
106+
public IUITween OnAnimationStart(Action<UIView, UIView> onAnimStart)
103107
{
104-
_arrayAnims = anims;
108+
_onAnimStart += onAnimStart;
105109
return this;
106110
}
107111

108-
public IUITween SetAnimations(Queue<IUIAnimation> anims)
112+
public IUITween SetAnimations(IUIAnimation[] anims)
109113
{
110-
_queueAnims = anims;
114+
_anims.AddRange(anims);
111115
return this;
112116
}
113117

114-
public IUITween RunAnimation()
118+
119+
public IUITween RunAnimation(bool isQueue = false)
115120
{
116-
RunAnim();
121+
RunAnim(isQueue);
117122
return this;
118123
}
119124

120-
private async void RunAnim()
125+
private async void RunAnim(bool isQueue = false)
121126
{
122-
if (_arrayAnims != null && _arrayAnims.Length > 0)
127+
//回调准备
128+
SetUITweenReady();
129+
//播放动画
130+
if (_anims != null && _anims.Count > 0)
123131
{
124132
await UniTask.NextFrame();
125-
UniTask[] animTask = new UniTask[_arrayAnims.Length];
126-
for (int i = 0; i < _arrayAnims.Length; i++)
127-
{
128-
//call ui view
129-
AnimStartCallUIView(_arrayAnims[i]);
130-
animTask[i] = _arrayAnims[i].Run();
131-
}
132-
//call tween
133-
this.SetAnimationStart();
134-
await UniTask.WhenAll(animTask);
135-
await UniTask.NextFrame();
136-
for (int i = 0; i < _arrayAnims.Length; i++)
133+
if (isQueue)
137134
{
138-
//call ui view
139-
AnimEndCallUIView(_arrayAnims[i]);
135+
this.SetAnimationStart();
136+
IUIAnimation lastAnim = null;
137+
for (int i = 0; i < _anims.Count; i++)
138+
{
139+
IUIAnimation nextAnim = _anims[i];
140+
//call ui view
141+
if (lastAnim != null)
142+
{
143+
AnimEndCallUIView(lastAnim);
144+
}
145+
AnimStartCallUIView(nextAnim);
146+
//call tween
147+
this.SetAnimationChanged(lastAnim, nextAnim);
148+
await nextAnim.Run();
149+
lastAnim = nextAnim;
150+
151+
}
152+
await UniTask.NextFrame();
140153
}
141-
//call tween
142-
this.SetAnimationComplete();
143-
}
144-
else if (_queueAnims != null && _queueAnims.Count > 0)
145-
{
146-
await UniTask.NextFrame();
147-
this.SetAnimationStart();
148-
IUIAnimation lastAnim = null;
149-
while (_queueAnims.Count > 0)
150-
{
151-
IUIAnimation nextAnim = _queueAnims.Dequeue();
152-
//call ui view
153-
if (lastAnim != null)
154+
else
155+
{
156+
UniTask[] animTask = new UniTask[_anims.Count];
157+
for (int i = 0; i < _anims.Count; i++)
154158
{
155-
AnimEndCallUIView(lastAnim);
159+
//call ui view
160+
AnimStartCallUIView(_anims[i]);
161+
animTask[i] = _anims[i].Run();
156162
}
157-
AnimStartCallUIView(nextAnim);
158163
//call tween
159-
this.SetAnimationChanged(lastAnim, nextAnim);
160-
await nextAnim.Run();
161-
lastAnim = nextAnim;
164+
this.SetAnimationStart();
165+
await UniTask.WhenAll(animTask);
166+
await UniTask.NextFrame();
167+
for (int i = 0; i < _anims.Count; i++)
168+
{
169+
//call ui view
170+
AnimEndCallUIView(_anims[i]);
171+
}
162172
}
163-
await UniTask.NextFrame();
173+
174+
//call tween
164175
this.SetAnimationComplete();
165176
}
166-
167177
}
168178

169179
private void AnimStartCallUIView(IUIAnimation uiAnim)

0 commit comments

Comments
 (0)