HoldEvent.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__decorate) ||
  6. function(t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", { value: !0 });
  17. const { ccclass: o, property: a, menu: n } = cc._decorator;
  18. e = class extends cc.Component {
  19. constructor() {
  20. super(...arguments), (this.callEvent = []), (this.targets = []), (this._interactable = !0);
  21. }
  22. set interactable(t) {
  23. if (t !== this._interactable)
  24. if ((this._interactable = t))
  25. for (const e of this.targets) e.setMaterial(0, cc.Material.getBuiltinMaterial("2d-sprite"));
  26. else {
  27. this.unschedule(this.onClick), (this.node.scale = 1);
  28. for (const t of this.targets) t.setMaterial(0, cc.Material.getBuiltinMaterial("2d-gray-sprite"));
  29. }
  30. }
  31. get interactable() {
  32. return this._interactable;
  33. }
  34. onLoad() {
  35. this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchUpgradeStart, this),
  36. this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchUpgradeEnd, this),
  37. this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchUpgradeCancel, this);
  38. }
  39. onTouchUpgradeStart() {
  40. this._interactable && (this.schedule(this.onClick, 0.1, cc.macro.REPEAT_FOREVER, 0.5), (this.node.scale = 1.1));
  41. }
  42. onDisable() {
  43. this.unschedule(this.onClick);
  44. }
  45. onClick() {
  46. cc.Component.EventHandler.emitEvents(this.callEvent);
  47. }
  48. onTouchUpgradeEnd() {
  49. this._interactable && (this.onTouchUpgradeCancel(), cc.Component.EventHandler.emitEvents(this.callEvent)),
  50. (this.node.scale = 1);
  51. }
  52. onTouchUpgradeCancel() {
  53. this.unschedule(this.onClick), (this.node.scale = 1);
  54. }
  55. };
  56. s([a({ type: cc.Component.EventHandler })], e.prototype, "callEvent", void 0),
  57. s([a([cc.RenderComponent])], e.prototype, "targets", void 0),
  58. (e = s([o], e)),
  59. (i.default = e);