Skip to content

Commit 588f5b1

Browse files
author
wanderer
committed
UIManager增加异步打开的接口
1 parent e97abb4 commit 588f5b1

File tree

3 files changed

+116
-38
lines changed

3 files changed

+116
-38
lines changed

GameFramework/Runtime/Debugger/ConsoleWindow.cs

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55
using System.Reflection;
6+
using System.Text;
67

78
namespace Wanderer.GameFramework
89
{
@@ -15,6 +16,10 @@ public class ConsoleWindow : IDebuggerWindow
1516
private Dictionary<string, MethodInfo> _commandMethod = new Dictionary<string, MethodInfo>();
1617
//action执行函数
1718
private Dictionary<string, Action> _commandAction = new Dictionary<string, Action>();
19+
//命令帮助
20+
private Dictionary<string, string> _commandHelp = new Dictionary<string, string>();
21+
//命令反馈
22+
private Dictionary<string, string> _commandFeedback=new Dictionary<string, string>();
1823
//支持反射
1924
private bool _reflectionSupported = true;
2025
//支持消息发送
@@ -28,22 +33,10 @@ public class ConsoleWindow : IDebuggerWindow
2833

2934
public void OnInit(params object[] args)
3035
{
31-
_commandAction.Add("d1", () =>
32-
{
33-
Debug.unityLogger.logEnabled = true;
34-
});
35-
_commandAction.Add("d0", () =>
36-
{
37-
Debug.unityLogger.logEnabled = false;
38-
});
39-
_commandAction.Add("f1", () =>
40-
{
41-
GameFrameworkMode.GetModule<DebuggerManager>().SetLogFileEnable(true);
42-
});
43-
_commandAction.Add("f0", () =>
44-
{
45-
GameFrameworkMode.GetModule<DebuggerManager>().SetLogFileEnable(false);
46-
});
36+
AddCommand("d0", () => { Debug.unityLogger.logEnabled = false; }, "关闭Debug.Log","Log disabled.");
37+
AddCommand("d1", () => { Debug.unityLogger.logEnabled = true; }, "开启Debug.Log", "Log enabled.");
38+
AddCommand("f0", () => { GameFrameworkMode.GetModule<DebuggerManager>().SetLogFileEnable(false); }, "关闭日志文件", "Log file disabled.");
39+
AddCommand("f1", () => { GameFrameworkMode.GetModule<DebuggerManager>().SetLogFileEnable(true); }, "开启日志文件", "Log file enabled.");
4740
}
4841

4942
public void OnEnter()
@@ -106,24 +99,52 @@ public void OnDraw()
10699
/// </summary>
107100
/// <param name="command"></param>
108101
/// <param name="callAction"></param>
109-
public void AddCommand(string command, Action callAction)
102+
public void AddCommand(string command, Action callAction,string help=null,string feedback = null)
110103
{
111104
if (!_commandAction.ContainsKey(command))
112105
{
113106
_commandAction.Add(command, callAction);
114107
}
108+
if (!string.IsNullOrEmpty(help))
109+
{
110+
if (!_commandHelp.ContainsKey(command))
111+
{
112+
_commandHelp.Add(command, help);
113+
}
114+
}
115+
if (!string.IsNullOrEmpty(feedback))
116+
{
117+
if (!_commandFeedback.ContainsKey(command))
118+
{
119+
_commandFeedback.Add(command, feedback);
120+
}
121+
}
115122
}
116123
/// <summary>
117124
/// 添加命令
118125
/// </summary>
119126
/// <param name="command"></param>
120127
/// <param name="callMethod"></param>
121-
public void AddCommand(string command, MethodInfo callMethod)
128+
public void AddCommand(string command, MethodInfo callMethod,string help = null, string feedback = null)
122129
{
123130
if (!_commandMethod.ContainsKey(command))
124131
{
125132
_commandMethod.Add(command, callMethod);
126133
}
134+
if (!string.IsNullOrEmpty(help))
135+
{
136+
if (!_commandHelp.ContainsKey(command))
137+
{
138+
_commandHelp.Add(command, help);
139+
}
140+
}
141+
if (!string.IsNullOrEmpty(feedback))
142+
{
143+
if (!_commandFeedback.ContainsKey(command))
144+
{
145+
_commandFeedback.Add(command, feedback);
146+
}
147+
}
127148
}
128149
/// <summary>
129150
/// 移除命令
@@ -139,6 +160,14 @@ public void RemoveCommand(string command)
139160
{
140161
_commandMethod.Remove(command);
141162
}
163+
if (_commandHelp.ContainsKey(command))
164+
{
165+
_commandHelp.Remove(command);
166+
}
167+
if (_commandFeedback.ContainsKey(command))
168+
{
169+
_commandFeedback.Remove(command);
170+
}
142171
}
143172
#endregion
144173

