| 
									
										
										
										
											2024-03-25 19:50:16 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * @Author: WoNiu | 
					
						
							|  |  |  |  * @Date: 2024-03-21 13:29:53 | 
					
						
							|  |  |  |  * @LastEditTime: 2024-03-25 01:18:18 | 
					
						
							|  |  |  |  * @LastEditors: WoNiu | 
					
						
							|  |  |  |  * @Description: | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-03-22 21:19:27 +08:00
										 |  |  | import { _decorator,Component, Node } from 'cc'; | 
					
						
							|  |  |  | import { BoardRoot } from './BoardRoot'; | 
					
						
							|  |  |  | import { UIRoot } from './UIRoot'; | 
					
						
							|  |  |  | import { DialogRoot } from './DialogRoot'; | 
					
						
							|  |  |  | const { ccclass, property } = _decorator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 19:50:16 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @description: 游戏根节点的单例 用于直接提供子节点 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-03-22 21:19:27 +08:00
										 |  |  | 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') | 
					
						
							| 
									
										
										
										
											2024-03-25 19:50:16 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @description: 游戏根节点脚本 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-03-22 21:19:27 +08:00
										 |  |  | 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) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |