You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
6.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
namespace DisComputer
{
public class CpuAnimation : SpareAnimationBase
{
[Header("拆卸提示操作指引")]
public GameObject unLoadTipGo;
[Header("安装提示操作指引")]
public GameObject loadTipGo;
public Vector3 mainShowPos;
public Vector3 mainInitPos;
[Header("卡扣")]
public GameObject buckleGo;
public Vector3 openEuler;
public Vector3 closeEuler;
[Header("卡槽")]
public GameObject slotGo;
[Header("卡槽打开角度")]
public Vector3 slotOpenEuler;
[Header("卡槽关闭角度")]
public Vector3 slotCloseEuler;
public GameObject lock01Go;
private CpuDetailAni curCpuAni;
// Start is called before the first frame update
void Start()
{
isHit01 = false;
}
private void Update()
{
if (isHit01)
{
if (Input.GetMouseButtonDown(0))
{
if (hit.collider)
{
hit.collider.gameObject.SetActive(false);
if(GameConfig.state == GameState.Unload)
{
buckleGo.transform.DOLocalRotate(openEuler, 0.35f).SetEase(Ease.Linear);
}else
{
buckleGo.transform.DOLocalRotate(closeEuler, 0.35f).SetEase(Ease.Linear);
}
isHit01 = false;
onclick--;
}
}
}
}
public override void SetLoadState()
{
unLoadTipGo.SetActive(false);
loadTipGo.SetActive(false);
buckleGo.SetActive(true);
mainGo.SetActive(true);
curCpuAni = mainGo.GetComponent<CpuDetailAni>();
curCpuAni.SetUnLoadState();
buckleGo.transform.localEulerAngles = closeEuler;
//卡槽设置关闭状态
slotGo.transform.localEulerAngles = slotCloseEuler;
}
public override void SetUnloadState()
{
unLoadTipGo.SetActive(false);
loadTipGo.SetActive(false);
buckleGo.SetActive(false);
curCpuAni = mainGo.GetComponent<CpuDetailAni>();
curCpuAni.SetLoadState();
mainGo.SetActive(false);
buckleGo.transform.localEulerAngles = openEuler;
slotGo.transform.localEulerAngles = slotOpenEuler;
}
public override bool IsCompareTag(object data)
{
if (GameConfig.state == GameState.Unload)
{
ToolType toolType = ToolType.BoltDriver;
ToolItem item = (ToolItem)data;
if (item.toolType == toolType)
{
return true;
}
CoolPointTip("请使用合适的工具");
return false;
}
else
{
Grid grid = (Grid)data;
if(grid.type == _type)
{
return true;
}
CoolPointTip("请选择正确的零件");
return false;
}
}
public override void OnLoadAct()
{
base.OnLoadAct();
StartCoroutine(LoadFocuse());
}
public override void OnUnLoadAct()
{
base.OnUnLoadAct();
StartCoroutine(UnloadFocuse());
}
//扣锁检测层
public LayerMask checkLayer;
private RaycastHit hit;
private bool isHit01 = false;
private int onclick = 1;
protected override IEnumerator UnloadFocuse()
{
yield return StartCoroutine(ProgressFocuse());
lock01Go.SetActive(true);
isHit01 = false;
onclick = 1;
yield return StartCoroutine(curCpuAni.UnloadFanProgress());
unLoadTipGo.SetActive(true);
while (true)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 50, checkLayer.value))
{
if (hit.collider.gameObject.name.Contains("lock01"))
{
isHit01 = true;
//Debug.LogFormat(">>>>>>>>>>>> hit go {0}", hit.collider.gameObject.tag);
}
}
if (onclick == 0)
{
break;
}
yield return new WaitForEndOfFrame();
}
yield return new WaitForSeconds(0.25f);
slotGo.transform.DOLocalRotate(slotOpenEuler,0.4f);
yield return new WaitForSeconds(0.5f);
unLoadTipGo.SetActive(false);
yield return StartCoroutine(curCpuAni.UnloadCpuProgress());
OnUnLoadFinishHandle?.Invoke();
mainGo.SetActive(false);
RewindCameraView();
}
protected override IEnumerator LoadFocuse()
{
yield return StartCoroutine(ProgressFocuse());
lock01Go.SetActive(true);
isHit01 = false;
onclick = 1;
buckleGo.SetActive(true);
mainGo.SetActive(true);
yield return StartCoroutine(curCpuAni.LoadCpuProgress());
loadTipGo.SetActive(true);
while (true)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 50, checkLayer.value))
{
if (hit.collider.gameObject.name.Contains("lock01"))
{
isHit01 = true;
}
}
if (onclick == 0)
{
break;
}
yield return new WaitForEndOfFrame();
}
loadTipGo.SetActive(false);
yield return new WaitForSeconds(0.25f);
slotGo.transform.DOLocalRotate(slotCloseEuler,0.45f);
yield return new WaitForSeconds(0.5f);
yield return StartCoroutine(curCpuAni.LoadFanProgress());
LzFramework.UI.TTUIPage.ShowPage<SparePartsView>();
OnLoadFinishHandle?.Invoke();
RewindCameraView();
}
}
}