@@ -179,6 +208,10 @@ private void ExecuteCommand(string command)
179208
if (_commandAction.TryGetValue(command, out Action callAction))
180209
{
181210
callAction.Invoke();
211+
if (_commandFeedback.TryGetValue(command, out string feedback))
212+
{
213+
AddLine(feedback);
214+
}
182215
return;
183216
}
184217

@@ -195,7 +228,6 @@ private void ExecuteCommand(string command)
195228
MethodInfo callMethod;
196229
if (!_commandMethod.TryGetValue(command, out callMethod))
197230
{
198-
199231
int index = command.LastIndexOf('.');
200232
if (index > 0 && index < command.Length - 1)
201233
{
@@ -255,6 +287,15 @@ private void ExecuteCommand(string command)
255287
}
256288
}
257289
}
290+
else
291+
{
292+
callMethod.Invoke(null,null);
293+
if (_commandFeedback.TryGetValue(command, out string feedback))
294+
{
295+
AddLine(feedback);
296+
}
297+
return;
298+
}
258299

259300

260301
//添加反馈
@@ -264,11 +305,22 @@ private void ExecuteCommand(string command)
264305
//执行默认的命令
265306
private int ExecuteDefaultCommand(string command)
266307
{
308+
command = command.ToLower();
267309
switch (command)
268310
{
269311
case "clear":
270312
ClearLines();
271313
return 0;
314+
case "help":
315+
StringBuilder helpBuilder = new StringBuilder();
316+
helpBuilder.AppendLine("help\tSee all the commands and the corresponding help.");
317+
helpBuilder.AppendLine("clear\tClean up all lines.");
318+
foreach (var item in _commandHelp)
319+
{
320+
helpBuilder.AppendLine($"{item.Key}\t{item.Value}.");
321+
}
322+
AddLine(helpBuilder.ToString());
323+
return 0;
272324
}
273325
return -1;
274326
}

GameFramework/Runtime/UI/UIManager.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public UIManager()
6464
/// <param name="callBack"></param>
6565
/// <param name="parameters"></param>
6666
/// <returns></returns>
67-
public IUITween Push(IUIContext uiContext, Action<string> callBack=null, params object[] parameters)
67+
public IUITween Push(IUIContext uiContext, Action<string> callBack=null, bool async = false, params object[] parameters)
6868
{
6969
//动态获取uiTween
7070
UITween uiTweener = UITweePool.Get();
@@ -103,23 +103,30 @@ public IUITween Push(IUIContext uiContext, Action<string> callBack=null, params
103103
}
104104
//处理新的ui
105105
_activeUIContextList.Add(uiContext);
106-
////异步加载
107-
//GetUIView(uiContext, (newUiView) => {
108-
// newUiView.OnEnter(uiContext, callBack, parameters);
109-
// _uiEnterArgs.UIView = newUiView;
110-
// _event.Trigger(this, _uiEnterArgs);
111-
// //设置打开的uiview
112-
// uiTweener.SetNextUIView(newUiView);
113-
// uiTweener.SetUITweenReady();
114-
//});
115106

116-
UIView newUiView = GetUIView(uiContext);
117-
newUiView.OnEnter(uiContext, callBack, parameters);
118-
//触发打开事件
119-
_uiEnterArgs.UIView = newUiView;
120-
_event.Trigger(this, _uiEnterArgs);
121-
//设置打开的uiview
122-
uiTweener.SetNextUIView(newUiView);
107+
if (async)
108+
{
109+
//异步加载
110+
GetUIView(uiContext, (newUiView) =>
111+
{
112+
newUiView.OnEnter(uiContext, callBack, parameters);
113+
_uiEnterArgs.UIView = newUiView;
114+
_event.Trigger(this, _uiEnterArgs);
115+
//设置打开的uiview
116+
uiTweener.SetNextUIView(newUiView);
117+
uiTweener.SetUITweenReadyAsync();
118+
});
119+
}
120+
else
121+
{
122+
UIView newUiView = GetUIView(uiContext);
123+
newUiView.OnEnter(uiContext, callBack, parameters);
124+
//触发打开事件
125+
_uiEnterArgs.UIView = newUiView;
126+
_event.Trigger(this, _uiEnterArgs);
127+
//设置打开的uiview
128+
uiTweener.SetNextUIView(newUiView);
129+
}
123130
return uiTweener;
124131
}
125132

