79 lines
2.1 KiB
C#
79 lines
2.1 KiB
C#
using DG.Tweening;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using static Unity.Burst.Intrinsics.X86.Avx;
|
|
|
|
/// <summary>
|
|
/// 剥线钳
|
|
/// </summary>
|
|
public class Tool_WireStripper : Tool_Base
|
|
{
|
|
private bool isCuning;
|
|
/// <summary>
|
|
/// 开始剪封印
|
|
/// </summary>
|
|
/// <param name="device_Seal"></param>
|
|
public void CutOpen(Device_Seal device_Seal)
|
|
{
|
|
isCuning = true;
|
|
transform.parent = null;
|
|
transform.DORotate(device_Seal.testPosAndRot.eulerAngles, 0.5f);
|
|
transform.DOMove(device_Seal.testPosAndRot.position, 1).OnComplete(() =>
|
|
{
|
|
//播放动画
|
|
StopAllCoroutines();
|
|
StartCoroutine(PlayAnimi(device_Seal));
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 剪的动画
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator PlayAnimi(Device_Seal device_Seal)
|
|
{
|
|
SkinnedMeshRenderer renderer = GetComponentInChildren<SkinnedMeshRenderer>();
|
|
float vlaue = 0;
|
|
//打开
|
|
while (renderer.GetBlendShapeWeight(0) < 100)
|
|
{
|
|
vlaue += (Time.deltaTime * 200);
|
|
renderer.SetBlendShapeWeight(0, vlaue);
|
|
yield return null;
|
|
}
|
|
//关闭
|
|
while (renderer.GetBlendShapeWeight(0) > 0)
|
|
{
|
|
vlaue -= (Time.deltaTime * 200);
|
|
renderer.SetBlendShapeWeight(0, vlaue);
|
|
yield return null;
|
|
}
|
|
//剪断
|
|
device_Seal.Cut();
|
|
isCuning = false;
|
|
ReBackHead();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0) && !isCuning)
|
|
{
|
|
//点击螺丝验电
|
|
Ray tmpray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
if (Physics.Raycast(tmpray, out RaycastHit hit))
|
|
{
|
|
//封印
|
|
Device_Seal ds = hit.transform.GetComponent<Device_Seal>();
|
|
if (ds != null)
|
|
{
|
|
if ((triggerAction == null ? 0 : triggerAction.Invoke(ds.triggerName, true)) == 0)
|
|
{
|
|
CutOpen(ds);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|