using DefaultNamespace.ProcessMode; using DG.Tweening; using MotionFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 剥线钳 /// public class Pliers : MonoBehaviour { [Header("剥线钳物体")] /// /// 剥线钳物体 /// public GameObject PliersObj; [Header("剥线钳动画")] /// /// 剥线钳动画 /// public SkinnedMeshRenderer PliersSki; [Header("柜门外封印动画")] /// /// 柜门外封印动画 /// public SkinnedMeshRenderer ElectricBoxSkinnedMeshRenderer; [Header("电箱里端子排右边封印")] /// /// 电箱里端子排右边封印 /// public SkinnedMeshRenderer RightSkinnedMeshRenderer; [Header("电箱端子排里面左边封印")] /// /// 电箱端子排里面左边封印 /// public SkinnedMeshRenderer LeftSkinnedMeshRenderer; [Header("集中器盖右边封印")] /// /// 集中器盖右边封印 /// public SkinnedMeshRenderer RconcentratorSMR; [Header("集中器盖左边封印")] /// /// 集中器盖左边封印 /// public SkinnedMeshRenderer LconcentratorSMR; [Header("变电箱门锁")] /// /// 变电箱门锁 /// public Transform Doorlock; [Header("工具解绑的父物体")] /// /// 工具解绑的父物体 /// public GameObject PlayerCamera; [Header("变电箱左门")] /// /// 变电箱左门 /// public Transform DoorOfCabinet; [Header("是否在梯子上")] /// /// 是否在梯子上 /// bool Onladder ; [Header("斜口钳钳开每个封印位置")] /// /// 斜口钳钳开每个封印位置 /// public Transform[] InteractivePliersTrans; [Header("斜口钳的原始位置")] /// /// 斜口钳的原始位置 /// private Vector3 originalPosition; [Header(" 斜口钳的原始旋转")] /// /// 斜口钳的原始旋转 /// private Quaternion originalRotation; void Start() { Init(); } /// /// 初始化 /// void Init() { PliersSki.SetBlendShapeWeight(0, 100); //PliersAni.Play("线钳"); originalPosition = PliersObj.transform.localPosition; originalRotation = PliersObj.transform.localRotation; } 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") { PliersObj.gameObject.transform.SetParent(null); StartCoroutine(JunctionBoxRight()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "接线盒_封印L") { PliersObj.gameObject.transform.SetParent(null); StartCoroutine(JunctionBoxLeft()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "集中器_封印R") { PliersObj.gameObject.transform.SetParent(null); StartCoroutine(RightRconcentrator()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } if (hit.collider.gameObject.name == "集中器_封印_L") { PliersObj.gameObject.transform.SetParent(null); StartCoroutine(LeftRconcentrator()); Debug.Log(hit.collider.gameObject.name); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } } } } } float weight; /// /// 剥线钳动画 /// /// IEnumerator PliersIE() { //PliersObj.gameObject.transform.position = InteractivePliersTrans[0].gameObject.transform.position; PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[0].gameObject.transform.position, InteractivePliersTrans[3].gameObject.transform.rotation); 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); DoorOfCabinet.gameObject.GetComponent().enabled = 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.localPosition = originalPosition; PliersObj.gameObject.transform.localRotation = originalRotation; PliersSki.SetBlendShapeWeight(0, 100); //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.position = InteractivePliersTrans[1].gameObject.transform.position; PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[1].gameObject.transform.position, InteractivePliersTrans[1].gameObject.transform.rotation); //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 = 25; i >= 0; i--)//更改斜口钳开口速度改i的值,越小越快 { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.1f); 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), 0.5f); yield return new WaitForSeconds(1.5f); StartCoroutine(PliersBack()); RightSkinnedMeshRenderer.gameObject.SetActive(false); // Destroy(RightSkinnedMeshRenderer); } /// /// 接线盒左边封印 /// /// IEnumerator JunctionBoxLeft() { // PliersObj.gameObject.transform.position = InteractivePliersTrans[2].gameObject.transform.position; PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[2].gameObject.transform.position, InteractivePliersTrans[2].gameObject.transform.rotation); //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(1f); for (int i = 25; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.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.position = InteractivePliersTrans[3].gameObject.transform.position; //PliersObj.gameObject.transform.rotation = InteractivePliersTrans[3].gameObject.transform.rotation; PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[3].gameObject.transform.position, InteractivePliersTrans[3].gameObject.transform.rotation); //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 = 25; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.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.1151f, 0.0243f, -0.1134f), 0.5f); yield return new WaitForSeconds(1f); StartCoroutine(PliersBack()); RconcentratorSMR.gameObject.SetActive(false); } /// /// 旧集中器左边封印 /// /// IEnumerator LeftRconcentrator() { //PliersObj.gameObject.transform.position = InteractivePliersTrans[4].gameObject.transform.position; PliersObj.gameObject.transform.SetPositionAndRotation(InteractivePliersTrans[4].gameObject.transform.position, InteractivePliersTrans[4].gameObject.transform.rotation); //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 = 25; i >= 0; i--) { yield return new WaitForSeconds(0.001f); PliersSki.SetBlendShapeWeight(0, i); } yield return new WaitForSeconds(0.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); } }