Skip to content

Commit afb8451

Browse files
committed
简化框架加载流程。
1 parent d9337d7 commit afb8451

File tree

7 files changed

+43
-79
lines changed

7 files changed

+43
-79
lines changed

Assets/LuaFramework/Lua/Logic/GameManager.lua renamed to Assets/LuaFramework/Lua/Logic/Game.lua

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,29 @@ require "Logic/CtrlManager"
1919
require "Controller/PromptCtrl"
2020

2121
--管理器--
22-
GameManager = {};
23-
local this = GameManager;
22+
Game = {};
23+
local this = Game;
2424

2525
local game;
2626
local transform;
2727
local gameObject;
2828
local WWW = UnityEngine.WWW;
2929

30-
function GameManager.LuaPanels()
31-
return unpack(PanelNames);
30+
function Game.InitViewPanels()
31+
for i = 1, #PanelNames do
32+
require ("View/"..tostring(PanelNames[i]))
33+
end
3234
end
3335

3436
--初始化完成,发送链接服务器信息--
35-
function GameManager.OnInitOK()
37+
function Game.OnInitOK()
3638
AppConst.SocketPort = 2012;
3739
AppConst.SocketAddress = "127.0.0.1";
3840
networkMgr:SendConnect();
3941

42+
--注册LuaView--
43+
this.InitViewPanels();
44+
4045
--this.test_class_func();
4146
--this.test_pblua_func();
4247
--this.test_cjson_func();
@@ -50,11 +55,11 @@ function GameManager.OnInitOK()
5055
if ctrl ~= nil and AppConst.ExampleMode then
5156
ctrl:Awake();
5257
end
53-
logWarn('SimpleFramework InitOK--->>>');
58+
logWarn('LuaFramework InitOK--->>>');
5459
end
5560

5661
--测试协同--
57-
function GameManager.test_coroutine()
62+
function Game.test_coroutine()
5863
logWarn("1111");
5964
coroutine.wait(1);
6065
logWarn("2222");
@@ -65,7 +70,7 @@ function GameManager.test_coroutine()
6570
end
6671

6772
--测试sproto--
68-
function GameManager.test_sproto_func()
73+
function Game.test_sproto_func()
6974
logWarn("test_sproto_func-------->>");
7075
local sp = sproto.parse [[
7176
.Person {
@@ -121,7 +126,7 @@ function GameManager.test_sproto_func()
121126
end
122127

123128
--测试lpeg--
124-
function GameManager.test_lpeg_func()
129+
function Game.test_lpeg_func()
125130
logWarn("test_lpeg_func-------->>");
126131
-- matches a word followed by end-of-string
127132
local p = lpeg.R"az"^1 * -1
@@ -132,12 +137,12 @@ function GameManager.test_lpeg_func()
132137
end
133138

134139
--测试lua类--
135-
function GameManager.test_class_func()
140+
function Game.test_class_func()
136141
LuaClass:New(10, 20):test();
137142
end
138143

139144
--测试pblua--
140-
function GameManager.test_pblua_func()
145+
function Game.test_pblua_func()
141146
local login = login_pb.LoginRequest();
142147
login.id = 2000;
143148
login.name = 'game';
@@ -148,15 +153,15 @@ function GameManager.test_pblua_func()
148153
end
149154

150155
--pblua callback--
151-
function GameManager.OnPbluaCall(data)
156+
function Game.OnPbluaCall(data)
152157
local msg = login_pb.LoginRequest();
153158
msg:ParseFromString(data);
154159
print(msg);
155160
print(msg.id..' '..msg.name);
156161
end
157162

158163
--测试pbc--
159-
function GameManager.test_pbc_func()
164+
function Game.test_pbc_func()
160165
local path = Util.DataPath.."lua/3rd/pbc/addressbook.pb";
161166
log('io.open--->>>'..path);
162167

@@ -178,7 +183,7 @@ function GameManager.test_pbc_func()
178183
end
179184

180185
--pbc callback--
181-
function GameManager.OnPbcCall(data)
186+
function Game.OnPbcCall(data)
182187
local path = Util.DataPath.."lua/3rd/pbc/addressbook.pb";
183188

184189
local addr = io.open(path, "rb")
@@ -195,19 +200,19 @@ function GameManager.OnPbcCall(data)
195200
end
196201

197202
--测试cjson--
198-
function GameManager.test_cjson_func()
203+
function Game.test_cjson_func()
199204
local path = Util.DataPath.."lua/3rd/cjson/example2.json";
200205
local text = util.file_load(path);
201206
LuaHelper.OnJsonCallFunc(text, this.OnJsonCall);
202207
end
203208

204209
--cjson callback--
205-
function GameManager.OnJsonCall(data)
210+
function Game.OnJsonCall(data)
206211
local obj = json.decode(data);
207212
print(obj['menu']['id']);
208213
end
209214

210215
--销毁--
211-
function GameManager.OnDestroy()
216+
function Game.OnDestroy()
212217
--logWarn('OnDestroy--->>>');
213218
end
File renamed without changes.

Assets/LuaFramework/Scripts/Common/LuaBehaviour.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,24 @@
66

77
namespace LuaFramework {
88
public class LuaBehaviour : Base {
9-
protected static bool initialize = false;
10-
119
private string data = null;
1210
private AssetBundle bundle = null;
1311
private Dictionary<string, LuaFunction> buttons = new Dictionary<string, LuaFunction>();
1412

1513
protected void Awake() {
16-
CallMethod("Awake", gameObject);
14+
Util.CallMethod(name, "Awake", gameObject);
1715
}
1816

1917
protected void Start() {
20-
CallMethod("Start");
18+
Util.CallMethod(name, "Start");
2119
}
2220

2321
protected void OnClick() {
24-
CallMethod("OnClick");
22+
Util.CallMethod(name, "OnClick");
2523
}
2624

2725
protected void OnClickEvent(GameObject go) {
28-
CallMethod("OnClick", go);
26+
Util.CallMethod(name, "OnClick", go);
2927
}
3028

3129
/// <summary>
@@ -83,14 +81,6 @@ public void ClearClick() {
8381
buttons.Clear();
8482
}
8583

86-
/// <summary>
87-
/// 执行Lua方法
88-
/// </summary>
89-
protected object[] CallMethod(string func, params object[] args) {
90-
if (!initialize) return null;
91-
return Util.CallMethod(name, func, args);
92-
}
93-
9484
//-----------------------------------------------------------------
9585
protected void OnDestroy() {
9686
if (bundle) {

Assets/LuaFramework/Scripts/ConstDefine/AppConst.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace LuaFramework {
77
public class AppConst {
8-
public const bool DebugMode = false; //调试模式-用于内部测试
8+
public const bool DebugMode = true; //调试模式-用于内部测试
99

1010
/// <summary>
1111
/// 如果想删掉框架自带的例子,那这个例子模式必须要
@@ -20,7 +20,7 @@ public class AppConst {
2020
/// </summary>
2121
public const bool UpdateMode = false; //更新模式-默认关闭
2222
public const bool LuaByteMode = false; //Lua字节码模式-默认关闭
23-
public const bool LuaBundleMode = true; //Lua代码AssetBundle模式-默认关闭
23+
public const bool LuaBundleMode = false; //Lua代码AssetBundle模式-默认关闭
2424

2525
public const bool UsePbc = true; //PBC
2626
public const bool UseLpeg = true; //lpeg

Assets/LuaFramework/Scripts/Controller/Command/StartUpCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ public override void Execute(IMessage message) {
2424
AppFacade.Instance.AddManager<ResourceManager>(ManagerName.Resource);
2525
AppFacade.Instance.AddManager<ThreadManager>(ManagerName.Thread);
2626
AppFacade.Instance.AddManager<GameManager>(ManagerName.Game);
27-
28-
Debug.Log("LuaFramework StartUp-------->>>>>");
2927
}
3028
}

Assets/LuaFramework/Scripts/Manager/GameManager.cs

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
using System.Reflection;
77
using System.IO;
88

9-
#if UNITY_EDITOR
10-
using UnityEditor;
11-
#endif
12-
139
namespace LuaFramework {
14-
public class GameManager : LuaBehaviour {
10+
public class GameManager : Manager {
11+
protected static bool initialize = false;
1512
private List<string> downloadFiles = new List<string>();
1613

1714
/// <summary>
@@ -232,51 +229,22 @@ void OnThreadCompleted(NotiData data) {
232229
}
233230
}
234231

235-
/// <summary>
236-
/// 资源初始化结束
237-
/// </summary>
238-
public void OnResourceInited() {
239-
LuaManager.InitStart();
240-
LuaManager.DoFile("Logic/Network"); //加载网络
241-
LuaManager.DoFile("Logic/GameManager"); //加载游戏
242-
initialize = true; //初始化完
243-
244-
NetManager.OnInit(); //初始化网络
245-
246-
object[] panels = CallMethod("LuaPanels");
247-
//---------------------Lua面板---------------------------
248-
foreach (object o in panels) {
249-
string name = o.ToString().Trim();
250-
if (string.IsNullOrEmpty(name)) continue;
251-
252-
LuaManager.DoFile("View/" + name);
253-
Debug.LogWarning("LoadLua---->>>>" + name + ".lua");
254-
}
255-
//------------------------------------------------------------
256-
CallMethod("OnInitOK"); //初始化完成
257-
}
258-
259232
void OnUpdateFailed(string file) {
260233
string message = "更新失败!>" + file;
261234
facade.SendMessageCommand(NotiConst.UPDATE_MESSAGE, message);
262235
}
263236

264-
void Update() {
265-
if (LuaManager != null && initialize) {
266-
//LuaManager.Update();
267-
}
268-
}
269-
270-
void LateUpdate() {
271-
if (LuaManager != null && initialize) {
272-
//LuaManager.LateUpate();
273-
}
274-
}
237+
/// <summary>
238+
/// 资源初始化结束
239+
/// </summary>
240+
public void OnResourceInited() {
241+
LuaManager.InitStart();
242+
LuaManager.DoFile("Logic/Game"); //加载游戏
243+
LuaManager.DoFile("Logic/Network"); //加载网络
244+
NetManager.OnInit(); //初始化网络
275245

276-
void FixedUpdate() {
277-
if (LuaManager != null && initialize) {
278-
//LuaManager.FixedUpdate();
279-
}
246+
Util.CallMethod(name, "OnInitOK"); //初始化完成
247+
initialize = true; //初始化完
280248
}
281249

282250
/// <summary>

ReadMe.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
tolua#地址: https://github.com/topameng/tolua
1515
tolua#底层库 https://github.com/topameng/tolua_runtime
1616

17+
//-------------2016-01-31-------------
18+
(1)简化框架加载流程。
19+
1720
//-------------2016-01-30-------------
1821
(1)添加luajit2.1版本在ios下的32、64位编码器。
1922
(2)修复加载Lua文件BUG。

0 commit comments

Comments
 (0)