Ulua学习笔记
来源:互联网 发布:阿里云免费套餐 编辑:程序博客网 时间:2024/06/06 09:40
require "Common/define"require "3rd/pblua/login_pb"require "3rd/pbc/protobuf"require "View/ChangeClothesPanel"luanet.load_assembly('UnityEngine');Application = luanet.import_type('UnityEngine.Application') ; ChangeClothesCtrl = {};local this = ChangeClothesCtrl;local panel;local luaBehaviour;local transform;local gameObject;local pressImageTable = {};local objectPool = {};--构建函数--function ChangeClothesCtrl.New()warn("ChangeClothesCtrl.New--->>");return this;endfunction ChangeClothesCtrl.Awake()warn("ChangeClothesCtrl.Awake--->>");PanelManager:CreatePanel('ChangeClothes', this.OnCreate);end--启动事件--function ChangeClothesCtrl.OnCreate(obj)gameObject = obj; this.gameObject = gameObject;transform = obj.transform;--panel = transform:GetComponent('UIPanel');luaBehaviour = transform:GetComponent('LuaBehaviour');warn("Start lua--->>"..gameObject.name);luaBehaviour:AddClick(ChangeClothesPanel.btnSureCreate, this.SureCreate); luaBehaviour:AddClick(ChangeClothesPanel.btnButton_01, this.btnButton_01); luaBehaviour:AddClick(ChangeClothesPanel.btnButton_02, this.btnButton_02); luaBehaviour:AddClick(ChangeClothesPanel.btnButton_03, this.btnButton_03); luaBehaviour:AddClick(ChangeClothesPanel.btnButton_04, this.btnButton_04); luaBehaviour:AddClick(ChangeClothesPanel.btnTop_01, this.btnTopButton_01); luaBehaviour:AddClick(ChangeClothesPanel.btnTop_02, this.btnTopButton_02); luaBehaviour:AddClick(ChangeClothesPanel.btnTop_03, this.btnTopButton_03); luaBehaviour:AddClick(ChangeClothesPanel.btnRotate_01, this.r); luaBehaviour:AddClick(ChangeClothesPanel.btnBack, this.back); pressImageTable = {ChangeClothesPanel.btnPressImg_01,ChangeClothesPanel.btnPressImg_02,ChangeClothesPanel.btnPressImg_03,ChangeClothesPanel.btnPressImg_04,ChangeClothesPanel.btnTopPressImg_01,ChangeClothesPanel.btnTopPressImg_02,ChangeClothesPanel.btnTopPressImg_03}; ResManager:LoadAsset('ClothesItem', 'ClothesItem', this.InitPanel); gameObject:SetActive(false);end--初始化面板--function ChangeClothesCtrl.InitPanel(prefab)local count = 12; local parent = ChangeClothesPanel.gridParent; this.SetGameObjectPool(count,prefab,parent,Item); local rtTrans = parent:GetComponent("RectTransform");local rowNum = count / 3;if count % 3 > 0 thenrowNum = toInt(rowNum + 1);endlocal size = rtTrans.sizeDelta; --size.y = rowNum * 100 + (rowNum - 1) * 50;rtTrans.sizeDelta = size;local position = rtTrans.localPosition;position.y = -(size.y / 2);rtTrans.localPosition = position;end--单击事件--function ChangeClothesCtrl.SureCreate(go) warn("SureCreate---->>>");endfunction ChangeClothesCtrl.btnButton_01(go) warn("btnButton_01---->>>"); SetPressPicActive(); ChangeClothesPanel.btnPressImg_01:SetActive(true); ChangeClothesPanel.btnTop_01:SetActive(true); ChangeClothesPanel.btnTop_02:SetActive(true); ChangeClothesPanel.btnTop_03:SetActive(true); endfunction ChangeClothesCtrl.btnButton_02(go) warn("btnButton_02---->>>") this.Reflash(10); SetPressPicActive(); ChangeClothesPanel.btnPressImg_02:SetActive(true); ChangeClothesPanel.btnTop_01:SetActive(false); ChangeClothesPanel.btnTop_02:SetActive(false); ChangeClothesPanel.btnTop_03:SetActive(false);endfunction ChangeClothesCtrl.btnButton_03(go) warn("btnButton_03---->>>"); this.Reflash(12); SetPressPicActive(); ChangeClothesPanel.btnPressImg_03:SetActive(true); ChangeClothesPanel.btnTop_01:SetActive(false); ChangeClothesPanel.btnTop_02:SetActive(false); ChangeClothesPanel.btnTop_03:SetActive(false);endfunction ChangeClothesCtrl.btnButton_04(go) warn("btnButton_04---->>>"); this.Reflash(2); SetPressPicActive(); ChangeClothesPanel.btnPressImg_04:SetActive(true); ChangeClothesPanel.btnTop_01:SetActive(false); ChangeClothesPanel.btnTop_02:SetActive(false); ChangeClothesPanel.btnTop_03:SetActive(false);endfunction ChangeClothesCtrl.btnTopButton_01() warn("btnTopButton_01---->>>"); this.Reflash(1); SetPressPicActive(); ChangeClothesPanel.btnPressImg_01:SetActive(true); ChangeClothesPanel.btnTopPressImg_01:SetActive(true);endfunction ChangeClothesCtrl.btnTopButton_02(go) warn("btnTopButton_02---->>>"); this.Reflash(4); SetPressPicActive(); ChangeClothesPanel.btnPressImg_01:SetActive(true); ChangeClothesPanel.btnTopPressImg_02:SetActive(true);endfunction ChangeClothesCtrl.btnTopButton_03(go) this.Reflash(6); warn("btnTopButton_03---->>>"); SetPressPicActive(); ChangeClothesPanel.btnPressImg_01:SetActive(true); ChangeClothesPanel.btnTopPressImg_03:SetActive(true);end--单击事件--function ChangeClothesCtrl.OnClick(go) warn("OnClick---->>>"..go.name);end--关闭事件--function ChangeClothesCtrl.Close()PanelManager:ClosePanel(CtrlName.Title);endfunction SetPressPicActive() warn("Here "..#pressImageTable); for i=1,#pressImageTable do pressImageTable[i]:SetActive(false); endendfunction ChangeClothesCtrl.r(go) local preson = ChangeClothesPanel.nanZhu; RotateCharacter(preson);end--rotate gameObjectfunction RotateCharacter(go) local targetObjet = go; targetObjet.transform.Rotate(Vector3.right * 1);endfunction ChangeClothesCtrl.SetGameObjectPool(size,obj,objParent,itemTable) --池大小 池对象 父物体 目标对象 local PoolSize = size; local PoolObj = obj; local PoolobjParent = objParent; local PoolitemTable = itemTable; local Length; if #itemTable%3==0 then Length = #itemTable/3; else Length = #itemTable/3+1; end local v2 = ChangeClothesPanel.grid:GetComponent('RectTransform').sizeDelta; local NewPos = Vector2:New(0,0); NewPos.x = 800; NewPos.y = 250*Length; warn("----------"..NewPos.y); ChangeClothesPanel.grid:GetComponent('RectTransform').sizeDelta = NewPos; if PoolSize<#itemTable then PoolSize = #PoolitemTable; end for i = 1, PoolSize do local go = newobject(PoolObj); go.name = 'Item'..tostring(i); go.transform:SetParent(PoolobjParent); go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; local label = go.transform:FindChild('Text'); label:GetComponent('Text').text = tostring(i); local Itemimage = go.transform:FindChild('Image').gameObject; if i<#PoolitemTable then--设置道具的属性 LuaHelper.ResourceLoad("Icon/"..Item[i].TextureName,Itemimage); luaBehaviour:AddClick(go, this.OnClick);--Add Method GameObjectUserData.setUserData(go.transform,i); else go:SetActive(false); end objectPool[i] = go; endendfunction ChangeClothesCtrl.Reflash(ItemNum) local Poolsize = #objectPool; if ItemNum>#objectPool then Poolsize = ItemNum; end warn("----------"..ItemNum); local Length; if ItemNum%3==0 then Length = ItemNum/3; else Length = ItemNum/3+1; end warn("----------"..Length); local v2 = ChangeClothesPanel.grid:GetComponent('RectTransform').sizeDelta; local NewPos = Vector2:New(0,0); NewPos.x = 800; NewPos.y = 250*Length; warn("----------"..NewPos.y); ChangeClothesPanel.grid:GetComponent('RectTransform').sizeDelta = NewPos; for i = 1,Poolsize do local go = objectPool[i]; if i<=ItemNum then--设置道具的属性 go:SetActive(true); go.name = 'Item'..tostring(i); local label = go.transform:FindChild('Text'); label:GetComponent('Text').text = tostring(i); local Itemimage = go.transform:FindChild('Image').gameObject; Itemimage:SetActive(true); LuaHelper.ResourceLoad("Icon/"..Item[i].TextureName,Itemimage); luaBehaviour:AddClick(go, this.OnClick);--Add Method GameObjectUserData.setUserData(go.transform,i); else GameObjectUserData.setUserData(go.transform,nil); go:SetActive(false); end objectPool[i] = go; endendfunction ChangeClothesCtrl.back() CtrlManager.SetPanel(gameObject,false); CtrlManager.SetPanel(SelectCharacterCtrl.gameObject,true);end
代码供给自己日后参考
0 0
- Ulua学习笔记
- ulua学习笔记1
- uLua热更新学习笔记
- ULUA 笔记
- 【ulua学习笔记】SimpleFramework使用步骤总结
- Unity3D 学习笔记4 —— UGUI+uLua游戏框架
- uLua+SimpleFramework常见问题的解答及学习笔记
- ulua使用笔记
- 学习ULua之委托
- uLua学习笔
- uLua
- ulua
- ulua
- ulua
- 【游戏客户端开发】Unity3D 学习笔记4 —— UGUI+uLua游戏框架
- unity3d热更新插件uLua学习整理
- unity3d热更新插件uLua学习整理
- unity3d热更新插件uLua学习整理
- LVM逻辑卷扩容
- linux压缩和解压
- 【PAT】1087. All Roads Lead to Rome (30)
- OC第五天:字典、集、数组排序
- 某大学医疗系统更改版
- Ulua学习笔记
- 单例
- 10.80386指令-Intel格式和AT&T格式的指令格式
- oracle常用SQL语句
- S2SH+ajax+json-------Struts.xml文件编写
- HDU 1025 最长递增子序列 DP+二分法
- 使用Storyboard进行界面跳转及传值
- Arduino的运行机制
- 11.数据传送指令MOV、XCHG效果