UIHandMaskView.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { GuideEvent } from "../../../data/const/EventConst";
  2. import { ViewZOrder } from "../../../data/const/ViewZOrder";
  3. import UEBase from "../../../frameWork/compment/UEBase";
  4. import EventMng from "../../../manager/EventMng";
  5. import { uiCommon } from "../../../utils/UICommon";
  6. const { ccclass, menu, property } = cc._decorator;
  7. @ccclass
  8. @menu("UI/persistNode/UIHandMaskView")
  9. export default class UIHandMaskView extends UEBase {
  10. static readonly BundleKey: string = "guide";
  11. static readonly PrefabUrl: string = "UIHandMaskView";
  12. static readonly CLS: string = "UIHandMaskView";
  13. @property(cc.Node) mask: cc.Node = null
  14. @property(cc.SpriteFrame)
  15. taskzhezhao: cc.SpriteFrame = null
  16. @property(cc.SpriteFrame)
  17. imgMask: cc.SpriteFrame = null
  18. private targetNodeScale: number = 1 //目标节点真实sacle
  19. protected onEnable() {
  20. // cc.game.addPersistRootNode(this.node);
  21. this.node.zIndex = ViewZOrder.MASK;
  22. EventMng.on(GuideEvent.HANDMASK_SHOW, this.ShowHandMask, this)
  23. }
  24. protected onDisable() {
  25. }
  26. ShowHandMask(targetNode: cc.Node, maskName: string) {
  27. if (!targetNode) {
  28. this.mask.active = false;
  29. return;
  30. }
  31. this.mask.active = true;
  32. let targetWolrdPos = uiCommon.getWorldPosCenter(targetNode)
  33. this.targetNodeScale = targetNode.scale
  34. let maskScale = 1
  35. this.getRealScale(targetNode)
  36. // this.mask.getComponent(cc.Mask).spriteFrame = this[maskName];
  37. this.scheduleOnce(() => {
  38. this.mask.width = targetNode.width * this.targetNodeScale * maskScale
  39. this.mask.height = targetNode.height * this.targetNodeScale * maskScale
  40. }, 0.02)
  41. this.mask.angle = targetNode.angle
  42. uiCommon.setWorldPos(this.mask, targetWolrdPos)
  43. }
  44. //获取目标节点真实sacle
  45. getRealScale(root: cc.Node) {
  46. if (root.parent != null) {
  47. this.targetNodeScale *= root.parent.scale
  48. this.getRealScale(root.parent)
  49. }
  50. }
  51. }