function m:AddListener() GameEntry.LuaEvent:Subscribe(UnityGameFramework.Runtime.ShowEntitySuccessEventArgs.EventId, self.OnShowSpineSuccessDelegate) end
function m:RemoveListener() GameEntry.LuaEvent:Unsubscribe(UnityGameFramework.Runtime.ShowEntitySuccessEventArgs.EventId, self.OnShowSpineSuccessDelegate) end
---界面轮询。 ---@param elapseSeconds number ---@param realElapseSeconds number ---@return void function m:OnUpdate(elapseSeconds, realElapseSeconds) if not self.IsCreateRole then return end if self.RoleData == nil then return end if self.IsCatch then return end if not self.IsMoving then if PlayerModule.GetServerTime() > self.NextMovieTimer then self:StartMove() end return end local direction = self.NextPos - self.View.transform.localPosition if direction.magnitude > self.RoleData.roleRareSpeed then self.View.transform:Translate(direction.normalized * self.RoleData.roleRareSpeed * UnityEngine.Time.deltaTime) self:ChangeRoleOrderZ() else self:StopMove() end end
function m:ChangeOrder() if self.RoleObj then local canvas = self.View:GetComponentInParent(typeof(UnityEngine.Canvas)) setGameObjectLayers(self.RoleObj.transform, "UI") local renderers = self.RoleObj:GetComponentsInChildren(typeof(UnityEngine.Renderer)) for i = 0, renderers.Length - 1 do renderers[i].sortingLayerID = LuaCodeInterface.SortingLayerNameToID("Default") renderers[i].sortingOrder = canvas.sortingOrder + 1 end end end
function m:OnShowSpineSuccess(sender, args) if self.EntityId == args.Entity.Id then self.RoleObj = args.Entity.gameObject self.Animation = args.Entity.gameObject:GetComponentInChildren(typeof(Spine.Unity.SkeletonAnimation)) self.Animation.state:SetAnimation(0,"idle", true) self:StartMove() self.IsCreateRole = true self:ChangeOrder() end end
---获取一个随机位置 坐标Z控制小人显示层级 function m:GetRandomPos() local rx = math.random(-self.View.transform.parent.rect.w/2,self.View.transform.parent.rect.w/2) local ry = math.random(-self.View.transform.parent.rect.h/2,self.View.transform.parent.rect.h/2) return Vector3.New(rx,ry,0) end
---开始移动 function m:StartMove() self.IsMoving = true self.NextPos = self:GetRandomPos() if self.Animation then self.Animation.state:SetEmptyAnimation(0, 0) self.Animation.state:SetAnimation(0, "walk", true) end self:RefreshWalkFaceTo() end
---移动到目标位置停止移动 function m:StopMove() self.IsMoving = false self.View.transform.localPosition = self.NextPos self.NextMovieTimer = math.random(0,4) + PlayerModule.GetServerTime() if self.Animation then self.Animation.state:SetAnimation(0,"idle", true) end end
---播放抓住状态 function m:CatchState() self.IsMoving = false self.IsCatch = true if self.Animation then self.Animation.AnimationName = nil self.Animation.state:SetEmptyAnimation(0, 0) self.Animation.state:SetAnimation(0,"drag", true) end end
---刷新移动朝向 function m:RefreshWalkFaceTo() local checkRet = self.NextPos.x - self.View.transform.localPosition.x local localScale = self.View.transform.localScale if checkRet > 0 then localScale.x = -math.abs(localScale.x) else localScale.x = math.abs(localScale.x) end self.View.transform.localScale = localScale end
---@param roleData AmusementParkDollMachineRoleData function m:SetData(roleData) self.RoleData = roleData self.IsCreateRole = false self.IsCatch = false for i = 1, 4 do self["Quality"..i]:SetActive(self.RoleData.roleRare == i) end self.View.name = self.RoleData.cid local pos = self:GetRandomPos() self.View.transform.localPosition = pos self:ChangeRoleOrderZ() self.NextPos = self:GetRandomPos() self:ShowSpine() end
---改变小人移动Z值(移动是层级关系) function m:ChangeRoleOrderZ() local pos = self.View.transform.localPosition ---设置小人移动的Z值 self.OrderZ.transform.localPosition = Vector3.New(0,0,(pos.y + 150)/100) end
function m:ShowSpine() self:HideEntity() self.EntityId = GameEntry.Entity:GenerateEntityID() GameEntry.Entity:ShowUIElement(self.EntityId, self.RoleData:GetCfgData().PlayerSpine, 0, self.SpineRoot.transform, Vector3.zero) end
function m:HideEntity() if self.EntityId ~= 0 then GameEntry.Entity:HideEntity(self.EntityId) self.EntityId = 0 end end
function m:Dispose() AssetUtil.UnloadAsset(self) self:RemoveListener() self:HideEntity()
LuaCodeInterface.ClearOutlet(self.View, self) UnityEngine.Object.Destroy(self.View) self.View = nil end
---界面轮询。 ---@param elapseSeconds number ---@param realElapseSeconds number ---@return void function m:OnUpdate(elapseSeconds, realElapseSeconds) self.View.transform:Translate(Vector3.New(self.Speed * UnityEngine.Time.deltaTime * -1, 0, 0)) end
---@param speed number function m:SetData(speed) self.Speed = speed end
function m:Dispose() AssetUtil.UnloadAsset(self) self:RemoveListener()
LuaCodeInterface.ClearOutlet(self.View, self) UnityEngine.Object.Destroy(self.View) self.View = nil end
---@class AmusementParkOneConnectBlockData local m = { ---@type number Index = 0, ---@type number X = 0, ---@type number Y = 0, ---@type number 0 未连接,1 已连接 State = 0, ---@type boolean 最新连通 IsFirst = false, }
function m.New(index,x,y) local o = Clone(m) o:Init(index,x,y) return o end
function m:Init(index,x,y) self.Index = index self.X = tonumber(x) self.Y = tonumber(y) end
self.StartPos = self.ImgDrag.transform.position self.ImgDrag:GetComponent("UIDrag").onBeginDrag = function(eventData) self:OnBeginDrag(eventData) end self.ImgDrag:GetComponent("UIDrag").onDrag = function(pointerEventData) self:OnDrag(pointerEventData) end self.ImgDrag:GetComponent("UIDrag").onReachTargetSuccess = function(eventData) self:OnDragSuccess(eventData) end self.ImgDrag:GetComponent("UIDrag").onReachTargetFailure = function(eventData) self:OnFailure(eventData) end
self:AddListener() end
function m:AddListener() self.View:GetComponent("Button").onClick:AddListener(self.DelegateBtnSelf) end
function m:RemoveListener() self.View:GetComponent("Button").onClick:RemoveListener(self.DelegateBtnSelf) end
function m:OnClickBtnSelf() if self.OnBeginDragCallBack then self.OnBeginDragCallBack(self) end end
function m:OnBeginDrag() if self.OnBeginDragCallBack then self.OnBeginDragCallBack(self) end end
function m:OnDrag(eventData) if self.OnDragCallBack then self.OnDragCallBack(self) end end
function m:OnDragSuccess(eventData) self.ImgDrag.transform.position = self.StartPos end
function m:OnFailure(eventData) self.ImgDrag.transform.position = self.StartPos end
function m:UpdateView() self.ImgDefault:SetActive(self.BlockData.State == 0) self.ImgCheck:SetActive(self.BlockData.State == 1) self.ImgTag:SetActive(self.BlockData.IsFirst) end
---@param blockData AmusementParkOneConnectBlockData function m:SetData(blockData) self.BlockData = blockData self.View.name = self.BlockData.Index self:UpdateView() end
function m:Dispose() AssetUtil.UnloadAsset(self) self:RemoveListener() self.OnBeginDragCallBack = nil self.OnDragCallBack = nil
LuaCodeInterface.ClearOutlet(self.View, self) UnityEngine.Object.Destroy(self.View) self.View = nil end