Files
MI-38/Heli_with_panels/Assets/Scripts/Panel2D/0115/ArrowToText.cs
2022-07-04 13:15:35 +03:00

187 lines
4.6 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ArrowToText : MonoBehaviour//frame1 0115
{
public GameObject arrow;//стрелочка на шкале
//public Text speed;//счетчик
public TextMeshPro speed;//счетчик
public GameObject frame;//цветная рамка
float rotateZ; //предыдущее значение rotateZ
float d, d1; //коэффициенты d (0-100), d1 (100-350)
float k; //текущее значение счетчика в float
bool reverse = false; //направление
(int scale,int count) min = ( 0, 40 );//минимальное значение счетчика
int max = 350;//максимальное значение счетчика
float waitTime = 0.005f;//время для корутины
bool point = false;//нажатие на счетчик
private Coroutine coroutine;
private void Start()
{
//Debug.Log($"min.Item1 = {min.scale}");
d = 100 / (125-112);
d1 = 4.7f;
OnK();
scaleText();
Rever();
}
private void Update()
{
if (rotateZ != arrow.gameObject.transform.eulerAngles.z)
{
ref readonly bool dragArrow = ref arrow.gameObject.GetComponent<Handler>().drag;
if (dragArrow)
{
if (coroutine != null)
{
StopCoroutine(coroutine);
point = false;
}
OnK();
scaleText();
Rever();
}
}
}
private void scaleText()
{
int ko = (int)k;
if (ko <320)
{
speed.color = Color.white;
if (frame.gameObject.GetComponent<ButtonCheckable3>() != null)
{
frame.gameObject.GetComponent<ButtonCheckable3>().EnableSprite(0);
}
}
else
{
speed.color = Color.red;
if (frame.gameObject.GetComponent<ButtonCheckable3>() != null)
{
frame.gameObject.GetComponent<ButtonCheckable3>().EnableSprite(1);
}
}
ko = ko / 10 * 10;
if (ko < min.count)
{
//speed.text = "";
speed.SetText("");
}
else
{
//speed.text = ko.ToString();
speed.SetText(ko.ToString());
}
}
private void OnK()
{
rotateZ = arrow.gameObject.transform.eulerAngles.z;
if(rotateZ > 111)
{
//Debug.Log($"здесь до 100");
k = (125 - rotateZ) * d;
}
if (rotateZ < 111&& rotateZ != 111)
{
//Debug.Log($"здесь после 100");
k = (90 - rotateZ) * d1+200;
}
if (rotateZ > 110.4&&rotateZ< 111.4)
{
//Debug.Log($"111 = 100");
k = 100f;
}
}
private void OnMouseDown()//нажатие на счетчик
{
//Debug.Log("кликнули");
point = !point;
if (point)
{
Rever();
if (reverse)
{
k--;
coroutine = StartCoroutine(AltNumber());
}
else
{
k++;
coroutine = StartCoroutine(AltNumber());
}
}
else
{
if (coroutine != null) StopCoroutine(coroutine);
}
}
private void Rever()
{
if (k <= min.scale)
{
reverse = false;
}
else if (k >= max)
{
reverse = true;
}
}
IEnumerator AltNumber()
{
while (point)
{
scaleText();
if (k<100)
{
//Debug.Log($"здесь до 100");
rotateZ = 125f - k / d;
}
if (k>100)
{
//Debug.Log($"здесь после 100");
rotateZ = 90 - (k - 200) / d1;
}
if (k >99&&k<101)
{
//Debug.Log($"111 = 100");
rotateZ =111;
}
arrow.gameObject.transform.localRotation = Quaternion.Euler(0f, 0f, rotateZ);
if (reverse)
{
k--;
}
else
{
k++;
}
Rever();
yield return new WaitForSeconds(waitTime);
}
}
}