import { _decorator, Color, isValid, Label, Node, RichText, Size, Sprite, UITransform, Vec3, view, } from "cc"; import li_EventManager from "./li_EventManager"; const { ccclass, property } = _decorator; @ccclass export default class Utils { //log日志 public static Log(msg: string | any, ...subst: any[]) { let IsLocalCSChanel = true; if (IsLocalCSChanel) { console.log(msg, subst); } } //警告日志 public static Warning(msg: string | any, ...subst: any[]) { let IsLocalCSChanel = true; if (IsLocalCSChanel) { console.warn(msg, subst); } } //错误日志 public static Error(msg: string | any, ...subst: any[]) { let IsLocalCSChanel = true; if (IsLocalCSChanel) { console.error(msg, subst); } } //解析节点 public static parseNode = function (node: Node, oriObj?: any) { if (!node || !node.children) return; oriObj = oriObj || node; let chs = node.children; for (let i = 0; i < chs.length; i++) { let ch = chs[i]; let chName = ch.name; if (chName && chName.length > 0) { try { oriObj[chName] = ch; } catch (error) { //hg_utils.hgLog("chName err:", chName); } } Utils.parseNode(ch, oriObj); } }; //更换父节点,保留原有的坐标和旋转 public static changeNodeParent(node: Node, parentNode: Node) { let world_Q = node.getWorldRotation(); let world_pos = node.getWorldPosition(); //原来的世界坐标 node.setParent(parentNode); node.setRotation(world_Q); node.setWorldPosition(world_pos); } /** * 封装setString方法 */ static setString(node: Node, str: string | number) { if (!isValid(node)) return; let lb: any = node.getComponent(Label); if (!lb) return; if (str == null) { str = ""; } str += ""; lb.string = str; } /** * 添加富文本 * @param node * @param str * @param outLine * @param width * @returns */ static addRichText( node: Node, str: string, outLine: string | null = null, width: number | null = 2, max: number = 0 ) { if (!node) return; let comp = node.getComponent(RichText); if (!comp) return; str = Utils.replaceAll(str, "", ""); str = str.replace(/\<\/font\>/g, ""); str = Utils.replaceAll(str, "'>", ">"); str = Utils.replaceAll(str, "