using DG.Tweening; using System.Collections; using System.Collections.Generic; using DefaultNamespace.ProcessMode; using MotionFramework; using UnityEngine; /// /// 螺丝刀 /// public class Screwdriver : MonoBehaviour { /// /// 螺丝刀坐标 /// public Transform ScrewdriverTrans; /// /// 右边螺丝 /// public GameObject ScrewR; /// /// 左边螺丝 /// public GameObject ScrewL; /// /// 集中器左侧螺丝 /// public GameObject LconcentratorScrew; /// /// 集中器右侧螺丝 /// public GameObject RconcentratorScrew; /// /// 集线器螺丝和封印 /// public GameObject[] concentratorScrew; /// /// 螺丝 /// a public GameObject[] ScrewObj; /// /// 集线盒电线动画 /// public SkinnedMeshRenderer ElectricWireSMR; /// /// 集中器盖子 /// public GameObject HubCoverObj; public InteractiveObjects[] interactiveObjects; /// /// 拆完封印 /// bool issplit; // Start is called before the first frame update void Start() { //StartCoroutine(IEElectricWire()); } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) {//Camera.transform.forward Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool raycast = Physics.Raycast(ray, out hit); if (raycast) { if (hit.collider.gameObject.name == "盖_固定螺丝_Rup") { StartCoroutine(Rscrew()); Debug.Log(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "固定螺丝_Ldown") { StartCoroutine(Lscrew()); Debug.Log(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "壳固定螺丝_R") { Debug.Log(hit.collider.gameObject.name); StartCoroutine(IERconcentratorScrew()); } if (hit.collider.gameObject.name == "壳固定螺丝_L") { Debug.Log(hit.collider.gameObject.name); StartCoroutine(IELconcentratorScrew()); } for (int i = 0; i < ScrewObj.Length; i++) { if (hit.collider.gameObject.name == ScrewObj[i].name) { Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject); ScrewObj[i].gameObject.SetActive(false); } //if (!ScrewObj[i].gameObject.activeInHierarchy) //{ // StartCoroutine(IEElectricWire()); //} } } } if (AreAllObjectsHidden()) { StartCoroutine(IEElectricWire()); Debug.Log("所有螺丝都已隐藏"); } if (AllHubOfHubs()) { HubCoverObj.gameObject.SetActive(false); Debug.Log("所有集线器盖子螺丝都已隐藏"); } } // 调用这个方法来检查所有游戏对象是否都被隐藏 // 获取所有游戏对象 // public GameObject[] allObjects = FindObjectsOfType(); public bool AreAllObjectsHidden() { // 检查每个对象的激活状态 foreach (GameObject obj in ScrewObj) { if (obj.activeInHierarchy) // 使用 activeInHierarchy 如果你想检查对象是否在其父级结构中被激活 { return false; // 如果找到任何一个激活的对象,返回false } } return true; // 如果所有对象都未激活,返回true } /// /// 集中器盖子螺丝 /// /// public bool AllHubOfHubs() { // 检查每个对象的激活状态 foreach (GameObject obj in concentratorScrew) { if (obj.activeInHierarchy) // 使用 activeInHierarchy 如果你想检查对象是否在其父级结构中被激活 { return false; // 如果找到任何一个激活的对象,返回false } } return true; // 如果所有对象都未激活,返回true } /// /// 螺丝刀返回动画 /// /// IEnumerator ScrewdriverBack() { ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.274139f, 1.803738f, -1.191f), 1f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-90f, 0, 0), 1f); yield return new WaitForSeconds(2f); } /// /// 接线盒右边螺丝 /// /// IEnumerator Rscrew() { ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2373f, 1.8549f, -1.244f), 1f); yield return new WaitForSeconds(1); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.191f, 1.831f, -1.158f), 1f); yield return new WaitForSeconds(2f); ScrewR.transform.DOLocalMove(new Vector3(0.1316f, 0.036f, 0.0034f), 1.5f); yield return new WaitForSeconds(3f); StartCoroutine(ScrewdriverBack()); ScrewR.gameObject.SetActive(false); } /// /// 接线盒左边螺丝 /// /// IEnumerator Lscrew() { ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2373f, 1.8284f, -1.3885f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f); yield return new WaitForSeconds(1.5f); ScrewL.transform.DOLocalMove(new Vector3(-0.07357633f, -0.01137948f, -0.0366f), 1f); yield return new WaitForSeconds(2f); StartCoroutine(ScrewdriverBack()); ScrewL.gameObject.SetActive(false); } /// /// 集中器右侧螺丝 /// /// IEnumerator IERconcentratorScrew() { ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2669f, 2.0962f, -1.3294f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f); yield return new WaitForSeconds(1.5f); RconcentratorScrew.transform.DOLocalMove(new Vector3(0.1143f, 0.0216f, -0.1031f), 1f); yield return new WaitForSeconds(0.5f); StartCoroutine(ScrewdriverBack()); RconcentratorScrew.gameObject.SetActive(false); } /// /// 集中器左侧螺丝 /// /// IEnumerator IELconcentratorScrew() { ScrewdriverTrans.transform.DOLocalMove(new Vector3(3.2669f, 2.0962f, -1.4616f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, -104.747f), 1f); yield return new WaitForSeconds(1.5f); ScrewdriverTrans.transform.DOLocalRotate(new Vector3(-19.741f, -113.296f, 90), 1f); yield return new WaitForSeconds(1.5f); LconcentratorScrew.transform.DOLocalMove(new Vector3(-0.1188f, 0.0216f, -0.1031f), 1f); yield return new WaitForSeconds(2f); StartCoroutine(ScrewdriverBack()); LconcentratorScrew.gameObject.SetActive(false); } /// /// 集线器螺丝拆完后电线动画 /// /// IEnumerator IEElectricWire() { //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.001f); ElectricWireSMR.SetBlendShapeWeight(0, i); } //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.002f); ElectricWireSMR.SetBlendShapeWeight(1, i); } //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.002f); ElectricWireSMR.SetBlendShapeWeight(2, i); } //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.002f); ElectricWireSMR.SetBlendShapeWeight(3, i); } //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.002f); ElectricWireSMR.SetBlendShapeWeight(4, i); } //yield return new WaitForSeconds(1f); for (int i = 0; i <= 100; i++) { yield return new WaitForSeconds(0.002f); ElectricWireSMR.SetBlendShapeWeight(5, i); } } }