ShanxiKnowledgeBase/SXElectricalInspection/Assets/GuYuan/Interactive/StopValve.cs

133 lines
3.5 KiB
C#

using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class StopValve : MonoBehaviour, IBeginDragHandler, IEndDragHandler, /*IDragHandler,*/ IPointerClickHandler
{
private Vector3 start = new Vector3(0, 0, -80);
//滑动点到阀门图片中点的向量
[SerializeField] Image stopValveImage; //截止阀
public float timeCount = 0;
public float limitTime = 0;
public float linearMeasure;
public int index; //阀门旋转多少圈可以开到100
public Vector2 currentPos = new Vector2();
public Transform trans;
[SerializeField] int mix;
[SerializeField] int max;
[SerializeField] float X;//X或者特定轴要固定的
[SerializeField] int sum = 90;//初始位置
[SerializeField] int ZhuanSum;//要旋转一次的角度
void OnEnable()
{
//UIManager.ins.ButtonToUI_but(true, confirm, popup);
//AudioManager.ins.PlayAudio(7);
//StartCoroutine(Deng());
}
/// <summary>
/// 开始拖拽
/// </summary>
/// <param name="eventData"></param>
public void OnBeginDrag(PointerEventData eventData)
{
//currentPos = transform.position;
//sum = (int)linearMeasure;
}
///// <summary>
///// 拖拽中
///// </summary>
///// <param name="eventData"></param>
//public void OnDrag(PointerEventData eventData)
//{
// timeCount += Time.deltaTime;
// if (timeCount > limitTime)
// {
// float x = Input.GetAxis("Mouse X");
// float y = Input.GetAxis("Mouse Y");
// if (x != 0 || y != 0)
// {
// if (x > 0 || y > 0)
// {
// sum = ZhuanSum;
// }
// else if (x < 0 || y < 0)
// {
// sum = -ZhuanSum;
// }
// }
// Debug.Log("旋转的方法"+x+" "+y);
// Deng(sum);
// timeCount = 0;
// }
//}
void Update()
{
if (true)
{
}
}
void Deng(float angle)
{
float z = Mathf.Clamp(angle, mix, max);
stopValveImage.transform.eulerAngles = new Vector3(0, 0, z);
linearMeasure = z;
if (transform.name.Equals("万用表"))
{
trans.DOLocalRotate(new Vector3(X, 0, ~(int)z), 0.01f);
}
else
{
trans.DOLocalRotate(new Vector3(X, ~(int)z, 0), 0.01f);
}
Debug.Log(Mathf.Clamp(~(int)z, mix, max));
}
/// <summary>
/// 拖拽结束
/// </summary>
/// <param name="eventData"></param>
public void OnEndDrag(PointerEventData eventData)
{
timeCount = 0;
}
public void OnPointerClick(PointerEventData eventData)
{
//timeCount += Time.deltaTime;
//if (timeCount > limitTime)
//{
//float x = Input.GetAxis("Mouse X");
//float y = Input.GetAxis("Mouse Y");
//if (x != 0 || y != 0)
//{
// if (x > 0 || y > 0)
// {
// sum = ZhuanSum;
// }
// else if (x < 0 || y < 0)
// {
// sum = -ZhuanSum;
// }
//}
//Debug.Log("旋转的方法" + x + " " + y);
//Deng(sum);
int z = (int)linearMeasure;
if (z % max != 0)
{
z += ZhuanSum;
}
else
{
z = mix;
}
Deng(z);
// timeCount = 0;
//}
}
}