CultivationOfBrewing-2/Assets/Scripts/CXX/Tools/Tool_Screw.cs

167 lines
4.1 KiB
C#

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 十字螺丝
/// </summary>
public class Tool_Screw : Tool_Base, PointInterface
{
/// <summary>
/// 是否已拧紧
/// </summary>
public bool isInstall;
/// <summary>
/// 上螺丝位置
/// </summary>
public Transform installPos;
/// <summary>
/// 是否带电
/// </summary>
[ReconnetAtrribute]
public bool hasElectricity;
/// <summary>
/// 安装状态时Y的local值
/// </summary>
public float initPostionY;
/// <summary>
/// 螺丝拆装事件回调
/// </summary>
private Action<bool> installAction;
/// <summary>
/// 螺丝判断条件回调
/// </summary>
private Func<bool> checkCanMove;
/// <summary>
/// 夹子位置
/// </summary>
public Transform jiaZiPos;
/// <summary>
/// 电压值
/// </summary>
public float ElectricityVlaue=226;
/// <summary>
/// 验电笔验电角度
/// </summary>
private Vector3 testPenAng=Vector3.zero;
/// <summary>
/// 验电笔验电角度(不设置为原角度,设置则为设置的角度)
/// </summary>
public Vector3 TestPenAng
{
get
{
if (testPenAng == Vector3.zero)
return installPos.localEulerAngles - new Vector3(0, 0, transform.localEulerAngles.y - 180);
else
return testPenAng;
}
set => testPenAng = value;
}
protected override void OnAwake()
{
base.OnAwake();
jiaZiPos = Instantiate(installPos, this.transform);
jiaZiPos.localEulerAngles = Vector3.zero;
jiaZiPos.localScale = new Vector3(0.5f, 0.5f, 0.5f);
}
public void AddinstallAction(Action<bool> action)
{
this.installAction = action;
}
public void AddCheckAction(Func<bool> checkCanMove)
{
this.checkCanMove = checkCanMove;
}
//protected override void OnMDown()
//{
// base.OnMDown();
//}
/// <summary>
/// 螺丝是否可以拧
/// </summary>
/// <returns></returns>
public bool CanMove()
{
if (checkCanMove == null)
{
return true;
}
else
{
return checkCanMove.Invoke();
}
}
/// <summary>
/// 被拧紧
/// </summary>
/// <param name="screwdriver"></param>
public void BeInstalled(Tool_Screwdriver screwdriver)
{
//动画
transform.DOLocalMoveY(initPostionY, 1)
.OnUpdate(() =>
{
transform.RotateAroundLocal(Vector3.up, -1);
screwdriver.transform.RotateAroundLocal(Vector3.up, -10);
})
.OnComplete(() =>
{
Debug.Log("螺丝已拧紧");
isInstall = true;
isMoving = false;
screwdriver.isMoving = false;
installAction?.Invoke(true);
screwdriver.ReBackHead();
CallScoreAction(true);
triggerAction?.Invoke(triggerName, true);
});
}
/// <summary>
/// 被拧松
/// </summary>
/// <param name="screwdriver"></param>
public void BeUnInstalled(Tool_Screwdriver screwdriver)
{
//动画
transform.DOLocalMoveY(initPostionY - 0.02f, 1)
.OnUpdate(() =>
{
transform.RotateAroundLocal(Vector3.up, 1);
screwdriver.transform.RotateAroundLocal(Vector3.up, 10);
})
.OnComplete(() =>
{
Debug.Log("螺丝已拧松");
isInstall = false;
isMoving = false;
screwdriver.isMoving = false;
installAction?.Invoke(false);
screwdriver.ReBackHead();
CallScoreAction(false);
triggerAction?.Invoke(triggerName, true);
});
}
public Transform GetPoint()
{
return jiaZiPos;
}
public string curretTriggerName()
{
return triggerName;
}
}