using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using ZenFulcrum.EmbeddedBrowser; public class StopValve : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler { private Vector3 start = new Vector3(0, 0, -80); //滑动点到阀门图片中点的向量 private Vector3 v1; [SerializeField] private Image stopValveImage; //截止阀 public float timeCount = 0; public float limitTime = 0; public int index; //阀门旋转多少圈可以开到100 public Vector2 currentPos = new Vector2(); int sum = 80; void OnEnable() { //UIManager.ins.ButtonToUI_but(true, confirm, popup); //AudioManager.ins.PlayAudio(7); //StartCoroutine(Deng()); } /// /// 开始拖拽 /// /// public void OnBeginDrag(PointerEventData eventData) { v1 = start - stopValveImage.transform.position; currentPos = eventData.position; } /// /// 拖拽中 /// /// public void OnDrag(PointerEventData eventData) { timeCount += Time.deltaTime; if (timeCount > limitTime) { if (currentPos.x - eventData.position.x > 0) { sum += 10; } if (currentPos.x - eventData.position.x < 0) { sum += -10; } Debug.Log("旋转的方法"); Deng(sum); timeCount = 0; } } void Deng(float angle) { //stopValveImage.transform.Rotate(new Vector3(0, 0, angle)); float z = Mathf.Clamp(angle, -80, 80); stopValveImage.transform.eulerAngles = new Vector3(0, 0, z); //stopValveImage.transform.Rotate(new Vector3(0, 0, z)); Debug.Log(z); } /// /// 拖拽结束 /// /// public void OnEndDrag(PointerEventData eventData) { timeCount = 0; } }