using DefaultNamespace.ProcessMode; using DG.Tweening; using MotionFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 剥线钳 /// public class Pliers : MonoBehaviour { /// /// 剥线钳物体 /// public GameObject PliersObj; /// /// 剥线钳动画 /// public SkinnedMeshRenderer PliersSki; /// /// 柜门外封印动画 /// public SkinnedMeshRenderer ElectricBoxSkinnedMeshRenderer; /// /// 电箱里端子排右边封印 /// public SkinnedMeshRenderer RightSkinnedMeshRenderer; /// /// 电箱端子排里面左边封印 /// public SkinnedMeshRenderer LeftSkinnedMeshRenderer; /// /// 集中器盖右边封印 /// public SkinnedMeshRenderer RconcentratorSMR; /// /// 集中器盖左边封印 /// public SkinnedMeshRenderer LconcentratorSMR; /// /// 变电箱门锁 /// public Transform Doorlock; /// /// 变电箱左门 /// public Transform DoorOfCabinet; /// /// 是否在梯子上 /// bool Onladder ; /// /// 斜口钳钳开柜门封印位置 /// public Transform ElectricBoxTrans; /// /// 工具解绑的父物体 /// public GameObject PlayerCamera; /// /// 斜口钳的原始位置 /// private Vector3 originalPosition; /// /// 工具的原始旋转 /// private Quaternion originalRotation; void Start() { Init(); } /// /// 初始化 /// void Init() { PliersSki.SetBlendShapeWeight(0, 0); //PliersAni.Play("线钳"); originalPosition = PliersObj.transform.position; } void Update() { //判断在梯子上 if (!Onladder) { 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 == "柜门_封印") { PliersObj.gameObject.transform.SetParent(null); StartCoroutine(PliersIE()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "接线盒_封印R") { StartCoroutine(JunctionBoxRight()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "接线盒_封印L") { StartCoroutine(JunctionBoxLeft()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "集中器_封印R") { StartCoroutine(RightRconcentrator()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "集中器_封印_L") { StartCoroutine(LeftRconcentrator()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } } } } } float weight; /// /// 剥线钳动画 /// /// IEnumerator PliersIE() { PliersObj.gameObject.transform.position = ElectricBoxTrans.gameObject.transform.position; yield return new WaitForSeconds(1f); //PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90,90,0),1.5f); //yield return new WaitForSeconds(2f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.1f); //PliersObj.gameObject.transform.SetParent(PlayerCamera.transform); StartCoroutine(OpenLock()); } /// /// 打开柜门封印动画 /// /// IEnumerator OpenLock() { for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.001f); ElectricBoxSkinnedMeshRenderer.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.1f); ElectricBoxSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.637f, 0.12f, -0.015f), 0.5f); yield return new WaitForSeconds(1f); ElectricBoxSkinnedMeshRenderer.gameObject.SetActive(false); gameObject.transform.Find("变电箱_门").GetComponent().enabled = false; StartCoroutine(OpenDoor()); } /// /// 电箱门动画 /// /// IEnumerator OpenDoor() { //yield return new WaitForSeconds(0.5f); Doorlock.transform.DOLocalRotate(new Vector3(160, 0, 0), 1f); yield return new WaitForSeconds(1.5f); DoorOfCabinet.transform.DOLocalRotate(new Vector3(-90, 0, 160), 2f); StartCoroutine(PliersBack()); } /// /// 剥线钳返回原点动画 /// /// IEnumerator PliersBack() { PliersObj.gameObject.transform.SetParent(PlayerCamera.transform); yield return new WaitForSeconds(0.5f); PliersObj.gameObject.transform.position = originalPosition; PliersObj.gameObject.transform.rotation = originalRotation; //PliersObj.gameObject.transform.DOLocalMove(new Vector3(303.05f, 2.386f, 163.028f),1f); PliersObj.gameObject.transform.DORotate(new Vector3(0,90,0),1f); yield return new WaitForSeconds(1.5f); //PliersObj.gameObject.SetActive(false); } /// /// 接线盒右边封印 /// /// IEnumerator JunctionBoxRight() { PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f); yield return new WaitForSeconds(1f); PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1497f, 1.888f, -1.3079f), 0.5f); yield return new WaitForSeconds(1f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.5f); for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.001f); RightSkinnedMeshRenderer.SetBlendShapeWeight(0, i); } RightSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(0.0746f, 0.0004f, -0.0416f), 1f); yield return new WaitForSeconds(1.5f); StartCoroutine(PliersBack()); RightSkinnedMeshRenderer.gameObject.SetActive(false); // Destroy(RightSkinnedMeshRenderer); } /// /// 接线盒左边封印 /// /// IEnumerator JunctionBoxLeft() { //PliersObj.gameObject.SetActive(true); PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f); yield return new WaitForSeconds(0.8f); PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1672f, 1.8637f, -1.4392f), 1f); yield return new WaitForSeconds(1.5f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(1f); for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.001f); LeftSkinnedMeshRenderer.SetBlendShapeWeight(0, i); } LeftSkinnedMeshRenderer.gameObject.transform.DOLocalMove(new Vector3(-0.0744f, -0.0247f, -0.043f), 0.5f); yield return new WaitForSeconds(1f); StartCoroutine(PliersBack()); LeftSkinnedMeshRenderer.gameObject.SetActive(false); //Destroy(LeftSkinnedMeshRenderer); } /// /// 集中器右边封印 /// /// IEnumerator RightRconcentrator() { PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f); yield return new WaitForSeconds(1.2f); PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1687f, 2.1218f, -1.4082f), 1f); yield return new WaitForSeconds(1f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(1f); for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.001f); RconcentratorSMR.SetBlendShapeWeight(0, i); } RconcentratorSMR.gameObject.transform.DOLocalMove(new Vector3(-0.066f, 0.0611f, -0.1134f), 0.5f); yield return new WaitForSeconds(1f); StartCoroutine(PliersBack()); RconcentratorSMR.gameObject.SetActive(false); } /// /// 集中器左边封印 /// /// IEnumerator LeftRconcentrator() { PliersObj.gameObject.transform.DOLocalRotate(new Vector3(-90, 90, 0), 0.5f); yield return new WaitForSeconds(1.2f); PliersObj.gameObject.transform.DOLocalMove(new Vector3(3.1683f, 2.1293f, -1.5439f), 1f); yield return new WaitForSeconds(1f); for (int i = 100; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(1f); for (int i = 0; i < 100; i++) { yield return new WaitForSeconds(0.001f); LconcentratorSMR.SetBlendShapeWeight(0, i); } LconcentratorSMR.gameObject.transform.DOLocalMove(new Vector3(-0.0659f, 0.0829f, -0.1134f), 0.5f); yield return new WaitForSeconds(1f); StartCoroutine(PliersBack()); LconcentratorSMR.gameObject.SetActive(false); } }