1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- var t = require;
- var e = module;
- var i = exports;
- var s =
- (this && this.__decorate) ||
- function(t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", { value: !0 });
- const { ccclass: o, property: a, menu: n } = cc._decorator;
- e = class extends cc.Component {
- constructor() {
- super(...arguments), (this.callEvent = []), (this.targets = []), (this._interactable = !0);
- }
- set interactable(t) {
- if (t !== this._interactable)
- if ((this._interactable = t))
- for (const e of this.targets) e.setMaterial(0, cc.Material.getBuiltinMaterial("2d-sprite"));
- else {
- this.unschedule(this.onClick), (this.node.scale = 1);
- for (const t of this.targets) t.setMaterial(0, cc.Material.getBuiltinMaterial("2d-gray-sprite"));
- }
- }
- get interactable() {
- return this._interactable;
- }
- onLoad() {
- this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchUpgradeStart, this),
- this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchUpgradeEnd, this),
- this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchUpgradeCancel, this);
- }
- onTouchUpgradeStart() {
- this._interactable && (this.schedule(this.onClick, 0.1, cc.macro.REPEAT_FOREVER, 0.5), (this.node.scale = 1.1));
- }
- onDisable() {
- this.unschedule(this.onClick);
- }
- onClick() {
- cc.Component.EventHandler.emitEvents(this.callEvent);
- }
- onTouchUpgradeEnd() {
- this._interactable && (this.onTouchUpgradeCancel(), cc.Component.EventHandler.emitEvents(this.callEvent)),
- (this.node.scale = 1);
- }
- onTouchUpgradeCancel() {
- this.unschedule(this.onClick), (this.node.scale = 1);
- }
- };
- s([a({ type: cc.Component.EventHandler })], e.prototype, "callEvent", void 0),
- s([a([cc.RenderComponent])], e.prototype, "targets", void 0),
- (e = s([o], e)),
- (i.default = e);
|