@@ -130,12 +137,12 @@ public IUITween Push(IUIContext uiContext, Action<string> callBack=null, params
130137
/// <param name="callBack"></param>
131138
/// <param name="parameters"></param>
132139
/// <returns></returns>
133-
public IUITween Push(string assetPath, Action<string> callBack=null, params object[] parameters)
140+
public IUITween Push(string assetPath, Action<string> callBack=null, bool async = false,params object[] parameters)
134141
{
135142
IUIContext uiContext = UIContextMgr[assetPath];
136143
if (uiContext != null)
137144
{
138-
IUITween uiTween = Push(uiContext, callBack, parameters);
145+
IUITween uiTween = Push(uiContext, callBack, async, parameters);
139146
return uiTween;
140147
}
141148
return null;

GameFramework/Runtime/UI/UITween.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface IUITween
1313
UIView NextUIView { get; }
1414
//UITween准备好
1515
IUITween OnUITweenReady(Action<IUITween,UIView, UIView> onUITweenReady);
16+
//UITween准备好 异步
17+
IUITween OnUITweenReadyAsync(Action<IUITween, UIView, UIView> onUITweenReady);
1618
//动画开始回调
1719
IUITween OnAnimationStart(Action<UIView, UIView> onAnimStart);
1820
//动画结束
@@ -30,6 +32,7 @@ public interface IUITween
3032
internal class UITween : IUITween
3133
{
3234
private Action<IUITween,UIView, UIView> _onUITweenReady;
35+
private Action<IUITween, UIView, UIView> _onUITweenReadyAsync;
3336
private Action<UIView, UIView> _onAnimStart;
3437
private Action<UIView, UIView> _onAnimComplete;
3538
private Action<IUIAnimation, IUIAnimation> _onAnimChanged;
@@ -55,6 +58,7 @@ public bool HasAnims
5558
public UITween Flush()
5659
{
5760
_onUITweenReady = null;
61+
_onUITweenReadyAsync = null;
5862
_onAnimStart = null;
5963
_onAnimComplete = null;
6064
_onAnimChanged = null;
@@ -110,6 +114,13 @@ public IUITween OnUITweenReady(Action<IUITween,UIView, UIView> onUITweenReady)
110114
return this;
111115
}
112116

117+
//UITween准备好 异步
118+
public IUITween OnUITweenReadyAsync(Action<IUITween, UIView, UIView> onUITweenReady)
119+
{
120+
_onUITweenReadyAsync = onUITweenReady;
121+
return this;
122+
}
123+
113124
public IUITween OnAnimationChanged(Action<IUIAnimation, IUIAnimation> onAnimChanged)
114125
{
115126
_onAnimChanged += onAnimChanged;
@@ -133,6 +144,14 @@ public IUITween OnAnimationStart(Action<UIView, UIView> onAnimStart)
133144
return this;
134145
}
135146

147+
/// <summary>
148+
/// 设置异步准备
149+
/// </summary>
150+
public void SetUITweenReadyAsync()
151+
{
152+
_onUITweenReadyAsync?.Invoke(this, LastUIView, NextUIView);
153+
}
154+
136155
public IUITween SetAnimation(IUIAnimation anim)
137156
{
138157
_anims.Add(anim);

0 commit comments

Comments
 (0)