/* * @Author: WoNiu * @Date: 2024-03-21 13:29:53 * @LastEditTime: 2024-03-25 01:18:18 * @LastEditors: WoNiu * @Description: */ import { _decorator,Component, Node } from 'cc'; import { BoardRoot } from './BoardRoot'; import { UIRoot } from './UIRoot'; import { DialogRoot } from './DialogRoot'; const { ccclass, property } = _decorator; /** * @description: 游戏根节点的单例 用于直接提供子节点 */ export class GameRootSingleton { private static readonly _instance: GameRootSingleton = new GameRootSingleton(); private constructor() {} public static getInstance(): GameRootSingleton { return GameRootSingleton._instance; } boardRootNode:Node; UIRootNode: Node; DialogRootNode: Node; boardRoot: BoardRoot; UIRoot: UIRoot; DialogRoot: DialogRoot; } @ccclass('GameRootController') /** * @description: 游戏根节点脚本 */ export class GameRootController extends Component { @property(Node) boardRootNode:Node; @property(Node) UIRootNode: Node; @property(Node) DialogRootNode: Node; start() { /// 给三个图层添加 root 根脚本 const game = GameRootSingleton.getInstance(); game.boardRootNode = this.boardRootNode; game.UIRootNode = this.UIRootNode; game.DialogRootNode = this.DialogRootNode; /// 给三个图层添加 root 根脚本 game.boardRoot = this.boardRootNode.getComponent(BoardRoot); game.UIRoot = this.UIRootNode.getComponent(UIRoot); game.DialogRoot = this.DialogRootNode.getComponent(DialogRoot); } update(deltaTime: number) { } }