You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							234 lines
						
					
					
						
							9.0 KiB
						
					
					
				
			
		
		
	
	
							234 lines
						
					
					
						
							9.0 KiB
						
					
					
				| import Common5 from "../../Platform/th/Common5";
 | |
| 
 | |
| const { ccclass, menu, property } = cc._decorator;
 | |
| 
 | |
| @ccclass
 | |
| @menu('FM组件/FMCircuit')
 | |
| export default class FMCircuit extends cc.Component {
 | |
|     @property({ type: cc.Node, tooltip: "链接节点1" })
 | |
|     FMCircuit_node1: cc.Node = null;
 | |
|     @property({ type: cc.Node, tooltip: "链接节点2" })
 | |
|     FMCircuit_node2: cc.Node = null;
 | |
| 
 | |
|     /**普通轨道1 */
 | |
|     circuit1: cc.Node = null;
 | |
|     /**转折轨道2 */
 | |
|     circuit2: cc.Node = null;
 | |
|     /**普通轨道3 */
 | |
|     circuit3: cc.Node = null;
 | |
|     /**转折轨道4 */
 | |
|     circuit4: cc.Node = null;
 | |
|     /**普通轨道5 */
 | |
|     circuit5: cc.Node = null;
 | |
|     /**当前是否开通轨道 */
 | |
|     opean: boolean = false;
 | |
|     onLoad() {
 | |
|         this.circuit1 = this.node.getChildByName("1");
 | |
|         this.circuit2 = this.node.getChildByName("2");
 | |
|         this.circuit3 = this.node.getChildByName("3");
 | |
|         this.circuit4 = this.node.getChildByName("4");
 | |
|         this.circuit5 = this.node.getChildByName("5");
 | |
|     }
 | |
| 
 | |
|     start() {
 | |
|         this.online();
 | |
|     }
 | |
|     /**线链接 */
 | |
|     online() {
 | |
|         if (this.node.name == "circuit19") {
 | |
|             console.log()
 | |
|         }
 | |
|         let angle = Common5.vectorsToDegress(this.FMCircuit_node1.getPosition().sub(this.FMCircuit_node2.getPosition()));
 | |
|         let node1 = this.FMCircuit_node1;
 | |
|         let node2 = this.FMCircuit_node2;
 | |
|         if (angle > 5 && angle < 90) {
 | |
|             let hi1 = this.circuit1.height;
 | |
|             let wi1 = this.circuit1.width;
 | |
|             let hi2 = this.circuit2.height;
 | |
|             let wi2 = this.circuit2.width;
 | |
|             let pos1 = cc.v2(node1.x, node1.y - node1.height / 2);
 | |
|             let pos2 = cc.v2(node2.x, node2.y + node2.height / 2);
 | |
|             let height1 = Math.abs(pos2.y - pos1.y);
 | |
|             let height2 = height1 - hi2;
 | |
|             let scaleh = height2 / hi1;
 | |
|             let width1 = Math.abs(pos1.x - pos2.x);
 | |
|             let width2 = width1 - wi2 * 2 + wi1;
 | |
|             let scalew = width2 / hi1;
 | |
|             this.circuit1.angle = 0;
 | |
|             this.circuit1.height *= scaleh / 2;
 | |
|             this.circuit1.setPosition(pos1.x, pos1.y - this.circuit1.height / 2);
 | |
|             this.circuit2.angle = 0;
 | |
|             this.circuit2.setPosition(pos1.x + wi2 / 2 - this.circuit1.width / 2, this.circuit1.y - this.circuit1.height / 2 - this.circuit2.height / 2);
 | |
|             this.circuit3.angle = -90;
 | |
|             this.circuit3.height *= scalew;
 | |
|             this.circuit3.setPosition(this.circuit2.x + wi2 / 2 + this.circuit3.height / 2, this.circuit2.y - hi2 / 2 + wi1 / 2 + 1);
 | |
|             this.circuit4.angle = 180;
 | |
|             this.circuit4.scaleX = 1;
 | |
|             this.circuit4.setPosition(pos2.x - wi2 / 2 + this.circuit1.width / 2, this.circuit3.y - hi2 / 2 + wi1 / 2 + 1);
 | |
|             this.circuit5.angle = 0;
 | |
|             this.circuit5.height *= scaleh / 2;
 | |
|             this.circuit5.setPosition(pos2.x, pos2.y + this.circuit5.height / 2);
 | |
|         } else if (angle >= 90) {
 | |
|             let hi1 = this.circuit1.height;
 | |
|             let wi1 = this.circuit1.width;
 | |
|             let hi2 = this.circuit2.height;
 | |
|             let wi2 = this.circuit2.width;
 | |
|             let k = node2.y > 0 ? 1 : -1;
 | |
|             let pos1 = cc.v2(node1.x, node1.y - k * node1.height / 2);
 | |
|             let pos2 = cc.v2(node2.x, node2.y - k * node2.height / 2);
 | |
|             let width1 = Math.abs(pos1.x - pos2.x);
 | |
|             let width2 = width1 - wi2 * 2 + wi1;
 | |
|             let scalew = width2 / hi1;
 | |
|             this.circuit1.angle = 0;
 | |
|             this.circuit1.height *= 1;
 | |
|             this.circuit1.setPosition(pos1.x, pos1.y - k * (this.circuit1.height / 2));
 | |
|             this.circuit2.angle = 90 - 90 * k;
 | |
|             this.circuit2.scaleX = 1 * k;
 | |
|             this.circuit2.setPosition(pos1.x + wi2 / 2 - this.circuit1.width / 2, this.circuit1.y - k * (this.circuit1.height / 2) - k * (this.circuit2.height / 2));
 | |
|             this.circuit3.angle = -90 * k;
 | |
|             this.circuit3.height *= scalew;
 | |
|             this.circuit3.setPosition(this.circuit2.x + wi2 / 2 + this.circuit3.height / 2, this.circuit2.y - k * (hi2 / 2) + k * (wi1 / 2 + 1));
 | |
|             this.circuit4.angle = 90 - 90 * k;
 | |
|             this.circuit4.scaleX = -1 * k;
 | |
|             this.circuit4.setPosition(pos2.x - wi2 / 2 + this.circuit1.width / 2, this.circuit2.y);
 | |
|             this.circuit5.angle = 0;
 | |
|             this.circuit5.height *= 1;
 | |
|             this.circuit5.setPosition(pos2.x, this.circuit1.y);
 | |
|         } else {
 | |
|             let hi1 = this.circuit1.height;
 | |
|             let wi1 = this.circuit1.width;
 | |
|             let hi2 = this.circuit2.height;
 | |
|             let wi2 = this.circuit2.width;
 | |
|             let pos1 = cc.v2(node1.x, node1.y - node1.height / 2);
 | |
|             let pos2 = cc.v2(node2.x, node2.y + node2.height / 2);
 | |
|             let height1 = Math.abs(pos2.y - pos1.y);
 | |
|             let height2 = height1 - hi2;
 | |
|             let scaleh = height2 / hi1;
 | |
|             let width1 = Math.abs(pos1.x - pos2.x);
 | |
|             let width2 = width1 - wi2 * 2 + wi1;
 | |
|             let scalew = width2 / hi1;
 | |
|             this.circuit1.angle = 0;
 | |
|             this.circuit1.height *= Math.round(scaleh / 2);
 | |
|             this.circuit1.setPosition(pos1.x, pos1.y - this.circuit1.height / 2);
 | |
|             this.circuit2.scaleX = -1;
 | |
|             this.circuit2.setPosition(pos1.x - wi2 / 2 + this.circuit1.width / 2, this.circuit1.y - this.circuit1.height / 2 - this.circuit2.height / 2);
 | |
|             this.circuit3.angle = 90;
 | |
|             this.circuit3.height *= scalew;
 | |
|             this.circuit3.setPosition(this.circuit2.x - wi2 / 2 - this.circuit3.height / 2, this.circuit2.y - hi2 / 2 + wi1 / 2 + 1);
 | |
|             this.circuit4.angle = -180;
 | |
|             this.circuit4.scaleX = -1;
 | |
|             this.circuit4.setPosition(pos2.x + wi2 / 2 - hi1 / 2 - 2, this.circuit3.y - hi2 / 2 + wi1 / 2 + 1);
 | |
|             this.circuit5.angle = 0;
 | |
|             this.circuit5.height *= Math.round(scaleh / 2);
 | |
|             this.circuit5.setPosition(pos2.x, pos2.y + this.circuit5.height / 2);
 | |
|         }
 | |
|     }
 | |
|     /**
 | |
|      * 显示路线
 | |
|      * @param bool true 正序显出 false 倒叙显出
 | |
|      */
 | |
|     onShow(bool: boolean) {
 | |
|         this.opean = true;
 | |
|         let k = 0;
 | |
|         let sq = [];
 | |
|         for (let i = 0; i < this.node.childrenCount; i++) {
 | |
|             let fade = cc.fadeIn(0.5);
 | |
|             if (i == this.node.childrenCount - 1) {
 | |
|                 sq.push(cc.sequence(fade, cc.callFunc(() => {
 | |
| 
 | |
|                 })))
 | |
|             } else {
 | |
|                 sq.push(fade);
 | |
|             }
 | |
|         }
 | |
|         // if (bool) {
 | |
|         this.node.children.forEach((e) => {
 | |
|             e.runAction(sq[k]);
 | |
|             k++;
 | |
|         })
 | |
|         // } else {
 | |
|         //     for (let index = this.node.childrenCount - 1; index >= 0; index--) {
 | |
|         //         this.node.children[index].runAction(sq[k]);
 | |
|         //         k++;
 | |
|         //     }
 | |
|         // }
 | |
|     }
 | |
|     /**
 | |
|      * 隐藏线路
 | |
|      * @param bool true 正序隐藏 false 倒叙隐藏
 | |
|      */
 | |
|     onHide(bool: boolean) {
 | |
|         let k = 0;
 | |
|         let sq = [];
 | |
|         for (let i = 0; i < this.node.childrenCount; i++) {
 | |
|             let fade = cc.fadeOut(0.5);
 | |
|             if (i == this.node.childrenCount - 1) {
 | |
|                 sq.push(cc.sequence(cc.delayTime(0.1), fade, cc.callFunc(() => {
 | |
|                     this.opean = false;
 | |
|                 })))
 | |
|             } else if (i == 0) {
 | |
|                 sq.push(fade);
 | |
|             } else {
 | |
|                 sq.push(cc.sequence(cc.delayTime(0.1), fade));
 | |
|             }
 | |
|         }
 | |
|         if (bool) {
 | |
|             this.node.children.forEach((e) => {
 | |
|                 e.runAction(sq[k]);
 | |
|                 k++;
 | |
|             })
 | |
|         } else {
 | |
|             for (let index = this.node.childrenCount - 1; index >= 0; index--) {
 | |
|                 this.node.children[index].runAction(sq[k]);
 | |
|                 k++;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
|     /**
 | |
|      * 赋值当前透明度
 | |
|      * @param opacity 
 | |
|      */
 | |
|     setopacity(opacity: number) {
 | |
|         this.node.children.forEach(e => {
 | |
|             e.opacity = opacity;
 | |
|         })
 | |
|     }
 | |
|     /**获取当前线路位置 */
 | |
|     onPosArry(bool): Array<cc.Vec2> {
 | |
|         let ary = [];
 | |
|         if (bool) {
 | |
|             this.node.children.forEach((e, k) => {
 | |
|                 if (k == 1 || k == 3) {
 | |
|                     let pos = e.convertToWorldSpaceAR(cc.v2(0, 0))
 | |
|                     ary.push(pos);
 | |
|                 }
 | |
|             })
 | |
|         } else {
 | |
|             for (let index = this.node.childrenCount - 1; index >= 0; index--) {
 | |
|                 if (index == 1 || index == 3) {
 | |
|                     let pos = this.node.children[index].convertToWorldSpaceAR(cc.v2(0, 0));
 | |
|                     ary.push(pos);
 | |
|                 }
 | |
| 
 | |
|             }
 | |
|         }
 | |
|         return ary;
 | |
|     }
 | |
|     /**
 | |
|      * 判断是那条线
 | |
|      */
 | |
|     onSetCricuit(node1: cc.Node, node2: cc.Node): boolean {
 | |
|         let k = 0;
 | |
|         if (node1 == this.FMCircuit_node1 || node1 == this.FMCircuit_node2) {
 | |
|             k++;
 | |
|         }
 | |
|         if (node2 == this.FMCircuit_node1 || node2 == this.FMCircuit_node2) {
 | |
|             k++;
 | |
|         }
 | |
|         if (this.opean) {
 | |
|             return false;
 | |
|         }
 | |
|         return k == 2;
 | |
|     }
 | |
|     // update (dt) {}
 | |
| }
 | |
| 
 |