|
|
- GuideSpiritItem = GuideSpiritItem or BaseClass(BaseItem)
- function GuideSpiritItem:__init()
- self.base_file = "guide"
- self.layout_file = "GuideSpiritItem"
- self.layer_name = "Main"
- self.destroy_imm = true
- self.use_background = true
-
- -- self.use_local_view = true
- self:Load()
- end
-
- function GuideSpiritItem:Load_callback()
- self.ModelBtn
- = GetChildGameObjects (self.transform,
- {
- "ModelBtn"
- })
- self.con,self.SpiritCon
- = GetChildTransforms(self.transform,
- {
- "Con","SpiritCon",
- })
- self:InitEvent()
-
- local function load_callback()
- self:SetSpiritModel()
- end
- local data = {
- clothe_res_id = GuideModel.SpiritBgId,
- type = SceneBaseType.StarSoul,
- layer_name = self.layer_name,
- rotate = Vector3(-15,0,0),
- action_name_list = {"idle"},
- can_rotate = false,
- scale = 50,
- position = Vector3(0, 12, 0),
- callBack = load_callback,
- layout_file = self.layout_file
- }
- lua_resM:SetRoleModel(self, self.con,data)
- end
-
- function GuideSpiritItem:SetSpiritModel()
- local function load_callback()
- if self.curr_Model == nil then
- self.curr_Model = lua_resM:GetPartModel(self, self.con)
- end
- if self.curr_Model then
- self.spirit_root = self.curr_Model.transform:Find("Bone001")
- if self.spirit_root then
- local function load_finish(go)
- if go then
- self:SetUILayer(go.transform)
- go.transform.localPosition = Vector3(0,0,0)
- go.transform.localScale = Vector3.one
- go.transform.localRotation = Quaternion.Euler(Vector3.zero)
- end
- end
- local function load_finish_func(go)
- if go then
- self.BGEffect = go.transform
- self:SetUILayer(go.transform)
- go.transform.localPosition = Vector3(0,0,0)
- go.transform.localScale = Vector3.one
- go.transform.localRotation = Quaternion.Euler(Vector3.zero)
- end
- end
- self:AddUIEffect("501001_bone001fx",self.spirit_root.transform,self.layer_name, nil, -1, false, -1, nil, nil, load_finish, nil, nil, true)
- self:AddUIEffect("ui_partnershow",self.curr_Model.transform,self.layer_name, nil, -1, false, -1, nil, nil, load_finish_func, nil, nil, true)
- self.SpiritCon:SetParent(self.spirit_root.transform)
- end
- end
- end
- local data = {
- clothe_res_id = GuideModel.SpiritId,
- type = SceneBaseType.StarSoul,
- layer_name = self.layer_name,
- rotate = Vector3(0,180,0),
- action_name_list = {"idle2"},
- can_rotate = false,
- scale = 1,
- position = Vector3(2.1, -144.2, 0),
- callBack = load_callback,
- layout_file = self.layout_file
- }
- lua_resM:SetRoleModel(self,self.SpiritCon.transform,data)
- end
-
- function GuideSpiritItem:InitEvent()
- local function clickFunc(target)
- if target == self.ModelBtn then
- GlobalEventSystem:Fire(EventName.OPEN_GUIDE_SPIRIT_VIEW)
- end
- end
- AddClickEvent(self.ModelBtn,clickFunc)
-
- local function onChangeMainCanvasVisible(ref,visible)
- if visible then
- local spirt_model = lua_resM:GetPartModel(self, self.SpiritCon)
- if spirt_model and spirt_model.gameObject then
- local animator = spirt_model.gameObject:GetComponent("Animator")
- if animator then
- if not self.timer_out then
- local onDelay = function( )
- if self.timer_out then
- GlobalTimerQuest:CancelQuest(self.timer_out)
- self.timer_out = nil
- end
- if animator then
- animator:Update(0)
- animator:CrossFade("idle2",0.1, 0)
- end
- end
- self.timer_out = setTimeout(onDelay, 0.1)
- end
- end
- end
- end
- end
- self.change_canvas_id = LuaViewManager:getInstance():Bind(LuaViewManager.CHANGE_MAIN_CANVAS_VISIBLE,onChangeMainCanvasVisible)
- end
-
- function GuideSpiritItem:__delete()
- if self.timer_out then
- TimerQuest.CancelQuest(GlobalTimerQuest, self.timer_out)
- self.timer_out = false
- end
- if self.event_id then
- self.model:UnBind(self.event_id)
- end
- if self.change_canvas_id then
- LuaViewManager:getInstance():UnBind(self.change_canvas_id)
- self.change_canvas_id = nil
- end
- end
|