using DefaultNamespace.ProcessMode; using DG.Tweening; using MotionFramework; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; /// /// 绝缘胶带 /// public class AdhesiveTape : MonoBehaviour { [Header("绝缘胶带")] /// /// 绝缘胶带 /// public GameObject TapeOBJ; [Header("电线前段胶带")] /// /// 电线前段胶带 /// public Material TapeMar; [Header("电线碰撞")] /// /// 电线碰撞 /// public BoxCollider TapeMarCol; [Header("胶带使用后位置")] /// /// 胶带使用后位置 /// public Transform TapeTrans; [Header("父物体玩家相机坐标")] /// /// 父物体玩家相机坐标 /// public Transform PlayerCamera; [Header("斜口钳的原始位置")] /// /// 斜口钳的原始位置 /// private Vector3 originalPosition; [Header("斜口钳的原始旋转")] /// /// 斜口钳的原始旋转 /// private Quaternion originalRotation; // Start is called before the first frame update void Start() { Init(); } void Init() { originalPosition = TapeOBJ.transform.localPosition; originalRotation = TapeOBJ.transform.localRotation; TapeMar.SetFloat("_step_p1", 0); TapeMar.SetFloat("_step_p2", 0); TapeMar.SetFloat("_step_p3", 0); TapeMar.SetFloat("_step_p4", 0); TapeMar.SetFloat("_step_p5", 0); TapeMar.SetFloat("_step_p6", 0); } // Update is called once per frame void Update() { if (EventSystem.current.IsPointerOverGameObject()) return; 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 == "pCylinder170") { TapeOBJ.gameObject.transform.SetParent(null); TapeOBJ.gameObject.transform.SetPositionAndRotation(TapeTrans.position, TapeTrans.rotation); StartCoroutine(Tape()); MotionEngine.GetModule().HandleClick(hit.collider.gameObject.name); } } } } /// /// 电线缠胶带 /// /// IEnumerator Tape() { yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p1", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p2", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p3", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p4", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p5", 1); yield return new WaitForSeconds(1f); TapeMar.SetFloat("_step_p6", 1); yield return new WaitForSeconds(1f); StartCoroutine(TapeBack()); } /// /// 胶带返回动画 /// /// IEnumerator TapeBack() { TapeOBJ.gameObject.transform.SetParent(PlayerCamera.transform); yield return new WaitForSeconds(0.5f); TapeOBJ.gameObject.transform.localPosition = originalPosition; TapeOBJ.gameObject.transform.localRotation = originalRotation; TapeMarCol.enabled = false; yield return new WaitForSeconds(1f); } }