| 
									
										
										
										
											2024-03-23 20:28:14 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * @Author: WoNiu | 
					
						
							|  |  |  |  * @Date: 2024-03-23 13:22:27 | 
					
						
							| 
									
										
										
										
											2024-03-24 17:57:19 +08:00
										 |  |  |  * @LastEditTime: 2024-03-24 16:04:20 | 
					
						
							| 
									
										
										
										
											2024-03-23 20:28:14 +08:00
										 |  |  |  * @LastEditors: WoNiu | 
					
						
							| 
									
										
										
										
											2024-03-24 17:57:19 +08:00
										 |  |  |  * @Description: node坐标控制 | 
					
						
							| 
									
										
										
										
											2024-03-23 20:28:14 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   _decorator, | 
					
						
							|  |  |  |   Color, | 
					
						
							|  |  |  |   Component, | 
					
						
							|  |  |  |   EditBox, | 
					
						
							|  |  |  |   Font, | 
					
						
							|  |  |  |   HorizontalTextAlignment, | 
					
						
							|  |  |  |   Node, | 
					
						
							|  |  |  |   Size, | 
					
						
							|  |  |  |   Sprite, | 
					
						
							|  |  |  |   UITransform, | 
					
						
							|  |  |  |   v2, | 
					
						
							|  |  |  |   VerticalTextAlignment, | 
					
						
							|  |  |  | } from "cc"; | 
					
						
							|  |  |  | const { ccclass, property } = _decorator; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @ccclass("LocationImportComponent") | 
					
						
							| 
									
										
										
										
											2024-03-24 17:57:19 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @description: node坐标控制 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-03-23 20:28:14 +08:00
										 |  |  | export class LocationImportComponent extends Component { | 
					
						
							|  |  |  |   editBox: EditBox; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onLoad(): void { | 
					
						
							|  |  |  |     const node = new Node(); | 
					
						
							|  |  |  |     node.setPosition(0, 30); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const uit = node.addComponent(UITransform); | 
					
						
							|  |  |  |     uit.anchorPoint = v2(0, 1); | 
					
						
							|  |  |  |     uit.setContentSize(new Size(150, 30)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const sp = node.addComponent(Sprite); | 
					
						
							|  |  |  |     sp.color = Color.WHITE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const editBox = node.addComponent(EditBox); | 
					
						
							|  |  |  |     editBox.inputMode = EditBox.InputMode.SINGLE_LINE; | 
					
						
							|  |  |  |     this.editBox = editBox; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.node.addChild(node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //* 修改 node 的坐标
 | 
					
						
							|  |  |  |     editBox.node.on("editing-did-ended", (text: EditBox) => { | 
					
						
							|  |  |  |         const los = text.textLabel.string.split(','); | 
					
						
							|  |  |  |         this.node.setPosition(Number(los[0]),Number(los[1])); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   start() { | 
					
						
							|  |  |  |     const placeholderLabel = this.editBox.placeholderLabel; | 
					
						
							|  |  |  |     placeholderLabel.string = "坐标"; | 
					
						
							|  |  |  |     placeholderLabel.horizontalAlign = HorizontalTextAlignment.LEFT; | 
					
						
							|  |  |  |     placeholderLabel.verticalAlign = VerticalTextAlignment.TOP; | 
					
						
							|  |  |  |     placeholderLabel.fontSize = 20; | 
					
						
							|  |  |  |     placeholderLabel.color = Color.RED; | 
					
						
							|  |  |  |     placeholderLabel.node.setPosition(0, 50); | 
					
						
							|  |  |  |     placeholderLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const textLabel = this.editBox.textLabel; | 
					
						
							|  |  |  |     textLabel.horizontalAlign = HorizontalTextAlignment.LEFT; | 
					
						
							|  |  |  |     textLabel.verticalAlign = VerticalTextAlignment.TOP; | 
					
						
							|  |  |  |     textLabel.fontSize = 20; | 
					
						
							|  |  |  |     textLabel.color = Color.RED; | 
					
						
							|  |  |  |     textLabel.node.setPosition(0, 50); | 
					
						
							|  |  |  |     textLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2); | 
					
						
							| 
									
										
										
										
											2024-03-24 17:57:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-23 20:28:14 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   update(deltaTime: number) {} | 
					
						
							|  |  |  | } |