80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 采集器插头
|
|
/// </summary>
|
|
public class Device_Plug : Device_Base
|
|
{
|
|
public bool isClosed = true;//插头是否插上
|
|
|
|
private Vector3 openedPosition = new Vector3(0.006096095f, -0.0737f, -0.006051207f);
|
|
private Vector3 closedPosition = new Vector3(0.006096095f, -0.08114577f, -0.006051207f);
|
|
|
|
public Action onPlugToClose;
|
|
|
|
/// <summary>
|
|
/// 打开插头
|
|
/// </summary>
|
|
public void Open()
|
|
{
|
|
if (isClosed && !DOTween.IsTweening(transform))
|
|
{
|
|
transform.DOLocalMove(openedPosition, 1.0f).OnComplete(() => {
|
|
isClosed = false;
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, true);
|
|
SetPlugColliderState(false);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 关闭插头
|
|
/// </summary>
|
|
public void Close()
|
|
{
|
|
if (!isClosed && !DOTween.IsTweening(transform))
|
|
{
|
|
transform.DOLocalMove(closedPosition, 1.0f).OnComplete(() => {
|
|
isClosed = true;
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, true);
|
|
//SetPlugColliderState(false);
|
|
onPlugToClose?.Invoke();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
if (isClosed)
|
|
Open();
|
|
else
|
|
Close();
|
|
}
|
|
|
|
public void SetPlugState(bool isClosed)
|
|
{
|
|
this.isClosed = isClosed;
|
|
if (isClosed)
|
|
transform.localPosition = closedPosition;
|
|
else
|
|
transform.localPosition = openedPosition;
|
|
}
|
|
|
|
public void SetPlugColliderState(bool _enable)
|
|
{
|
|
BoxCollider boxCollider = GetComponent<BoxCollider>();
|
|
if (boxCollider != null)
|
|
boxCollider.enabled = _enable;
|
|
}
|
|
}
|