mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 00:05:39 +03:00
67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Events;
|
||
using TMPro;
|
||
|
||
public class mfiClockIndicator : MonoBehaviour
|
||
{
|
||
public int minutesInHour;
|
||
public int hoursInCircle;
|
||
private string formatText = "{0}";
|
||
private TextMeshPro _number;
|
||
private Handler _hArrow=null, _mArrow=null;
|
||
private int curH, curM;
|
||
|
||
void Awake()
|
||
{
|
||
Init();
|
||
//ChangeNumber();
|
||
}
|
||
void Init() // так надо. Awake не всегда вызывается до начала работы с объектом
|
||
{
|
||
_number = GetComponent<TextMeshPro>();
|
||
Handler[] handles = this.GetComponentsInChildren<Handler>();
|
||
for (int i = 0; i < handles.Length; i++)
|
||
{
|
||
if (handles[i].gameObject.name.EndsWith("_h"))
|
||
_hArrow = handles[i];
|
||
if (handles[i].gameObject.name.EndsWith("_m"))
|
||
_mArrow = handles[i];
|
||
}
|
||
curH = curM = 0;
|
||
}
|
||
/* private void ChangeIndicator(float val)
|
||
{
|
||
float num = TransformAngleToState(val);
|
||
_number.text = string.Format(formatText, (int)Mathf.Round(num));
|
||
}
|
||
public void ChangeNumber()
|
||
{
|
||
if (_hArrow == null) Init();
|
||
ChangeIndicator(_arrow.currentAngle);
|
||
}*/
|
||
|
||
public int TransformHourAngleToState(float val)
|
||
{
|
||
if (val < 0) val += 360f;
|
||
int res = (int)Mathf.Round((val / 360f) * (minutesInHour * hoursInCircle));
|
||
return res;
|
||
}
|
||
public int TransformMinutesAngleToState(float val)
|
||
{
|
||
if (val < 0) val += 360f;
|
||
int res = (int)Mathf.Round((val / 360f) * minutesInHour + curH* minutesInHour);
|
||
return res;
|
||
}
|
||
|
||
public void setState(int newstate) {
|
||
newstate %= minutesInHour * hoursInCircle;
|
||
curH = newstate / minutesInHour;
|
||
curM = newstate % minutesInHour;
|
||
_mArrow.SetCurAngle(180f * (curM / (minutesInHour / 2f)));
|
||
_hArrow.SetCurAngle(180f * (newstate / (minutesInHour * hoursInCircle / 2f)));
|
||
_number.text = string.Format(formatText, newstate);
|
||
}
|
||
}
|