82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
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 end;
|
|
private Vector3 start = new Vector3(0, 0, -80);
|
|
//滑动点到阀门图片中点的向量
|
|
private Vector3 v1;
|
|
private Vector3 v2;
|
|
private float al;
|
|
[SerializeField] private Image stopValveImage; //截止阀
|
|
Vector2 tempPos;
|
|
|
|
private float valveOpen; //阀门开度
|
|
public int index; //阀门旋转多少圈可以开到100
|
|
int sum = 80;
|
|
void OnEnable()
|
|
{
|
|
//UIManager.ins.ButtonToUI_but(true, confirm, popup);
|
|
//AudioManager.ins.PlayAudio(7);
|
|
//StartCoroutine(Deng());
|
|
}
|
|
/// <summary>
|
|
/// 开始拖拽
|
|
/// </summary>
|
|
/// <param name="eventData"></param>
|
|
public Vector2 currentPos = new Vector2();
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
v1 = start - stopValveImage.transform.position;
|
|
currentPos = eventData.position;
|
|
}
|
|
public float timeCount = 0;
|
|
public float limitTime = 0;
|
|
/// <summary>
|
|
/// 拖拽中
|
|
/// </summary>
|
|
/// <param name="eventData"></param>
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
timeCount += Time.deltaTime;
|
|
if (timeCount > limitTime)
|
|
{
|
|
Debug.Log(currentPos.x-eventData.position.x);
|
|
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)
|
|
{
|
|
float Temp = Math.Clamp(angle,-80,80);
|
|
stopValveImage.transform.Rotate(new Vector3(0,0, Temp));
|
|
}
|
|
/// <summary>
|
|
/// 拖拽结束
|
|
/// </summary>
|
|
/// <param name="eventData"></param>
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
timeCount = 0;
|
|
}
|
|
}
|