| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import { _decorator, Component, RenderComponent, builtinResMgr, RichText, Node, Sprite } from 'cc';
- const { ccclass, property } = _decorator;
- /**
- * 灰度控制脚本
- * @author 郑聂华
- */
- @ccclass('GrayEffectNode')
- export class GrayEffectNode extends Component {
- setGray() {
- this.node.children.forEach(childNode => {
- //childNode.getComponentsInChildren(RenderComponent).forEach(renderComponent => {
- // renderComponent.setMaterial(builtinResMgr.get('ui-sprite-gray-material'), 0);
- //});
- this.checkSpriteGray(childNode, true);
- this.checkRichTextGray(childNode);
- });
- }
- revert() {
- this.node.children.forEach(childNode => {
- this.checkSpriteGray(childNode, false);
- });
- // this.node.children.forEach(childNode => {
- // childNode.getComponentsInChildren(RenderComponent).forEach(renderComponent => {
- // renderComponent.setMaterial(builtinResMgr.get('ui-sprite-material'), 0);
- // });
- // });
- }
- checkRichTextGray(richTextNode: Node) {
- if (richTextNode.getComponent(RichText)) {
- let strProp = richTextNode.getComponent(RichText);
- let strs = strProp.string.split("#");
- let target = "";
- for (let i = 0; i < strs.length; i++) {
- if (i != 0) {
- strs[i] = "#585858" + strs[i].slice(6);
- }
- target += strs[i];
- }
- strProp.string = target;
- }
- }
- checkSpriteGray(tempNode: Node, isGray: boolean) {
- tempNode.getComponentsInChildren(Sprite).forEach(img => {
- img.grayscale = isGray;
- });
- }
- }
|