Login = {}
-- 单例类
local this = Login
function Login:GetInstance()
return this
end
function initAssets()
print("initAssets ...")
-- 加载资源
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","Fonts",this.loadFontsCB)
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","NewLogin",Login.loadNewLoginCB)
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","Waiting",Login.loadWaitingCB)
end
-- 资源加载两种写法:
-- 1.一个资源加载完毕,通知下一资源开始加载,这种方式加载时间会累积,等待时间比较长
-- 2.同时加载,当所有资源包和依赖项加载完毕之后,就可以加载对应的资源,
-- 方式二
local progress1 = 0
Login.loadFontsCB = function(name,progress)
if progress >= 1 then
progress1 = progress;
this.loadComplete()
end
end
local progress2 = 0
Login.loadNewLoginCB = function(name,progress)
if progress >= 1 then
progress2 = progress;
this.loadComplete();
end
end
local progress3 = 0
Login.loadWaitingCB = function(name,progress)
if progress >= 1 then
progress3 = progress;
this.loadComplete();
end
end
Login.loadComplete = function()
if progress1 >= 1 and progress2 >= 1 and progress3 >= 1 then
-- 登录界面
local loginPanelObj = CS.AssetBundleManager.Instance:LoadAsset("Login","NewLogin","NewLogin2Panel");
local canvas = CS.UnityEngine.GameObject.Find("Canvas").transform
-- 实例化登录界面
local loginPanel = CS.UnityEngine.GameObject.Instantiate(loginPanelObj,canvas)
loginPanel.transform.localPosition = CS.UnityEngine.Vector3.zero
-- 添加login.cs脚本
loginPanel:AddComponent(typeof(CS.Login))
loginPanel:AddComponent(typeof(CS.LuaInjection)) --挂载LuaInjection脚本到游戏物体上
print(self,self.name)
--print(loginBtn,loginBtn.name)
--local loginBtn = CS.FindUtil.FindChild("LoginBtn",loginPanel.transform);
--loginBtn:GetComponent(typeof(CS.UnityEngine.UI.Button)).onClick:AddListener(Login.LoadStart)
-- loginBtn:GetComponent("Button") 获取组件
--loginBtn:GetComponent("Button").onClick:AddListener(Login.LoadStart)
LoginBtn:GetComponent("Button").onClick:AddListener(Login.LoadStart)
end
end
Login.LoadStart = function()
print('点击登录按钮')
local WaitingPanel = CS.AssetBundleManager.Instance:LoadAsset("Login","Waiting","WaitingPanel");
local canvas = CS.UnityEngine.GameObject.Find("Canvas").transform
local waiting = CS.UnityEngine.GameObject.Instantiate(WaitingPanel,canvas)
waiting.transform.localPosition = CS.UnityEngine.Vector3.zero
waiting:SetActive(true)
end
--[[
点击注册到注册界面
注册:
登录成功 --> 开始界面
--]]
--方式一
--[[
--资源加载完毕的回调
--name:AB包的名字 ,progress:加载的进度
Login.loadFontsCB = function(name,progress)
if progress >= 1 then
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","NewLogin",Login.loadNewLoginCB)
end
end
Login.loadNewLoginCB = function(name,progress)
--加载登录界面
end
Login.loadWaitingCB = function(name,progress)
end
--]]
-- 单例类
local this = Login
function Login:GetInstance()
return this
end
function initAssets()
print("initAssets ...")
-- 加载资源
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","Fonts",this.loadFontsCB)
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","NewLogin",Login.loadNewLoginCB)
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","Waiting",Login.loadWaitingCB)
end
-- 资源加载两种写法:
-- 1.一个资源加载完毕,通知下一资源开始加载,这种方式加载时间会累积,等待时间比较长
-- 2.同时加载,当所有资源包和依赖项加载完毕之后,就可以加载对应的资源,
-- 方式二
local progress1 = 0
Login.loadFontsCB = function(name,progress)
if progress >= 1 then
progress1 = progress;
this.loadComplete()
end
end
local progress2 = 0
Login.loadNewLoginCB = function(name,progress)
if progress >= 1 then
progress2 = progress;
this.loadComplete();
end
end
local progress3 = 0
Login.loadWaitingCB = function(name,progress)
if progress >= 1 then
progress3 = progress;
this.loadComplete();
end
end
Login.loadComplete = function()
if progress1 >= 1 and progress2 >= 1 and progress3 >= 1 then
-- 登录界面
local loginPanelObj = CS.AssetBundleManager.Instance:LoadAsset("Login","NewLogin","NewLogin2Panel");
local canvas = CS.UnityEngine.GameObject.Find("Canvas").transform
-- 实例化登录界面
local loginPanel = CS.UnityEngine.GameObject.Instantiate(loginPanelObj,canvas)
loginPanel.transform.localPosition = CS.UnityEngine.Vector3.zero
-- 添加login.cs脚本
loginPanel:AddComponent(typeof(CS.Login))
loginPanel:AddComponent(typeof(CS.LuaInjection)) --挂载LuaInjection脚本到游戏物体上
print(self,self.name)
--print(loginBtn,loginBtn.name)
--local loginBtn = CS.FindUtil.FindChild("LoginBtn",loginPanel.transform);
--loginBtn:GetComponent(typeof(CS.UnityEngine.UI.Button)).onClick:AddListener(Login.LoadStart)
-- loginBtn:GetComponent("Button") 获取组件
--loginBtn:GetComponent("Button").onClick:AddListener(Login.LoadStart)
LoginBtn:GetComponent("Button").onClick:AddListener(Login.LoadStart)
end
end
Login.LoadStart = function()
print('点击登录按钮')
local WaitingPanel = CS.AssetBundleManager.Instance:LoadAsset("Login","Waiting","WaitingPanel");
local canvas = CS.UnityEngine.GameObject.Find("Canvas").transform
local waiting = CS.UnityEngine.GameObject.Instantiate(WaitingPanel,canvas)
waiting.transform.localPosition = CS.UnityEngine.Vector3.zero
waiting:SetActive(true)
end
--[[
点击注册到注册界面
注册:
登录成功 --> 开始界面
--]]
--方式一
--[[
--资源加载完毕的回调
--name:AB包的名字 ,progress:加载的进度
Login.loadFontsCB = function(name,progress)
if progress >= 1 then
CS.AssetBundleManager.Instance:LoadAssetBundle("Login","NewLogin",Login.loadNewLoginCB)
end
end
Login.loadNewLoginCB = function(name,progress)
--加载登录界面
end
Login.loadWaitingCB = function(name,progress)
end
--]]