88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 螺丝刀
|
|
/// </summary>
|
|
public class Tool_Screwdriver : Tool_Base
|
|
{
|
|
/// <summary>
|
|
/// 开始安装螺丝
|
|
/// </summary>
|
|
/// <param name="screw"></param>
|
|
public void Install(Tool_Screw 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);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始卸载螺丝
|
|
/// </summary>
|
|
/// <param name="screw"></param>
|
|
public void UnInstall(Tool_Screw 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_Screw ts = hit.transform.GetComponent<Tool_Screw>();
|
|
if (ts != null)
|
|
{
|
|
//螺丝判断条件,是否可以拧
|
|
if (ts.CanMove())
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke(ts.triggerName, true)) == 0)
|
|
{
|
|
if (ts.isInstall)
|
|
{
|
|
UnInstall(ts);
|
|
}
|
|
else
|
|
{
|
|
Install(ts);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|