mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 04:15:37 +03:00
04.07.2022
This commit is contained in:
66
Heli_with_panels/Assets/MFI/mfiClockIndicator.cs
Normal file
66
Heli_with_panels/Assets/MFI/mfiClockIndicator.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user