1118OPSSNew/Assets/Zion/Scripts//设备/Tool_Screw.cs

213 lines
5.3 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>
/// 安装状态时Y的local值
/// </summary>
public float initPostionY;
/// <summary>
/// 螺丝拆装事件回调
/// </summary>
private Action<bool> installAction;
/// <summary>
/// 螺丝判断条件回调
/// </summary>
private Func<bool> checkCanMove;
/// <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;
}
public GameObject circileLeft;
public GameObject circileRight;
protected LineRenderer lineRenderer;
protected override void OnAwake()
{
base.OnAwake();
}
public void AddinstallAction(Action<bool> action)
{
this.installAction = action;
}
public void AddCheckAction(Func<bool> checkCanMove)
{
this.checkCanMove = checkCanMove;
}
/// <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()
{
//动画
isMoving = true;
transform.DOLocalMoveZ(3.815f, 2.0f)
.OnUpdate(() =>
{
transform.RotateAroundLocal(Vector3.forward, -0.1f);
})
.OnComplete(() =>
{
Debug.Log("螺丝已拧紧");
isInstall = true;
isMoving = false;
installAction?.Invoke(true);
CallScoreAction(true);
triggerAction?.Invoke(triggerName, true);
});
}
/// <summary>
/// 被拧松
/// </summary>
/// <param name="screwdriver"></param>
public void BeUnInstalled()
{
//动画
isMoving = true;
transform.DOLocalMoveZ(3.8382f, 2.0f)
.OnUpdate(() =>
{
transform.RotateAroundLocal(Vector3.forward, 0.1f);
})
.OnComplete(() =>
{
Debug.Log("螺丝已拧松");
isInstall = false;
isMoving = false;
installAction?.Invoke(false);
CallScoreAction(false);
triggerAction?.Invoke(triggerName, true);
});
}
public Transform GetPoint()
{
return null;
}
public string curretTriggerName()
{
return triggerName;
}
protected override void OnMDown()
{
base.OnMDown();
if (isInstall && LiveSceneManager.Instance.currentTool != null)
{
BeUnInstalled();
}
else
{
if (circileLeft.activeInHierarchy)
{
BeInstalled();
}
else
{
circileLeft.SetActive(true);
lineRenderer = circileLeft.GetComponent<LineRenderer>();
lineRenderer.enabled = true;
lineRenderer.SetPosition(0, circileLeft.transform.position);
}
}
StepManager.Instance.FinishStep(triggerName);
}
private void Update()
{
if (circileLeft.activeInHierarchy && lineRenderer != null && !circileRight.activeInHierarchy)
{
lineRenderer.SetPosition(1, LiveSceneManager.Instance.spawnToolPos.position);
}
}
// if (Input.GetMouseButtonDown(0))
// {
// //点击螺丝验电
// 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 (ts.isInstall)
// {
// ts.BeUnInstalled();
// }
// else
// {
// ts.BeInstalled();
// }
// }
// }
// }
// }
//}
}