262 lines
10 KiB
C#
262 lines
10 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
using System;
|
|
using System.Globalization;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class PersonScript : MonoBehaviour
|
|
{
|
|
[Header("Äàííûå ñîòðóäíèêà")]
|
|
public string FIO; //ÔÈÎ ñîòðóäíèêà
|
|
public string Tabnomer; //Ñåðèéíûé íîìåð ñîòðóäíèêà
|
|
[Header("Êîìïîíåíòû ñîòðóäíèêà")]
|
|
[SerializeField] private Animator PersonAnimator; //Àíèìàòîð
|
|
[SerializeField] private NavMeshAgent NavMeshAgent; //ÈÈ
|
|
[SerializeField] private int CurrentPoint; //Òåêóùàÿ òî÷êà
|
|
[SerializeField] private ThanksStASSForTheNiceMethod Delogger; //Ñêðèïò ñ äàííûìè
|
|
[SerializeField] private Uiika Uiika;
|
|
public VisualTreeAsset MainUIPrefab;
|
|
private Label TimeText; //UI êîìïîíåíòû -->
|
|
private Label CordsMoText;
|
|
private Label CordsRTLSText;
|
|
private Label PointText;
|
|
private Label TimeLabel;
|
|
private Label OtmetkaName;
|
|
private Label FullTime;
|
|
private Label SlidBegin;
|
|
private Label SlidEnd;
|
|
private ProgressBar ProgressBar;
|
|
private Button PlayButton;
|
|
private Button StopButton;
|
|
private Button BackButton;
|
|
private Slider Slider;
|
|
private SliderInt SliderTime;
|
|
private SliderInt SliderMove; // <-- UI êîìïîíåíòû
|
|
[SerializeField] private GameObject MoPointPrefab; //Ïðåôàá òî÷êè ÌÎ
|
|
[SerializeField] private GameObject RTLSPointPrefab; //Ïðåôàá òî÷êè ÐÒËÑ
|
|
[Header("UIDocument")]
|
|
public UIDocument UI; //UI
|
|
private GameObject moPoint; //ïàìÿòü î òî÷êå ÌÎ
|
|
private GameObject rtlsPoint; //ïàìÿòü î òî÷êå ÐÒËÑ
|
|
[Header("Äàííûå ÈÈ")]
|
|
public float WaitTime; //Âðåìÿ ïðîâåðêè òî÷êè
|
|
public float NavAgentSpeed; //Ñêîðîñòü ïåðåìåùåíèÿ ÈÈ
|
|
public Vector3 VectorDestination; //Òî÷êà íàçíà÷åíèÿ
|
|
public float RemainingDistance; // îñòàâøååñÿ ðàññòîÿíèå äî òî÷êè
|
|
[Space]
|
|
public bool Play; //Ïðîèãðûâàíèå õîæäåíèÿ
|
|
|
|
public void InitMePlease() //Èíèöèàëèçàöèÿ UI è óñòàíîâêà íà÷àëüíûõ çíà÷åíèé
|
|
{
|
|
var root = UI.rootVisualElement;
|
|
|
|
TimeText = root.Q<Label>("TextTime");
|
|
FullTime = root.Q<Label>("FullTime");
|
|
CordsMoText = root.Q<Label>("TextCordsMo");
|
|
CordsRTLSText = root.Q<Label>("TextCordsRTLS");
|
|
PointText = root.Q<Label>("TextPoint");
|
|
PointText.visible = false;
|
|
TimeLabel = root.Q<Label>("TimeLabel");
|
|
OtmetkaName = root.Q<Label>("OtmetkaName");
|
|
ProgressBar = root.Q<ProgressBar>("progressbar");
|
|
ProgressBar.visible = false;
|
|
PlayButton = root.Q<Button>("playbutton");
|
|
StopButton = root.Q<Button>("stopbutton");
|
|
BackButton = root.Q<Button>("BackButton");
|
|
Slider = root.Q<Slider>("Slider");
|
|
SliderTime = root.Q<SliderInt>("SliderTime");
|
|
SliderMove = root.Q<SliderInt>("SliderMove");
|
|
|
|
NavMeshAgent.Warp(Delogger.LocationsMO[0]); //Òåëåïîðò ÈÈ íà ïåðâóþ òî÷êó èç èñòîðèè
|
|
|
|
string[] strArray = Delogger.Time[0].Split(' ');
|
|
TimeLabel.text = strArray[1]; //Îòîáðàæåíèå âðåìåíè íà ïîëçóíêå ñíèçó
|
|
|
|
OtmetkaName.text = Delogger.BlockNamesAliases[0];
|
|
|
|
SliderTime.highValue = Delogger.LocationsMO.Count - 1;
|
|
ProgressBar.highValue = Delogger.LocationsMO.Count - 1;
|
|
TimeText.text = "Âðåìÿ: " + Delogger.Time[CurrentPoint];
|
|
CordsMoText.text = "Êîîðäèíàòû ÌÎ: " + Delogger.LocationsMO[CurrentPoint];
|
|
CordsRTLSText.text = "Êîîðäèíàòû ÐÒËÑ: " + Delogger.LocationsRTLS[CurrentPoint];
|
|
PointText.text = "Òåêóùàÿ òî÷êà: " + CurrentPoint + " èç " + (Delogger.LocationsMO.Count - 1);
|
|
SliderTime.ElementAt(0).ElementAt(0).ElementAt(2).Add(SliderTime.ElementAt(1));
|
|
|
|
PlayButton.clicked += PlayButtonPressed; //Áèíä èâåíòà íà íàæàòèå êíîïêè PlayButton
|
|
StopButton.clicked += StopButtonPressed; //Áèíä èâåíòà íà íàæàòèå êíîïêè StopButton
|
|
BackButton.clicked += BackButtonPressed;
|
|
Uiika.MakeTable();
|
|
FullTime.text = "Ñ "+Delogger.Time[0] +" ïî "+ Delogger.Time[Delogger.Time.Count - 1];
|
|
if (moPoint == null)
|
|
{
|
|
moPoint = Instantiate(MoPointPrefab, Delogger.LocationsMO[CurrentPoint], MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÌÎ
|
|
}
|
|
else if (moPoint.transform.position != Delogger.LocationsMO[CurrentPoint])
|
|
{
|
|
Destroy(moPoint); //Óäàëåíèå òî÷êè ÌÎ
|
|
}
|
|
Play = true;
|
|
//if (rtlsPoint == null)
|
|
//{
|
|
// rtlsPoint = Instantiate(RTLSPointPrefab, Delogger.LocationsRTLS[CurrentPoint], MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÐÒËÑ
|
|
//}
|
|
//else if (rtlsPoint.transform.position != Delogger.LocationsRTLS[CurrentPoint])
|
|
//{
|
|
// Destroy(rtlsPoint); //Óäàëåíèå òî÷êè ÐÒËÑ
|
|
//}
|
|
|
|
|
|
void BackButtonPressed()
|
|
{
|
|
UI.visualTreeAsset = MainUIPrefab;
|
|
Uiika.RequestButton.SetEnabled(true); //Îòêëþ÷åíèå êíîïêè RequestButton, äëÿ èçáåæàíèÿ ïîâòîðíûõ äàííûõ
|
|
Uiika.Start();
|
|
Uiika.Remember();
|
|
Play = false;
|
|
NavMeshAgent.SetDestination(gameObject.transform.position);
|
|
PersonAnimator.SetBool("isMoving", false);
|
|
Destroy(moPoint); //Óäàëåíèå òî÷êè ÌÎ
|
|
Destroy(rtlsPoint); //Óäàëåíèå òî÷êè ÐÒËÑ
|
|
NavMeshAgent.speed = 4;
|
|
WaitTime = 0.7f;
|
|
CurrentPoint = 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
//Èçìåíåíèå âðåìåíè ïðîâåðêè òî÷êè
|
|
Slider.RegisterCallback<ChangeEvent<float>>((evt) =>
|
|
{
|
|
WaitTime = evt.newValue;
|
|
});
|
|
|
|
//Èçìåíåíèå òî÷êè ïî ïîëçóíêó âíèçó
|
|
SliderTime.RegisterCallback<ChangeEvent<int>>((zvt) =>
|
|
{
|
|
CurrentPoint = zvt.newValue;
|
|
NavMeshAgent.Warp(Delogger.LocationsMO[CurrentPoint]);
|
|
|
|
string[] strArray = Delogger.Time[CurrentPoint].Split(' ');
|
|
TimeLabel.text = strArray[1];
|
|
OtmetkaName.text = Delogger.BlockNamesAliases[CurrentPoint];
|
|
TimeText.text = "Âðåìÿ: " + Delogger.Time[CurrentPoint];
|
|
CordsMoText.text = "Êîîðäèíàòû ÌÎ: " + Delogger.LocationsMO[CurrentPoint];
|
|
CordsRTLSText.text = "Êîîðäèíàòû ÐÒËÑ: " + Delogger.LocationsRTLS[CurrentPoint];
|
|
PointText.text = "Òåêóùàÿ òî÷êà: " + CurrentPoint + " èç " + (Delogger.LocationsMO.Count - 1);
|
|
ProgressBar.value = CurrentPoint;
|
|
});
|
|
|
|
//Èçìåíåíèå ñêîðîñòè ïåðåìåùåíèÿ ÈÈ
|
|
SliderMove.RegisterCallback<ChangeEvent<int>>((speed) =>
|
|
{
|
|
NavMeshAgent.speed = speed.newValue;
|
|
});
|
|
|
|
//Çàïóñê öèêëà íà ïðîâåðêó òî÷êè
|
|
StartCoroutine("CheckPosition");
|
|
}
|
|
|
|
void PlayButtonPressed() //Âûçîâ ñ êíîïêè PlayButton
|
|
{
|
|
Play = true;
|
|
NavMeshAgent.SetDestination(Delogger.LocationsMO[CurrentPoint]);
|
|
PlayButton.SetEnabled(false);
|
|
StopButton.SetEnabled(true);
|
|
}
|
|
void StopButtonPressed() //Âûçîâ ñ êíîïêè StopButton
|
|
{
|
|
Play = false;
|
|
NavMeshAgent.SetDestination(gameObject.transform.position);
|
|
PersonAnimator.SetBool("isMoving", false);
|
|
PlayButton.SetEnabled(true);
|
|
StopButton.SetEnabled(false);
|
|
}
|
|
|
|
|
|
void Update()
|
|
{
|
|
if (Play)
|
|
{
|
|
RemainingDistance = NavMeshAgent.remainingDistance; //Âûâîä îñòàâøååñÿ ðàññòîÿíèÿ äî òî÷êè
|
|
NavMeshAgent.SetDestination(Delogger.LocationsMO[CurrentPoint]); //Âûñòàâëåíèå òî÷êè äëÿ ÈÈ â çàâèñèìîñòè îò òåêóùåãî èíäåêñà
|
|
VectorDestination = Delogger.LocationsMO[CurrentPoint]; //Çàïèñü êîîðäèíàò â ïåðåìåííóþ äëÿ ïðîñìîòðà
|
|
|
|
CheckPoints(); //Ïðîâåðêà òî÷åê åñòü ëè îíè
|
|
SetUIParams(); //Óñòàíîâëåíèå ïàðàìåòðîâ â UI
|
|
|
|
PersonAnimator.SetBool("isMoving", NavMeshAgent.velocity.magnitude > 0.01f); //Ïðîâåðêà ñêîðîñòè ÈÈ äëÿ îòîáðàæåíèÿ àíèìàöèè
|
|
NavAgentSpeed = NavMeshAgent.velocity.magnitude; //Òåêóùàÿ ñêîðîñòü ÈÈ
|
|
}
|
|
switch (NavMeshAgent.speed)
|
|
{
|
|
case 10:
|
|
WaitTime = 0.1f;
|
|
break;
|
|
case 9:
|
|
WaitTime = 0.2f;
|
|
break;
|
|
case 8:
|
|
WaitTime = 0.3f;
|
|
break;
|
|
case 7:
|
|
WaitTime = 0.4f;
|
|
break;
|
|
case 6:
|
|
WaitTime = 0.5f;
|
|
break;
|
|
case 5:
|
|
WaitTime = 0.6f;
|
|
break;
|
|
case 4:
|
|
WaitTime = 0.7f;
|
|
break;
|
|
}
|
|
}
|
|
IEnumerator CheckPosition()
|
|
{
|
|
if (NavMeshAgent.remainingDistance <= NavMeshAgent.stoppingDistance & Play & CurrentPoint != Delogger.LocationsMO.Count -1) // Ïðîâåðêà íà îñòàâøèååñÿ ðàññòîÿíèå, íà ðàçðåøåíî ëè ïðîèãðûâàíèå, íà òî ÷òî òåêóùàÿ òî÷êà íå ïîñëåäíÿÿ
|
|
{
|
|
CurrentPoint++; //Ñëåäóþùàÿ òî÷êà
|
|
ProgressBar.value = CurrentPoint; //Óñòàíîâêà çíà÷åíèÿ â ProgressBar
|
|
}
|
|
yield return new WaitForSecondsRealtime(WaitTime);
|
|
StartCoroutine("CheckPosition");
|
|
}
|
|
private void CheckPoints()
|
|
{
|
|
if (moPoint == null)
|
|
{
|
|
moPoint = Instantiate(MoPointPrefab, Delogger.LocationsMO[CurrentPoint], MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÌÎ
|
|
}
|
|
else if (moPoint.transform.position != Delogger.LocationsMO[CurrentPoint])
|
|
{
|
|
Destroy(moPoint); //Óäàëåíèå òî÷êè ÌÎ
|
|
}
|
|
//if (rtlsPoint == null)
|
|
//{
|
|
// rtlsPoint = Instantiate(RTLSPointPrefab, Delogger.LocationsRTLS[CurrentPoint], MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÐÒËÑ
|
|
//}
|
|
//else if (rtlsPoint.transform.position != Delogger.LocationsRTLS[CurrentPoint])
|
|
//{
|
|
// Destroy(rtlsPoint); //Óäàëåíèå òî÷êè ÐÒËÑ
|
|
//}
|
|
}
|
|
private void SetUIParams()
|
|
{
|
|
SliderTime.SetValueWithoutNotify(CurrentPoint);
|
|
TimeText.text = "Âðåìÿ: " + Delogger.Time[CurrentPoint];
|
|
CordsMoText.text = "Êîîðäèíàòû ÌÎ: " + Delogger.LocationsMO[CurrentPoint];
|
|
CordsRTLSText.text = "Êîîðäèíàòû ÐÒËÑ: " + Delogger.LocationsRTLS[CurrentPoint];
|
|
PointText.text = "Òåêóùàÿ òî÷êà: " + CurrentPoint + " èç " + (Delogger.LocationsMO.Count - 1);
|
|
|
|
string[] strArray = Delogger.Time[CurrentPoint].Split(' ');
|
|
TimeLabel.text = strArray[1];
|
|
|
|
OtmetkaName.text = Delogger.BlockNamesAliases[CurrentPoint];
|
|
}
|
|
}
|