using DefaultNamespace.ProcessMode; using DG.Tweening; using MotionFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; /// /// 集中器 /// public class concentrator : MonoBehaviour { [Header("集中器")] /// /// 集中器 /// public GameObject ConcentratorObj; [Header("集线盒电线动画")] /// /// 集线盒电线动画 /// public SkinnedMeshRenderer ElectricWireSMR; [Header("电线碰撞")] /// /// 电线碰撞 /// public BoxCollider TapeMarCol; [Header("电线前段胶带材质动画")] /// /// 电线前段胶带材质动画 /// public Material TapeMar; /// /// 螺丝是否全部显示 /// int allls; [Header("是否播放集线器螺丝拆完后电线动画")] /// /// 是否播放集线器螺丝拆完后电线动画 /// public static bool isPlayAni = true; [Header("集中器盖子")] /// /// 集中器盖子 /// public GameObject Cover; [Header("新集中器在电箱中的位置")] /// /// 新集中器在电箱中的位置 /// public Transform oncentratorTrans; [Header("新集中器盖子上左右两颗螺丝")] /// /// 新集中器盖子上左右两颗螺丝 /// public GameObject[] screw; [Header("集中器端子螺丝")] /// /// 集中器端子螺丝 /// public GameObject[] ScrewObj; public GameObject 透明盖子封印碰撞R; public GameObject 透明盖子封印碰撞L; bool isplaying = true; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (EventSystem.current.IsPointerOverGameObject()) return; if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool raycast = Physics.Raycast(ray, out hit); if (raycast) { if (hit.collider.gameObject.name == "新的集中器碰撞") { ConcentratorObj.gameObject.transform.SetParent(null); StartCoroutine(Newconcentrator()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); 透明盖子封印碰撞R.GetComponent().enabled = true; 透明盖子封印碰撞L.GetComponent().enabled = true; } if (hit.collider.gameObject.name == "JZQ_螺丝1") { StartCoroutine(TapeBackFrist()); ScrewObj[0].GetComponent().enabled = true; ScrewObj[1].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } else if (hit.collider.gameObject.name == "JZQ_螺丝2") { StartCoroutine(TapeBackSecond()); ScrewObj[2].GetComponent().enabled = true; ScrewObj[3].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } else if (hit.collider.gameObject.name == "JZQ_螺丝3") { StartCoroutine(TapeBackThird()); ScrewObj[4].GetComponent().enabled = true; ScrewObj[5].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } else if (hit.collider.gameObject.name == "JZQ_螺丝4") { StartCoroutine(TapeBackFourth()); ScrewObj[6].GetComponent().enabled = true; ScrewObj[7].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } else if (hit.collider.gameObject.name == "JZQ_螺丝6") { StartCoroutine(TapeBackFifth()); ScrewObj[8].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } else if (hit.collider.gameObject.name == "JZQ_螺丝7") { StartCoroutine(TapeBackSixth()); ScrewObj[9].GetComponent().enabled = true; MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } // for (int i = 0; i < ScrewObj.Length; i++) // { // if (hit.collider.gameObject.name == ScrewObj[i].name) // { // Debug.Log(hit.collider.gameObject.name); // //StartCoroutine(IEHubSegmentRowScrews()); // ScrewObj[i].GetComponent().enabled = true; // if (ScrewObj[0].GetComponent().enabled & ScrewObj[1].GetComponent().enabled) // { // StartCoroutine(TapeBackFrist()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // if (ScrewObj[2].GetComponent().enabled & ScrewObj[3].GetComponent().enabled) // { // StartCoroutine(TapeBackSecond()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // if (ScrewObj[4].GetComponent().enabled & ScrewObj[5].GetComponent().enabled) // { // StartCoroutine(TapeBackThird()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // if (ScrewObj[6].GetComponent().enabled & ScrewObj[7].GetComponent().enabled) // { // StartCoroutine(TapeBackFourth()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // if (ScrewObj[8].GetComponent().enabled) // { // StartCoroutine(TapeBackFifth()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // if (ScrewObj[9].GetComponent().enabled) // { // StartCoroutine(TapeBackSixth()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } // } // } if (AreAllObjectsHidden()) { isPlayAni = false; //StartCoroutine(IEElectricWire()); //MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // Debug.Log("所有螺丝都显示"); } // if (hit.collider.gameObject.name == "JZQ_螺丝007") // { // MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // } //if (hit.collider.gameObject.name == "pCylinder170") //{ // if (isplaying) // { // StartCoroutine(IEElectricWire());// MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); // isplaying = false; // } //} } } } /// /// 新集中器螺丝全部安装上 /// /// public bool AreAllObjectsHidden() { allls = 0; for (int i = 0; i < ScrewObj.Length; i++) { if (ScrewObj[i].gameObject.GetComponent().enabled == true) { //StartCoroutine(IEElectricWire()); allls++; } } if (allls >= ScrewObj.Length) { StartCoroutine(IEElectricWire()); return true; } else { return false; } } /// /// 新集中器更换动画 /// /// IEnumerator Newconcentrator() { ConcentratorObj.gameObject.transform.DOLocalMove(oncentratorTrans.gameObject.transform.localPosition, 1f); //3.0778f, 2.2149f, -1.4581f yield return new WaitForSeconds(1f); } /// /// 集中器盖子后续动画 /// /// IEnumerator IEElectricWire() { TapeMarCol.enabled = false; yield return new WaitForSeconds(1f); Cover.gameObject.SetActive(true); yield return new WaitForSeconds(0.5f); Cover.gameObject.transform.DOLocalMove(new Vector3(0, 0.01672375f, -0.09654188f), 1f); yield return new WaitForSeconds(1.1f); screw[0].gameObject.SetActive(true); yield return new WaitForSeconds(1.0f); screw[1].gameObject.SetActive(true); } /// /// 第一个螺丝和第二个安装完成后卸下胶带和电线安装的动画 /// /// IEnumerator TapeBackFrist() { TapeMar.SetFloat("_step_p1", 0); if (ElectricWireSMR.GetBlendShapeWeight(0) != 0 && ElectricWireSMR.GetBlendShapeWeight(0) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(0, i); } } } IEnumerator TapeBackSecond() { TapeMar.SetFloat("_step_p2", 0); if (ElectricWireSMR.GetBlendShapeWeight(1) != 0 && ElectricWireSMR.GetBlendShapeWeight(1) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(1, i); } } } IEnumerator TapeBackThird() { TapeMar.SetFloat("_step_p3", 0); if (ElectricWireSMR.GetBlendShapeWeight(2) != 0 && ElectricWireSMR.GetBlendShapeWeight(2) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(2, i); } } } IEnumerator TapeBackFourth() { TapeMar.SetFloat("_step_p4", 0); if (ElectricWireSMR.GetBlendShapeWeight(3) != 0 && ElectricWireSMR.GetBlendShapeWeight(3) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(3, i); } } } IEnumerator TapeBackFifth() { TapeMar.SetFloat("_step_p5", 0); if (ElectricWireSMR.GetBlendShapeWeight(4) != 0 && ElectricWireSMR.GetBlendShapeWeight(4) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(4, i); } } } IEnumerator TapeBackSixth() { TapeMar.SetFloat("_step_p6", 0); if (ElectricWireSMR.GetBlendShapeWeight(5) != 0 && ElectricWireSMR.GetBlendShapeWeight(5) == 100) { for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(5, i); } } } /// /// 胶带还原&和电线还原动画 /// /// //IEnumerator IETapeBackFrist() //{ // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p6", 0); // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p5", 0); // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p4", 0); // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p3", 0); // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p2", 0); // yield return new WaitForSeconds(1f); // TapeMar.SetFloat("_step_p1", 0); // yield return new WaitForSeconds(1f); //} }