推薦閱讀:
做某件事的開心之處大概就來源於成就感吧,能帶來成就感的事大家是都願意去做的
———來自小白的裝B
好久沒寫文章了,不是代表我懶了,只是我一直都這麼懶的。哈哈哈,開個玩笑,文章雖沒有,但是知識還是學到了的。由於豆渣佔滿了腦子空間,每次知識只能拿小本本記錄下來,等到知識積累到一定程度了,參透了其中的奧妙,就將它同大家分享出來。
1.能不使用盡量不用全局廣播:Event.Brocast()
2.setdata()會調用腳本的start()和commite()方法
因此,使用了setdata()的地方無須再調用start()或commit()方法
3.分頁標籤點擊事件:當點擊的是當前頁籤直接返回
if pageIdx==clickIdx then
return
end
4.方法傳入參數,能table的就table,不要單個變量傳。
table方法:
args={sid=1001,num=10}
function(args)
單變量傳入:
local sid=1001
local num=10
function(sid,num)
5.配置表數據使用多個字段,先把該數據取出再.字段名
不友好的寫法:
local reward=config[idx].reward
local num=config[idx].num
優化後寫法:
local info=config[idx]
local reward=info.reward
local num=info.num
6.pop彈窗:以下兩種彈窗有遮罩的,不用加Image。
popupmanager.openinsubview(this.gameObject)
view.ispopup = true
7.pop彈窗不要動畫打開關閉:
popupmanager.openinsubview(go, true, true, 0)
popupmanager.close(go, 0)
8.Rect Transform設置上下拉伸時,修改距離頂部,底部高度,長寬的方法:
local rect = this.gameObject:GetComponent("RectTransform")
rect.offsetMax = Vector2.New(0, 0);--頂部
rect.offsetMin = Vector2.New(0, 0);--底部
rect.sizeDelta = Vector2.New(720, 0);--寬高
含義如下:
rect.sizeDelta的x是width
rect.sizeDelta的y是height
rect.offsetMin 是vector2(left, bottom);
rect.offsetMax 是vector2(right, top);
其他屬性修改方法:
rect.anchorMin = Vector2.New(0.5, 0.5)
rect.anchorMax = Vector2.New(0.5, 0.5)
rect.pivot = Vector2.New(0.5, 0.5)
rect.localScale = Vector3.New(0.8, 0.8)
9.滑動列表中使用了灰色材質球的,遮罩使用3Dmask
10.spine動畫使用:Unity 使用 Spine 動畫
11.粒子特效層級問題:修改層級時需要修改粒子特效裏所有能修改的層級,比低一級的大一層級即可
12.粒子特效使用方法:
Util.DestroyAllChild(ui.upgradeEff)
local UI_jueseshengji = Util.Instance(utils.getuiseffect("UI_jueseshengji"))
Util.SetParent(UI_jueseshengji, ui.upgradeEff)
13.隱藏lable描邊等
local outline = ui.uplvtxt.gameObject:GetComponent("Outline")
local shadow = ui.uplvtxt.gameObject:GetComponent("Shadow")
outline.effectColor = "#FFFFFF"
shadow.effectColor = "#FFFFFF"
14.滑動列表滑動到指定下標idx
ui.towerList.totalCount = towerTotal
ui.towerList:RefillCells(idx)
15.unity設置某物體的父物體
obj.transform:SetParent(go.transform)
16.引用技術