import { Color, Sprite } from 'cc'; import { Material } from 'cc'; import { _decorator, Component, Node } from 'cc'; const { ccclass, property } = _decorator; @ccclass('SetOutline') export class SetOutline extends Component { @property({ type: Material }) mt: Material = null; @property width: number = 1; @property({ type: Color }) color: Color = new Color(230, 205, 23, 255); oldmt: Material = null; protected onLoad(): void { this.oldmt = this.node.getComponent(Sprite).material; this.node.on(Node.EventType.TOUCH_START, this.click, this); } show(show = true, width = 0, color = null) { this.isShow = show; if (width > 0) this.width = width; if (color) this.color = color; this.node.getComponent(Sprite).material = this.isShow ? this.mt : this.oldmt; this.mt.setProperty("_LineWidth", this.width); this.mt.setProperty("_LineColor", this.color); } isShow = false; click() { this.show(!this.isShow); } }