mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 05:25:38 +03:00
04.07.2022
This commit is contained in:
170
Heli_with_panels/Assets/Scripts/Panel2D/0115/ScaleToText4.cs
Normal file
170
Heli_with_panels/Assets/Scripts/Panel2D/0115/ScaleToText4.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
//[AddComponentMenu("Transform/Follow Transform")]
|
||||
[RequireComponent(typeof(TextMeshPro))]
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class ScaleToText4 : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("Objects")]
|
||||
public GameObject scale;//шкала с которой связан счетчик
|
||||
public TextMeshPro countNumber;//счетчик
|
||||
public GameObject frame;//рамка
|
||||
[SerializeField] private GameObject Panel;// родительская панель
|
||||
|
||||
private float Y; // (оставила название) предыдущее значение изменяемой координаты, в данном случае y
|
||||
private float d; //коэффициент
|
||||
private float k; //текущее значение счетчика в float
|
||||
private bool reverse = false; //направление
|
||||
|
||||
[Header("Variables")]
|
||||
[SerializeField] private int min = -340;// минимальное значение счетчика для frame3 =-130
|
||||
[SerializeField] private int max = 340;// максимальное значение счетчика для frame3 =6760
|
||||
[SerializeField] private float deltaScale = 15f;// дельта шкалы для frame3 =3450
|
||||
[SerializeField] private float deltaCoorScale = 105f;// дельта координат шкалы (сколько юнитов координат в deltaScale) для frame3 =1800
|
||||
[SerializeField] private float startCoorScale = 1263f;// координаты шкалы для счетчика 0
|
||||
[Space(15)]
|
||||
[Tooltip("x or y")] [SerializeField] private string typeXY="y";// тип сериализуемый
|
||||
|
||||
|
||||
[Space(10)]
|
||||
[SerializeField] private float waitTime = 0.05f;//время для корутины
|
||||
[HideInInspector] public bool point = false;//нажатие на счетчик
|
||||
private Coroutine coroutine;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
countNumber = transform.GetComponent<TextMeshPro>();
|
||||
d = deltaCoorScale / deltaScale;//высчитывается дельта координат к дельте шкалы
|
||||
OnK();
|
||||
scaleText();
|
||||
Rever();
|
||||
waitTime = 0.005f;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if ((typeXY == "x"&&Y != scale.gameObject.transform.localPosition.x)|| (typeXY == "y" && Y != scale.gameObject.transform.localPosition.y))//проверка типа
|
||||
{
|
||||
OnK();
|
||||
scaleText();
|
||||
Rever();
|
||||
}
|
||||
}
|
||||
|
||||
private void scaleText()
|
||||
{
|
||||
//Debug.Log($"k = {k}");
|
||||
int ko = (int)k;
|
||||
//Debug.Log($"ko = {ko}");
|
||||
if (typeXY == "y" && Panel.transform.name == "Panel0115")//проверка типа начало
|
||||
{
|
||||
if (ko >= 0)
|
||||
{
|
||||
countNumber.color = Color.white;
|
||||
if (frame.gameObject.GetComponent<ButtonCheckable3>() != null)
|
||||
{
|
||||
frame.gameObject.GetComponent<ButtonCheckable3>().EnableSprite(0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
countNumber.color = Color.yellow;
|
||||
if (frame.gameObject.GetComponent<ButtonCheckable3>() != null)
|
||||
{
|
||||
frame.gameObject.GetComponent<ButtonCheckable3>().EnableSprite(1);
|
||||
}
|
||||
|
||||
}
|
||||
if (ko > 100 || ko < -100)
|
||||
{
|
||||
ko = ko / 10 * 10;
|
||||
}
|
||||
} else if (typeXY == "x" && Panel.transform.name == "Panel0115"){
|
||||
if (ko < 0)
|
||||
{
|
||||
ko = 360 + ko;
|
||||
}
|
||||
}
|
||||
//проверка типа конец
|
||||
// altitude.text = ko.ToString();
|
||||
countNumber.SetText(ko.ToString());
|
||||
}
|
||||
private void OnK()
|
||||
{
|
||||
Y = (typeXY == "x")? scale.gameObject.transform.localPosition.x: scale.gameObject.transform.localPosition.y;//проверка типа
|
||||
k = -(Y- startCoorScale) / d;//дельта
|
||||
}
|
||||
private void OnMouseDown()//нажатие на счетчик
|
||||
{
|
||||
/*point = !point;
|
||||
//Debug.Log($"point = {point}");
|
||||
if (point)
|
||||
{
|
||||
Rever();
|
||||
if (reverse)
|
||||
{
|
||||
k-=0.5f;
|
||||
coroutine = StartCoroutine(AltNumber());
|
||||
}
|
||||
else
|
||||
{
|
||||
k+=0.5f;
|
||||
coroutine = StartCoroutine(AltNumber());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (coroutine != null) StopCoroutine(coroutine);
|
||||
}*/
|
||||
|
||||
}
|
||||
private void Rever()
|
||||
{
|
||||
//Debug.Log($" вне условия k = {k}; min = {min}; max = {max}");
|
||||
if (k <= min)
|
||||
{
|
||||
//Debug.Log($"1. k <= min; {k}<= {min}");
|
||||
reverse = false;
|
||||
}
|
||||
else if (k >= max)
|
||||
{
|
||||
//Debug.Log($"2. k >= max; {k}>= {max}");
|
||||
reverse = true;
|
||||
}
|
||||
}
|
||||
IEnumerator AltNumber()
|
||||
{
|
||||
while (point)
|
||||
{
|
||||
scaleText();
|
||||
Y = -(k *d) + startCoorScale;//дельта
|
||||
if (typeXY == "x")
|
||||
{
|
||||
scale.gameObject.transform.localPosition = new Vector3(Y, scale.gameObject.transform.localPosition.y, scale.gameObject.transform.localPosition.z);
|
||||
//Debug.Log($"scale.gameObject.transform.localPosition = {scale.gameObject.transform.localPosition}");
|
||||
}
|
||||
else if(typeXY == "y"){
|
||||
scale.gameObject.transform.localPosition = new Vector3(scale.gameObject.transform.localPosition.x, Y, scale.gameObject.transform.localPosition.z);
|
||||
}
|
||||
//scale.gameObject.transform.localPosition = new Vector3(scale.gameObject.transform.localPosition.x, Y, scale.gameObject.transform.localPosition.z);//проверка типа
|
||||
if (reverse)
|
||||
{
|
||||
k-=0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
k+=0.5f;
|
||||
}
|
||||
Rever();
|
||||
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user