using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 扳手 /// public class Tool_Spanner : Tool_Base { /// /// 开始安装螺丝 /// /// public void Install(Tool_SpannerScrew screw) { if (!screw.isInstall && !screw.isMoving && !isMoving) { screw.isMoving = true; isMoving = true; Debug.Log("开始拧紧螺丝"); hand_out_action?.Invoke(); //螺丝刀移到螺丝上 transform.parent = null; transform.DOLocalRotate(screw.installPos.localEulerAngles, 0.5f); transform.DOMove(screw.installPos.position, 1).OnComplete(() => { //screw.BeInstalled(this); }); } } /// /// 开始卸载螺丝 /// /// public void UnInstall(Tool_SpannerScrew screw) { if (screw.isInstall && !screw.isMoving && !isMoving) { screw.isMoving = true; isMoving = true; Debug.Log("开始卸螺丝"); hand_out_action?.Invoke(); //螺丝刀移到螺丝处 transform.parent = null; transform.DOLocalRotate(screw.installPos.localEulerAngles, 0.5f); transform.DOMove(screw.installPos.position, 1).OnComplete(() => { //screw.BeUnInstalled(this); }); } } private void Update() { if (Input.GetMouseButtonDown(0) && !base.isMoving) { //点击螺丝验电 Ray tmpray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(tmpray, out RaycastHit hit)) { //螺丝 Tool_SpannerScrew ts = hit.transform.GetComponent(); if (ts != null) { //螺丝判断条件,是否可以拧 if (ts.CanMove()) { if ((triggerAction == null ? 0 : triggerAction.Invoke(ts.triggerName, true)) == 0) { if (ts.isInstall) { UnInstall(ts); } else { Install(ts); } } } } } } } }