推薦閱讀:
打開SimpleFramework_UGUI項目,此時項目可能會報如下錯誤:
解決辦法:單擊 "Lua/Gen Lua Wrap Files"生成Wrap文件
選擇Assets\Examples\Scenes\login場景,雙擊運行,此時項目會報如下錯誤:
解決辦法:單擊 "Game/Build WindowsResuorces"打包資源,此時項目會報如下錯誤
解決辦法:下載網盤鏈接文件:報錯需替換的文件,替換項目目錄Assets\uLua\Source\LuaWrap中對應的文件。
運行項目,此時項目會報如下錯誤:
解決辦法:刪掉項目目錄Assets/StreamingAssets文件。單擊 “Game/Build WindowsResuorces”
此時,運行項目,將看到框架提供的案例界面,如下:
注意:上述錯誤爲必現錯誤,因此爲了方便我們可以打開項目依次執行如下操作,使得項目快速正確的運行
(1)單擊 \ “Lua/Clear LuaBinder File + Wrap Files” 清除緩存
(2) 單擊 "Lua/Gen Lua Wrap Files"生成Wrap文件
(3)下載網盤鏈接文件:報錯需替換的文件,替換項目目錄Assets\uLua\Source\LuaWrap中對應的文件。
(4)刪掉項目目錄Assets下的StreamingAssets文件。
(5)單擊 "Game/Build WindowsResuorces"打包資源。
(6)運行項目,出現案例,完工!
接下來簡單介紹一下框架的使用
爲了便於區分,在項目Assets下創建創建一個MyGame文件,用於存放接下來添加的資源預製場景等。由於是演示,這裏MyGame目錄裏面就不再細分了。
(1)打開一個新場景,創建一個空物體,命名爲:GlobalGenerator,同事添加GlobalGenerator腳本。
(2)爲Canvas添加Tag標籤:Canvas
打開PanelManager,修改代碼如下:
(3)創建startPanel,gamePanel面板保存爲預製,並設置AssetBundle:
注意名字的對應。例如:面板名字爲name+Panel,則AssetBundel名爲:name+.assetsbundle。
(4)使用sublime打開Assets\Lua文件夾,找到Lua/Logic/GameMananger文件打開,註釋所有代碼,接下來開始寫GameManager代碼
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時06分
--------------------------------------------------------------------------------
--
--使用了Common/define中的AppConst和NetManager字段,需引用--
require "Common/define"
--管理器--
GameManager = {};
local this = GameManager;
function GameManager.LuaScriptPanel()
--返回需要加載的場景面板名字,和(1)中的name對應--
return 'start', 'game';
end
--初始化完成,發送鏈接服務器信息--
function GameManager.OnInitOK()
AppConst.SocketPort = 2012;
AppConst.SocketAddress = "127.0.0.1";
NetManager:SendConnect();
end
(5)在Lua/View下創建startPanel.lua,gamePanel.lua文件,名字和(1)中對應。接下來寫startPanel面板:
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時11分
--------------------------------------------------------------------------------
--
startPanel={}
local this=startPanel
local transform
local gameObject
function startPanel.Awake(obj)
gameObject=obj
transform=obj.transform
this.InitPanel();
end
function startPanel.InitPanel()
--用於後面控制面板的顯示與隱藏--
this.bg=transform:FindChild("bg").gameObject
--獲取場景面板上的組件:開始按鈕--
this.startBtn=transform:FindChild("bg/startBtn").gameObject
end
同理,gamePanel.lua代碼如下;
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時17分
--------------------------------------------------------------------------------
--
gamePanel={}
local this=gamePanel
local transform
local gameObject
function gamePanel.Awake(obj)
gameObject=obj
transform=obj.transform
this.InitPanel();
end
function gamePanel.InitPanel()
this.returnBtn=transform:FindChild("bg/returnBtn").gameObject
end--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時11分
--------------------------------------------------------------------------------
--
gamePanel={}
local this=gamePanel
local transform
local gameObject
function gamePanel.Awake(obj)
gameObject=obj
transform=obj.transform
this.InitPanel();
end
function gamePanel.InitPanel()
this.bg=transform:FindChild("bg").gameObject
this.returnBtn=transform:FindChild("bg/returnBtn").gameObject
end
(6)在Lua/Controller下創建startCtrl.lua,gameCtrl.lua文件,名字和(1)中對應。接下來寫startCtrl中的代碼:
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時11分
--------------------------------------------------------------------------------
--
require "Common/define"
startCtrl = {};
local this = startCtrl;
local transform;
local gameObject;
local lua
--構建函數--
function startCtrl.New()
return this;
end
function startCtrl.Awake()
--創建面板的名字和(1)中name保持一致--
PanelManager:CreatePanel('start', this.OnCreate);
end
--啓動事件--
function startCtrl.OnCreate(obj)
gameObject = obj;
transform=obj.transform
lua = gameObject:GetComponent('LuaBehaviour');
--爲startPanel面板中的startBtn對象添加OnClickStart點擊事件--
lua:AddClick(startPanel.startBtn, this.OnClickStart);
end
--單擊事件--
function startCtrl.OnClickStart(go)
startPanel.bg:SetActive(false)
gamePanel.bg:SetActive(true)
end
--關閉事件--
function startCtrl.Close()
end
同理,gamePanel.lua代碼如下;
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時11分
--------------------------------------------------------------------------------
--
require "Common/define"
gameCtrl = {};
local this = gameCtrl
local transform;
local gameObject;
local lua
--構建函數--
function gameCtrl.New()
return this;
end
function gameCtrl.Awake()
PanelManager:CreatePanel('game', this.OnCreate)
end
--啓動事件--
function gameCtrl.OnCreate(obj)
gameObject = obj;
transform=obj.transform
lua = gameObject:GetComponent('LuaBehaviour')
lua:AddClick(gamePanel.returnBtn, this.OnClickReturn)
end
function gameCtrl.Show()
gamePanel.bg:SetActive(true)
end
function gameCtrl.Hide()
gamePanel.bg:SetActive(false)
startPanel.bg:SetActive(true)
end
--單擊事件--
function gameCtrl.OnClickReturn(go)
this.Hide();
end
--關閉事件--
function gameCtrl.Close()
end
(7)在GameManager.lua中添加代碼如下:
--
--------------------------------------------------------------------------------
-- @autor: shirln
-- @about:
-- CSDN:https://blog.csdn.net/shirln
-- QQGroup:704621321
-- @data: 2019年08月29日 11時30分
--------------------------------------------------------------------------------
--
--使用了Common/define中的AppConst和NetManager字段,需引用--
require "Common/define"
----------
--添加代碼
----------
require"Controller/startCtrl"
require"Controller/gameCtrl"
--管理器--
GameManager = {};
local this = GameManager;
function GameManager.LuaScriptPanel()
--返回需要加載的場景面板名字,和(1)中的name對應--
return 'start', 'game';
end
--初始化完成,發送鏈接服務器信息--
function GameManager.OnInitOK()
AppConst.SocketPort = 2012;
AppConst.SocketAddress = "127.0.0.1";
NetManager:SendConnect();
----------
--添加代碼
----------
startCtrl.Awake();
gameCtrl.Awake();
end
(8)至此,你剛剛的兩個面板通過按鈕點擊就可以實現切換顯示了。
接下來,給大家介紹一下如何打包
(1)查看本地電腦局域網ip(不會的可百度),例如ip:192.168.199.145
(2)使用vs打開項目目錄下的Server解決方案,修改Service/HttpServer腳本中的地址爲(1)中的ip地址:
(3)“重新生成”項目,打開目錄下Server\Server\bin\Debug,找到SuperSocket.SocketService.exe,右鍵管理員身份運行,輸入r,成功打開框架自帶服務器如下;
注意:如果下方報錯,多半與IP地址有關,請仔細合適IP地址。
(4)解壓Assets\Plugins\x86;如果是32位Unity編輯器,刪掉x86_64目錄,如果是64位編輯,刪除x86目錄即可。
(5)修改APPConst
打包到Android
會出現下列錯誤:
錯誤雖然看上去看多,但只需要小小的修改一個地方,如圖:
接下來就是開心打包中。。。
注意:打包完還需要Build對應平臺的資源,不然會報錯哦!
最後就是我們期待已久的熱更新了
(1)UI熱更新:更新UI後,需要Build對應平臺的資源,然後重啓遊戲進行熱更新
(2)代碼熱更新:只需要修改代碼,重啓遊戲即可進行熱更新