using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using System; namespace DisComputer { /* * @func 显卡动画 * * */ public class XianKaAnimation : 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; public GameObject lock01Go; public Transform lousiTran; public Vector3 lousiShowPos; // 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() { mainGo.SetActive(true); buckleGo.SetActive(true); unloadTipGo.SetActive(false); loadTipGo.SetActive(false); mainGo.transform.localPosition = mainInitPos; buckleGo.transform.localEulerAngles = closeEuler; lousiTran.gameObject.SetActive(true); lousiTran.localPosition = Vector3.zero; } public override void SetUnloadState() { mainGo.SetActive(false); buckleGo.SetActive(true); unloadTipGo.SetActive(false); loadTipGo.SetActive(false); mainGo.transform.localPosition = mainShowPos; buckleGo.transform.localEulerAngles = openEuler; lousiTran.gameObject.SetActive(false); lousiTran.localPosition = lousiShowPos; } 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 != null) { 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()); BoltDriver driver = lousiTran.GetComponent(); yield return StartCoroutine(driver.RotationLouSi()); lousiTran.DOLocalMove(lousiShowPos, 0.5f); unloadTipGo.SetActive(true); lock01Go.SetActive(true); isHit01 = false; onclick = 1; 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(); } yield return new WaitForSeconds(0.5f); unloadTipGo.SetActive(false); mainGo.transform.DOLocalMove(mainShowPos, 0.5f).SetDelay(0.45f).SetEase(Ease.OutQuart).OnComplete(() => { CommonTool.WaitTimeAfterDo(this, 0.350f, () => { OnUnLoadFinishHandle?.Invoke(); mainGo.SetActive(false); lousiTran.gameObject.SetActive(false); RewindCameraView(); }); }); } protected override IEnumerator LoadFocuse() { yield return StartCoroutine(ProgressFocuse()); lock01Go.SetActive(true); isHit01 = false; onclick = 1; buckleGo.SetActive(true); mainGo.SetActive(true); mainGo.transform.DOLocalMove(mainInitPos, 0.5f).SetEase(Ease.Linear).OnComplete(() => { }); yield return new WaitForSeconds(1.0f); lousiTran.gameObject.SetActive(true); lousiTran.DOLocalMove(Vector3.zero,0.5f); yield return new WaitForSeconds(1.0f); BoltDriver driver = lousiTran.GetComponent(); yield return StartCoroutine(driver.RotationLouSi()); 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.5f); RewindCameraView(); LzFramework.UI.TTUIPage.ShowPage(); OnLoadFinishHandle?.Invoke(); } } }