64 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| using DG.Tweening;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| 
 | |
| /// <summary>
 | |
| /// 接线
 | |
| /// </summary>
 | |
| public class Tool_Line: Tool_Base
 | |
| {
 | |
|     /// <summary>
 | |
|     /// 是否接上
 | |
|     /// </summary>
 | |
|     public bool isConnected;
 | |
|     /// <summary>
 | |
|     /// 标识
 | |
|     /// </summary>
 | |
|     public string id;
 | |
| 
 | |
|     /// <summary>
 | |
|     /// 固定接线的螺丝
 | |
|     /// </summary>
 | |
|     public List<Tool_Screw> screws=new List<Tool_Screw>();
 | |
| 
 | |
| 
 | |
|     /// <summary>
 | |
|     /// 安装状态时Y的local值
 | |
|     /// </summary>
 | |
|     public float InstallPosY;
 | |
| 
 | |
|     protected override void OnAwake()
 | |
|     {
 | |
|         base.OnAwake();
 | |
|         id = gameObject.name;
 | |
|     }
 | |
| 
 | |
|     private void OnMouseDown()
 | |
|     {
 | |
|         if(isConnected)
 | |
|         {
 | |
|             //取下接线
 | |
|             if(screws.TrueForAll(a=>!a.isInstall))
 | |
|             {
 | |
|                 transform.DOLocalMoveY(InstallPosY - 2, 1).OnComplete(()=>
 | |
|                 {
 | |
|                     isConnected = false;
 | |
|                 });
 | |
|             }
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             //装上接线
 | |
|             if (screws.TrueForAll(a => !a.isInstall))
 | |
|             {
 | |
|                 transform.DOLocalMoveY(InstallPosY, 1).OnComplete(() => 
 | |
|                 {
 | |
|                     isConnected = true;
 | |
|                 });
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |