156 lines
4.9 KiB
C#
156 lines
4.9 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 采集器
|
|
/// </summary>
|
|
public class Device_Collector : Device_Base
|
|
{
|
|
public Device_Plug plug;//采集器插头
|
|
public Transform installArea;//安装区域
|
|
|
|
public Vector3 installPos = new Vector3(-0.1565018f, 0.08880007f, 0.0439f);//安装位置
|
|
public Vector3 uninstallPos = new Vector3(-0.1565018f, 0.08880007f, -0.0424f);//卸载位置
|
|
public bool isInstalled = true;//是否安装
|
|
|
|
/// <summary>
|
|
/// 连线插头
|
|
/// </summary>
|
|
public List<Device_LinePlug> linePlugs;
|
|
|
|
public void Init(bool isInstall)
|
|
{
|
|
if (isInstall)
|
|
transform.localPosition = installPos;
|
|
else
|
|
transform.localPosition = uninstallPos;
|
|
plug.SetPlugState(isInstall);
|
|
isInstalled = isInstall;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取下采集器
|
|
/// </summary>
|
|
public void Uninstall()
|
|
{
|
|
if (isInstalled && !plug.isClosed && !DOTween.IsTweening(transform))
|
|
{
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study && GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, false) != 0)return;
|
|
transform.DOLocalMove(uninstallPos, 1.0f).OnComplete(() =>
|
|
{
|
|
isInstalled = false;
|
|
transform.gameObject.SetActive(false);
|
|
if (installArea != null)
|
|
installArea.gameObject.SetActive(true);
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, true);
|
|
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移动到卸载位置
|
|
/// </summary>
|
|
public void MoveToUninstall()
|
|
{
|
|
transform.localPosition = uninstallPos;
|
|
}
|
|
/// <summary>
|
|
/// 移动到安装位置
|
|
/// </summary>
|
|
public void MoveToInstall()
|
|
{
|
|
transform.localPosition = installPos;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装采集器
|
|
/// </summary>
|
|
public void Install(Transform collector_transform, Vector3 localAng, Action comp = null)
|
|
{
|
|
if (!isInstalled && !plug.isClosed && !DOTween.IsTweening(transform))
|
|
{
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study && GameManager.ProcessMgr.IsRightSubProcessStepsTriggerID(triggerName, false) != 0) return;
|
|
transform.parent = collector_transform;
|
|
transform.GetComponentsInChildren<PermanentTriggerBase>(true).ToList().ForEach(a => a.Awake());
|
|
//默认是拆除的状态
|
|
//Init(false);
|
|
hand_out_action?.Invoke();
|
|
//从手里飞过去
|
|
transform.localEulerAngles = localAng;
|
|
transform.DOLocalMove(installPos, 2).OnComplete(() =>
|
|
{
|
|
isInstalled = true;
|
|
if (installArea != null)
|
|
installArea.gameObject.SetActive(false);
|
|
comp?.Invoke();
|
|
//LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
|
|
Debug.Log("采集器已安装");
|
|
//CallScoreAction(true);
|
|
});
|
|
}
|
|
}
|
|
|
|
protected override void OnMDown()
|
|
{
|
|
base.OnMDown();
|
|
if (isInstalled)
|
|
Uninstall();
|
|
else
|
|
{
|
|
if (LiveSceneManager.Instance != null)
|
|
{
|
|
Transform controller = LiveSceneManager.Instance.device_Control.transform;
|
|
Install(controller, Vector3.zero);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安装
|
|
/// </summary>
|
|
/// <param name="trigger"></param>
|
|
/// <param name="addAction"></param>
|
|
public void Add(DeviceTrigger trigger, Action addAction)
|
|
{
|
|
if (triggerAction == null || triggerAction.Invoke(trigger.triggerName, false) == 0)
|
|
{
|
|
transform.parent = null;
|
|
transform.transform.eulerAngles = trigger.transform.eulerAngles;
|
|
hand_out_action?.Invoke();
|
|
transform.DOMove(trigger.transform.position, 1).OnComplete(() =>
|
|
{
|
|
LiveSceneManager.Instance.OnCheckSubProcess(false);
|
|
isInstalled = true;
|
|
addAction?.Invoke();
|
|
triggerAction.Invoke(trigger.triggerName, true);
|
|
CallScoreAction(true);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 直接设置安装状态
|
|
/// </summary>
|
|
/// <param name="trigger"></param>
|
|
public void SetInstallState(DeviceTrigger trigger)
|
|
{
|
|
transform.parent = null;
|
|
transform.transform.eulerAngles = trigger.transform.eulerAngles;
|
|
transform.position = trigger.transform.position;
|
|
isInstalled = true;
|
|
|
|
//手动初始化
|
|
transform.GetComponentsInChildren<Tool_Base>(true).ToList().ForEach(a => a.Awake());
|
|
transform.GetComponentsInChildren<Device_Base>(true).ToList().ForEach(a => a.Awake());
|
|
}
|
|
}
|