using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; public class concentrator : MonoBehaviour { /// /// 集中器 /// public GameObject concentratorObj; /// /// 集中器端子螺丝 /// public GameObject[] ScrewObj; /// /// 集线盒电线动画 /// public SkinnedMeshRenderer ElectricWireSMR; /// /// 电线碰撞 /// public BoxCollider TapeMarCol; /// /// 电线前段胶带 /// public Material TapeMar; /// /// 螺丝是否全部显示 /// int allls; /// /// 是否播放集线器螺丝拆完后电线动画 /// public static bool isPlayAni = true; bool isplaying = true; // Start is called before the first frame update void Start() { } // 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 == "新的集中器碰撞") { StartCoroutine(Newconcentrator()); Debug.Log(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 (hit.collider.gameObject.name == "pCylinder170") { if (isplaying) { StartCoroutine(IEElectricWire()); isplaying = false; } } } } if (AreAllObjectsHidden()) { isPlayAni = false; StartCoroutine(TapeBack()); Debug.Log("所有螺丝都显示"); } } /// /// 新集中器螺丝 /// /// public bool AreAllObjectsHidden() { allls = 0; for (int i = 0; i < ScrewObj.Length; i++) { if (ScrewObj[i].gameObject.GetComponent().enabled) { allls++; } } if (allls >= ScrewObj.Length - 1) { return true; } else { return false; } } /// /// 集线器上线动画 /// /// IEnumerator Newconcentrator() { concentratorObj.gameObject.transform.DOLocalMove(new Vector3(3.0778f, 2.2149f, -1.4581f), 1f); yield return new WaitForSeconds(1.0f); } /// /// 集线器上线动画 /// /// IEnumerator IEElectricWire() { TapeMarCol.enabled = false; for (int i = 0; i < 6; i++) { for (int a = 100; a >= 0; a--) { yield return new WaitForSeconds(0.01f); ElectricWireSMR.SetBlendShapeWeight(i, a); } } } /// /// 胶带还原动画 /// /// IEnumerator TapeBack() { TapeMarCol.enabled = true; 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); } }