реализ от 25.04.2025

This commit is contained in:
Станислав Хозяенок 2025-04-25 08:33:44 +07:00
parent df6e2fe069
commit 6df08a2ee4
8 changed files with 2072 additions and 363 deletions

View File

@ -36,3 +36,4 @@ namespace Assets.Scripts.API.MTEGetMarksLabelsByArrPoint
public float z; public float z;
} }
} }

View File

@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using System; using System;
using NpgsqlTypes;
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); // Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Item public class Item
@ -18,6 +19,14 @@ public class Item
public float z_mo { get; set; } public float z_mo { get; set; }
} }
public class MarkItem
{
public string name { get; set; }
public int time_end { get; set; }
public int time_spend { get; set; }
public int time_start { get; set; }
}
public class MarksTime public class MarksTime
{ {
public int count_seconds { get; set; } public int count_seconds { get; set; }
@ -31,6 +40,7 @@ public class ResposeMethod
public string time_begin { get; set; } public string time_begin { get; set; }
public string time_end { get; set; } public string time_end { get; set; }
public List<MarksTime> marks_time { get; set; } public List<MarksTime> marks_time { get; set; }
public List<MarkItem> marks_hronology { get; set; }
} }
public class MethodJSON public class MethodJSON

View File

@ -1,11 +1,179 @@
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.AI; using UnityEngine.AI;
using System; using System;
using System.Globalization;
using UnityEngine.UIElements; using UnityEngine.UIElements;
public class PathUtils
{
NavMeshPath _path;
bool _isPathCalculated = false;
Vector3 _calculatedFromPos;
Vector3 _calculatedToPos;
bool _isSuccessesCalculatedPath = false;
bool _isNeedCalculatePath;
float _totalDistance = 0;
// totalDistance == float.MaxValue - ïóòü äî îáúåêòà íå ïîñòðîåí óñïåøíî óñïåøíî
// isPathAlreadyCalculated - åñëè ïóòü äî ýòîãî óæå ïðîñòðîåí
public Vector3 GetPointAtPercentage(Vector3 fromPos, Vector3 toPos, float percentage,out float totalDistance, out bool isPathAlreadyCalculated)
{
_isNeedCalculatePath = false;
if (_isPathCalculated)
{
if (_calculatedFromPos != fromPos || _calculatedToPos != toPos)
{
_isNeedCalculatePath = true;
isPathAlreadyCalculated = false;
}
else
{
isPathAlreadyCalculated = true;
_isNeedCalculatePath = false;
}
}
else
{
_isNeedCalculatePath = true;
isPathAlreadyCalculated = false;
}
if (_isNeedCalculatePath)
{
_isPathCalculated = false;
_path = new NavMeshPath();
_isSuccessesCalculatedPath = NavMesh.CalculatePath(fromPos, toPos, NavMesh.AllAreas, _path);
_calculatedFromPos = fromPos;
_calculatedToPos = toPos;
_isPathCalculated = true;
}
if (_isSuccessesCalculatedPath)
{
if (_isNeedCalculatePath) {
_totalDistance = 0f;
for (int i = 1; i < _path.corners.Length; i++)
{
_totalDistance += Vector3.Distance(_path.corners[i - 1], _path.corners[i]);
}
}
totalDistance = _totalDistance;
float targetDistance = _totalDistance * percentage;
float accumulatedDistance = 0f;
for (int i = 1; i < _path.corners.Length; i++)
{
float segmentDistance = Vector3.Distance(_path.corners[i - 1], _path.corners[i]);
if (accumulatedDistance + segmentDistance >= targetDistance)
{
// Íàõîäèì òî÷êó íà òåêóùåì ñåãìåíòå
float remainingDistance = targetDistance - accumulatedDistance;
Vector3 direction = (_path.corners[i] - _path.corners[i - 1]).normalized;
return _path.corners[i - 1] + direction * remainingDistance;
}
accumulatedDistance += segmentDistance;
}
}
else
{
totalDistance = float.MaxValue;
}
return fromPos;
}
}
public class TeleportationChecker
{
public NavMeshAgent _agent;
public float BaseSpeed = 3.0f;
public float Speed { get => BaseSpeed * KSpeed; }
public float ElapsedTimeMax = 70.0f;
public float KSpeed = 1f; // Êîýôôèöèåíò ñêîðîñòè
public enum TypeMove {
Warp, Move, Nothing
}
PathUtils _pathUtils;
public TeleportationChecker(NavMeshAgent agent)
{
_agent = agent;
_pathUtils = new PathUtils();
}
float textScale = 10f;
public TypeMove IsNeedWarp(Vector3 oldPos, DateTime oldTime, Vector3 newPos, DateTime newTime, float diffSecondsLastTick, DateTime currentTime, out Vector3 warpPosition)
{
;
float elapsedTimeSeconds = (float)(newTime - oldTime).TotalSeconds;
float currentTimeSeconds = (float)(currentTime - oldTime).TotalSeconds;
float maxDistance = Speed * diffSecondsLastTick;
Vector3 targetPoint = _pathUtils.GetPointAtPercentage(oldPos, newPos, currentTimeSeconds / elapsedTimeSeconds, out float actualDistance, out bool isPathAlreadyCalculated);
// Åñëè íå ìîæåì äîéòè òî âîçâðàùàåì ñòàðóþ ïîçèöèþ
if (actualDistance == float.MaxValue)
{
warpPosition = oldPos;
return TypeMove.Warp;
}
// Îáðàáàòûâàåì òîëüêî òå çàäåðæêà êîòîðûõ áûëà ìåíüøå 10 ñåêóíä äî ñëåäóþùåé òî÷êè
if (elapsedTimeSeconds > ElapsedTimeMax)
{
warpPosition = oldPos;
return TypeMove.Warp;
}
if (isPathAlreadyCalculated)
{
float speed = actualDistance / elapsedTimeSeconds;
if (speed < 0.8 * Speed) {
// Äðóãàÿ ëîãèêà îáðàáîòêè
maxDistance = float.MinValue;
// Ïåðåðàñ÷èòûâàåì âðåìÿ ñ êîòîðîãî íà÷í¸ì ïåðåìåùåíèÿ
// âûñ÷èòûâàåì âðåìÿ íåîáõîäèìîå äëÿ ïðîõîäà ñ ïîìùüþ 0.9 îò ìàêñèìàëüíîé
float localTotalTime = actualDistance / ((float) 0.9 * Speed);
float localTimeBegin = (elapsedTimeSeconds - (float)localTotalTime);
if (currentTimeSeconds > localTimeBegin)
{
targetPoint = _pathUtils.GetPointAtPercentage(oldPos, newPos, (currentTimeSeconds - localTimeBegin )/ localTotalTime, out actualDistance, out isPathAlreadyCalculated);
warpPosition = targetPoint;
return TypeMove.Move;
}
}
}
float currentDistance = Vector3.Distance(_agent.transform.position, targetPoint);
Debug.Log($"{currentDistance} {maxDistance}");
if (currentDistance - textScale * _agent.radius < maxDistance )
{
Debug.Log("Move");
warpPosition = targetPoint;
return TypeMove.Move;
} else
{
warpPosition = oldPos;
if (isPathAlreadyCalculated)
{
// Óæå áûëî ñîâåðøåíî ïåðåìåùåíèå ïî òî÷êàì
return TypeMove.Nothing;
}
else
{
// ïîçèöèÿ íîâàÿ ïåðåìåùàåì
return TypeMove.Warp;
}
}
}
}
public class PersonScript : MonoBehaviour public class PersonScript : MonoBehaviour
{ {
[Header("Äàííûå ñîòðóäíèêà")] [Header("Äàííûå ñîòðóäíèêà")]
@ -17,23 +185,25 @@ public class PersonScript : MonoBehaviour
[SerializeField] private int CurrentPoint; //Òåêóùàÿ òî÷êà [SerializeField] private int CurrentPoint; //Òåêóùàÿ òî÷êà
[SerializeField] private ThanksStASSForTheNiceMethod Delogger; //Ñêðèïò ñ äàííûìè [SerializeField] private ThanksStASSForTheNiceMethod Delogger; //Ñêðèïò ñ äàííûìè
[SerializeField] private Uiika Uiika; [SerializeField] private Uiika Uiika;
[SerializeField] private Canvas NoSignalCanvas;
public VisualTreeAsset MainUIPrefab; public VisualTreeAsset MainUIPrefab;
private Label TimeText; //UI êîìïîíåíòû --> //private Label TimeText; //UI êîìïîíåíòû -->
private Label CordsMoText; //private Label CordsMoText;
private Label CordsRTLSText; //private Label CordsRTLSText;
private Label PointText; //private Label PointText;
private Label TimeLabel; //private Label TimeLabel;
private Label OtmetkaName; //private Label OtmetkaName;
private Label FullTime; //private Label FullTime;
private Label SlidBegin; //private Label SlidBegin;
private Label SlidEnd; //private Label SlidEnd;
private ProgressBar ProgressBar; //private ProgressBar ProgressBar;
private Button PlayButton; //private Button PlayButton;
private Button StopButton; //private Button StopButton;
private Button BackButton; //private Button BackButton;
private Slider Slider; //private Slider Slider;
private SliderInt SliderTime; //private SliderInt SliderTime;
private SliderInt SliderMove; // <-- UI êîìïîíåíòû //private SliderInt SliderMove; // <-- UI êîìïîíåíòû
[SerializeField] private GameObject MoPointPrefab; //Ïðåôàá òî÷êè ÌÎ [SerializeField] private GameObject MoPointPrefab; //Ïðåôàá òî÷êè ÌÎ
[SerializeField] private GameObject RTLSPointPrefab; //Ïðåôàá òî÷êè ÐÒËÑ [SerializeField] private GameObject RTLSPointPrefab; //Ïðåôàá òî÷êè ÐÒËÑ
[Header("UIDocument")] [Header("UIDocument")]
@ -50,212 +220,298 @@ public class PersonScript : MonoBehaviour
public void InitMePlease() //Èíèöèàëèçàöèÿ UI è óñòàíîâêà íà÷àëüíûõ çíà÷åíèé public void InitMePlease() //Èíèöèàëèçàöèÿ UI è óñòàíîâêà íà÷àëüíûõ çíà÷åíèé
{ {
var root = UI.rootVisualElement; // Ñïàâí òî÷åê
//if (SceneParams.Instance.spawnMovePoint.IsSpawnMTEPoint)
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); //Ñïàâí òî÷êè ÐÒËÑ // if (moPoint == null)
//} // {
//else if (rtlsPoint.transform.position != Delogger.LocationsRTLS[CurrentPoint]) // moPoint = Instantiate(MoPointPrefab, Delogger.LocationsMO[CurrentPoint], MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÌÎ
//{ // }
// Destroy(rtlsPoint); //Óäàëåíèå òî÷êè ÐÒËÑ // else if (moPoint.transform.position != Delogger.LocationsMO[CurrentPoint])
// {
// Destroy(moPoint); //Óäàëåíèå òî÷êè ÌÎ
// }
//} //}
//if (SceneParams.Instance.spawnMovePoint.IsSpawnRTLSPoint)
//{
// 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() //Play = true;
{
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"); Uiika.EventCurrentDateTimeChanged.AddListener(HandleNewTime);
//StartCoroutine("CheckPosition");
} }
void PlayButtonPressed() //Âûçîâ ñ êíîïêè PlayButton static readonly DateTime defaultDateTime = new DateTime(0);
DateTime currentKey = defaultDateTime;
TagRecord tagRecordOld;
TagRecord? tagRecordNew;
DateTime findedKey;
DateTime findedKeyNext;
public int IsSecondInAnyRange(double second)
{ {
Play = true; var items = Delogger.MarksHronology;
NavMeshAgent.SetDestination(Delogger.LocationsMO[CurrentPoint]); // Èñïîëüçóåì áèíàðíûé ïîèñê äëÿ íàõîæäåíèÿ ïîäõîäÿùåãî äèàïàçîíà
PlayButton.SetEnabled(false); int left = 0;
StopButton.SetEnabled(true); int right = items.Count - 1;
while (left <= right)
{
int mid = left + (right - left) / 2;
// Ïðîâåðÿåì, âõîäèò ëè second â òåêóùèé äèàïàçîí
if (second >= items[mid].time_start && second <= items[mid].time_end)
{
return mid;
}
// Åñëè second ìåíüøå time_start, èùåì â ëåâîé ÷àñòè
if (second < items[mid].time_start)
{
right = mid - 1;
}
else // Èíà÷å èùåì â ïðàâîé ÷àñòè
{
left = mid + 1;
}
}
return -1; // Äèàïàçîí íå íàéäåí
} }
void StopButtonPressed() //Âûçîâ ñ êíîïêè StopButton
public void HandleNewTime(DateTimeChangedData data)
{ {
Play = false; teleportationChecker.KSpeed = data.Speed;
NavMeshAgent.SetDestination(gameObject.transform.position); NavMeshAgent.speed = teleportationChecker.Speed;
PersonAnimator.SetBool("isMoving", false);
PlayButton.SetEnabled(true); var keys = new List<DateTime>(Delogger.mapDateTimeRecords.Keys);
StopButton.SetEnabled(false);
} DateTime utcTime = TimeZoneInfo.ConvertTimeToUtc(data.NewTime);
int? keyIndex = FindClosestDateTimeKeyIndex(keys, utcTime);
if (keyIndex == null)
{
// Óñòàíàâëèâàåì íà÷àëüíóþ ïîçèöèþ òýãà
NavMeshAgent.Warp(SceneParams.Instance.person.StartPosition);
currentKey = defaultDateTime;
//this.NoSignalCanvas.gameObject.SetActive(true);
Uiika.SetMarkText("");
}
else {
int currentIndex = (int)keyIndex;
findedKey = keys[currentIndex];
if (currentKey != findedKey)
{
currentKey = findedKey;
tagRecordOld = Delogger.mapDateTimeRecords[findedKey];
// Ïåðåìåùàåì
if (currentIndex == keys.Count - 1)
{
tagRecordNew = null;
// Íà ïîñëåäíèé òåëåïîðòèðóåì
NavMeshAgent.Warp(tagRecordOld.LocationsMO);
}
else
{
findedKeyNext = keys[currentIndex + 1];
tagRecordNew = Delogger.mapDateTimeRecords[findedKeyNext];
TeleportationChecker.TypeMove typeMove = teleportationChecker.IsNeedWarp(tagRecordOld.LocationsMO, findedKey, tagRecordNew.Value.LocationsMO, findedKeyNext, data.DeltaTime, utcTime, out Vector3 warpPosition);
switch (typeMove)
{
case TeleportationChecker.TypeMove.Move:
NavMeshAgent.SetDestination(warpPosition);
break;
case TeleportationChecker.TypeMove.Warp:
NavMeshAgent.Warp(warpPosition);
break;
}
}
//if (teleportationChecker.)
CheckPoints(tagRecordOld);
//Uiika.SetMarkText(tagRecordOld.BlockNamesAliases);
int idxRange = IsSecondInAnyRange((data.NewTime - Uiika.DatBegin).TotalSeconds);
if (idxRange !=-1)
{
Uiika.SetMarkText(Delogger.MarksHronology[idxRange].name);
}
else
{
Uiika.SetMarkText("");
}
} else
{
if (tagRecordNew != null )
{
TeleportationChecker.TypeMove typeMove = teleportationChecker.IsNeedWarp(tagRecordOld.LocationsMO, findedKey, tagRecordNew.Value.LocationsMO, findedKeyNext, data.DeltaTime, utcTime, out Vector3 warpPosition);
switch (typeMove)
{
case TeleportationChecker.TypeMove.Move:
NavMeshAgent.SetDestination(warpPosition);
break;
}
}
}
}
}
TeleportationChecker teleportationChecker;
void Start()
{
SceneParams.Instance.person.StartPosition = transform.position;
teleportationChecker = new TeleportationChecker(NavMeshAgent);
}
static DateTime? FindClosestDateTime(List<DateTime> keys, DateTime targetDateTime)
{
// Ïîëó÷àåì ìàññèâ êëþ÷åé
DateTime universalDateTime = targetDateTime.ToUniversalTime();
DateTime utcTime = TimeZoneInfo.ConvertTimeToUtc(targetDateTime);
// Âûïîëíÿåì áèíàðíûé ïîèñê
int index = keys.BinarySearch(utcTime);
// Åñëè ýëåìåíò íàéäåí, âîçâðàùàåì ïðåäûäóùèé ýëåìåíò
if (index >= 0)
{
if (index > 0)
{
return keys[index - 1]; // Âîçâðàùàåì ïðåäûäóùèé ýëåìåíò
}
else
{
return null; // Íåò ýëåìåíòîâ ìåíüøå çàäàííîãî
}
}
else
{
// Åñëè ýëåìåíò íå íàéäåí, BinarySearch âîçâðàùàåò îòðèöàòåëüíîå çíà÷åíèå,
// êîòîðîå óêàçûâàåò íà ìåñòî, ãäå ýëåìåíò ìîã áû áûòü âñòàâëåí.
index = ~index; // Ïîëó÷àåì èíäåêñ âñòàâêè
if (index > 0)
{
return keys[index - 1]; // Âîçâðàùàåì ïðåäûäóùèé ýëåìåíò
}
else
{
return null; // Íåò ýëåìåíòîâ ìåíüøå çàäàííîãî
}
}
}
static int? FindClosestDateTimeKeyIndex(List<DateTime> keys, DateTime targetDateTime)
{
// Ïðåîáðàçóåì öåëåâóþ äàòó è âðåìÿ â UTC
// Âûïîëíÿåì áèíàðíûé ïîèñê
int index = keys.BinarySearch(targetDateTime);
// Åñëè ýëåìåíò íàéäåí, âîçâðàùàåì åãî èíäåêñ
if (index >= 0)
{
return index; // Âîçâðàùàåì èíäåêñ íàéäåííîãî ýëåìåíòà
}
else
{
// Åñëè ýëåìåíò íå íàéäåí, BinarySearch âîçâðàùàåò îòðèöàòåëüíîå çíà÷åíèå,
// êîòîðîå óêàçûâàåò íà ìåñòî, ãäå ýëåìåíò ìîã áû áûòü âñòàâëåí.
index = ~index; // Ïîëó÷àåì èíäåêñ âñòàâêè
if (index > 0)
{
return index - 1; // Âîçâðàùàåì èíäåêñ ïðåäûäóùåãî ýëåìåíòà
}
else
{
return null; // Íåò ýëåìåíòîâ ìåíüøå çàäàííîãî
}
}
}
void Update() void Update()
{ {
if (Play) //if (Play)
{ //{
RemainingDistance = NavMeshAgent.remainingDistance; //Âûâîä îñòàâøååñÿ ðàññòîÿíèÿ äî òî÷êè // RemainingDistance = NavMeshAgent.remainingDistance; //Âûâîä îñòàâøååñÿ ðàññòîÿíèÿ äî òî÷êè
NavMeshAgent.SetDestination(Delogger.LocationsMO[CurrentPoint]); //Âûñòàâëåíèå òî÷êè äëÿ ÈÈ â çàâèñèìîñòè îò òåêóùåãî èíäåêñà // NavMeshAgent.SetDestination(Delogger.LocationsMO[CurrentPoint]); //Âûñòàâëåíèå òî÷êè äëÿ ÈÈ â çàâèñèìîñòè îò òåêóùåãî èíäåêñà
VectorDestination = Delogger.LocationsMO[CurrentPoint]; //Çàïèñü êîîðäèíàò â ïåðåìåííóþ äëÿ ïðîñìîòðà // VectorDestination = Delogger.LocationsMO[CurrentPoint]; //Çàïèñü êîîðäèíàò â ïåðåìåííóþ äëÿ ïðîñìîòðà
CheckPoints(); //Ïðîâåðêà òî÷åê åñòü ëè îíè // CheckPoints(); //Ïðîâåðêà òî÷åê åñòü ëè îíè
SetUIParams(); //Óñòàíîâëåíèå ïàðàìåòðîâ â UI // //SetUIParams(); //Óñòàíîâëåíèå ïàðàìåòðîâ â UI
PersonAnimator.SetBool("isMoving", NavMeshAgent.velocity.magnitude > 0.01f); //Ïðîâåðêà ñêîðîñòè ÈÈ äëÿ îòîáðàæåíèÿ àíèìàöèè PersonAnimator.SetBool("isMoving", NavMeshAgent.velocity.magnitude > 0.01f); //Ïðîâåðêà ñêîðîñòè ÈÈ äëÿ îòîáðàæåíèÿ àíèìàöèè
NavAgentSpeed = NavMeshAgent.velocity.magnitude; //Òåêóùàÿ ñêîðîñòü ÈÈ 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()
//IEnumerator CheckPosition()
//{
// if (NavMeshAgent.remainingDistance <= NavMeshAgent.stoppingDistance & Play & CurrentPoint != Delogger.LocationsMO.Count -1) // Ïðîâåðêà íà îñòàâøèååñÿ ðàññòîÿíèå, íà ðàçðåøåíî ëè ïðîèãðûâàíèå, íà òî ÷òî òåêóùàÿ òî÷êà íå ïîñëåäíÿÿ
// {
// CurrentPoint++; //Ñëåäóþùàÿ òî÷êà
// }
// yield return new WaitForSecondsRealtime(WaitTime);
// StartCoroutine("CheckPosition");
//}
private void CheckPoints(TagRecord record)
{ {
SliderTime.SetValueWithoutNotify(CurrentPoint); if (SceneParams.Instance.spawnMovePoint.IsSpawnMTEPoint)
TimeText.text = "Âðåìÿ: " + Delogger.Time[CurrentPoint]; {
CordsMoText.text = "Êîîðäèíàòû ÌÎ: " + Delogger.LocationsMO[CurrentPoint]; if (moPoint == null)
CordsRTLSText.text = "Êîîðäèíàòû ÐÒËÑ: " + Delogger.LocationsRTLS[CurrentPoint]; {
PointText.text = "Òåêóùàÿ òî÷êà: " + CurrentPoint + " èç " + (Delogger.LocationsMO.Count - 1); moPoint = Instantiate(MoPointPrefab, record.LocationsMO, MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÌÎ
}
else if (moPoint.transform.position != record.LocationsMO)
{
Destroy(moPoint); //Óäàëåíèå òî÷êè ÌÎ
}
}
string[] strArray = Delogger.Time[CurrentPoint].Split(' '); if (SceneParams.Instance.spawnMovePoint.IsSpawnRTLSPoint) {
TimeLabel.text = strArray[1]; if (rtlsPoint == null)
{
OtmetkaName.text = Delogger.BlockNamesAliases[CurrentPoint]; rtlsPoint = Instantiate(RTLSPointPrefab, record.LocationsRTLS, MoPointPrefab.gameObject.transform.rotation); //Ñïàâí òî÷êè ÐÒËÑ
}
else if (rtlsPoint.transform.position != record.LocationsRTLS)
{
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];
//}
} }

View File

@ -15,26 +15,40 @@ public class PlayerScript : MonoBehaviour
void Start() void Start()
{ {
limit = Mathf.Abs(limit);
if (limit > 90) limit = 90;
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
transform.position = target.position + offset;
} }
void Update() public void SetPlayerPosition()
{
limit = Mathf.Abs(limit);
if (limit > 90) limit = 90;
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax) / 2);
transform.position = target.position + offset;
}
void Update()
{ {
if (SceneParams.Instance.cameraSettings.IsBlockZoom == false)
{
if (Input.GetAxis("Mouse ScrollWheel") > 0) offset.z += zoom; if (Input.GetAxis("Mouse ScrollWheel") > 0) offset.z += zoom;
else if (Input.GetAxis("Mouse ScrollWheel") < 0) offset.z -= zoom; else if (Input.GetAxis("Mouse ScrollWheel") < 0) offset.z -= zoom;
offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin)); offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
if (Input.GetMouseButton(0))
{
X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
Y += Input.GetAxis("Mouse Y") * sensitivity;
Y = Mathf.Clamp(Y, -limit, limit);
transform.localEulerAngles = new Vector3(-Y, X, 0);
} }
if (SceneParams.Instance.cameraSettings.IsBlockMove == false)
{
if (Input.GetMouseButton(0))
{
X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
Y += Input.GetAxis("Mouse Y") * sensitivity;
Y = Mathf.Clamp(Y, -limit, limit);
transform.localEulerAngles = new Vector3(-Y, X, 0);
}
}
// Îáíîâëÿåì ïîçèöèþ â êàæäîì êàäðå
if (SceneParams.Instance.cameraSettings.IsStartPos == false)
{
transform.position = transform.localRotation * offset + target.position; transform.position = transform.localRotation * offset + target.position;
}
} }
} }

71
SceneParams.cs Normal file
View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
class SceneParams
{
static private SceneParams _instance;
static public SceneParams Instance
{
get
{
if (_instance == null)
{
_instance = new SceneParams();
}
return _instance;
}
}
public class CameraSettings
{
private bool isBlockMove = true;
private bool isBlockZoom = true;
// Запретить переход
public bool IsBlockMove {
get => isBlockMove;
set
{
if (Instance.IsDataHistoryLoadged)
isBlockMove = value;
}
}
public bool IsBlockZoom {
get => isBlockZoom;
set
{
if (Instance.IsDataHistoryLoaded)
isBlockZoom = value;
}
}
public Transform DefaultTransform = null;
public bool IsStartPos { get; set; } = true;
}
public class SpawnMovePoint
{
private bool isSpawnMTEPoint = false;
private bool isSpawnRTLSPoint = false;
public bool IsSpawnMTEPoint { get => isSpawnMTEPoint; set => isSpawnMTEPoint = value; }
public bool IsSpawnRTLSPoint { get => isSpawnRTLSPoint; set => isSpawnRTLSPoint = value; }
}
public class Person
{
private Vector3 startPosition;
public Vector3 StartPosition { get => startPosition; set => startPosition = value; }
}
public CameraSettings cameraSettings = new CameraSettings();
public SpawnMovePoint spawnMovePoint = new SpawnMovePoint();
public Person person = new Person();
public bool IsDataHistoryLoaded { get; set; } = false;
}

11
SceneParams.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c998991bbfa514e4c9b67162d41b1469
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,17 +7,29 @@ using Newtonsoft.Json;
using UnityEngine.UIElements; using UnityEngine.UIElements;
//using UnityEngine.Analytics; //using UnityEngine.Analytics;
public struct TagRecord
{
public String Time;
public String BlockNamesAliases;
public Vector3 LocationsMO;
public Vector3 LocationsRTLS;
}
public class ThanksStASSForTheNiceMethod : MonoBehaviour public class ThanksStASSForTheNiceMethod : MonoBehaviour
{ {
[Header("Ññûëêà íà ìåòîä è àâòîðèçàöèÿ")] [Header("Ññûëêà íà ìåòîä è àâòîðèçàöèÿ")]
public string URL; public string URL;
public string Auth; public string Auth;
[Header("Ëèñòû ñ äàííûìè")] [Header("Ëèñòû ñ äàííûìè")]
public List<Vector3> LocationsMO; //Òî÷êè ÌÎ public SortedDictionary<DateTime, TagRecord> mapDateTimeRecords = new SortedDictionary<DateTime, TagRecord>();
public List<Vector3> LocationsRTLS; //Òî÷êè ÐÒËÑ public List<String> MarksTime = new List<string>();
public List<String> BlockNamesAliases; //Íàçâàíèå îòìåòîê public List<MarkItem> MarksHronology;
public List<String> Time; //Âðåìÿ //public List<Vector3> LocationsMO; //Òî÷êè ÌÎ
public List<String> MarksTime; //public List<Vector3> LocationsRTLS; //Òî÷êè ÐÒËÑ
//public List<String> BlockNamesAliases; //Íàçâàíèå îòìåòîê
[Header("UIDocument")] [Header("UIDocument")]
public UIDocument UI; public UIDocument UI;
[Header("Ýêðàí ñ ïåðåìåùåíèåì")] [Header("Ýêðàí ñ ïåðåìåùåíèåì")]
@ -34,12 +46,9 @@ public class ThanksStASSForTheNiceMethod : MonoBehaviour
} }
public void ClearList() //Î÷èñòêà äàííûõ public void ClearList() //Î÷èñòêà äàííûõ
{ {
LocationsMO.Clear(); mapDateTimeRecords.Clear();
LocationsRTLS.Clear();
BlockNamesAliases.Clear();
Time.Clear();
MarksTime.Clear();
} }
void GenerateRequest() //Ãåíåðàöèÿ çàïðîñà void GenerateRequest() //Ãåíåðàöèÿ çàïðîñà
{ {
//StartCoroutine(SpawnTestItems()); //StartCoroutine(SpawnTestItems());
@ -102,15 +111,13 @@ public class ThanksStASSForTheNiceMethod : MonoBehaviour
//request.SetRequestHeader("Access-Control-Allow-Origin", "*"); //request.SetRequestHeader("Access-Control-Allow-Origin", "*");
request.timeout = 60; request.timeout = 60;
yield return request.SendWebRequest(); yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success) if (request.result != UnityWebRequest.Result.Success)
{ {
Debug.Log("Error: " + request.error); Debug.Log("Error: " + request.error);
UIka.RequestButton.SetEnabled(true); UIka.DoActionsOnRequestFailed(request.error);
UIka.forcodes.visible = true;
UIka.forcodes.text = "Â äàííûé ìîìåíò ñåðâèñ âðåìåííî íåäîñòóïåí.";
UIka.loadimg.visible = false;
} }
else else
{ {
@ -118,57 +125,60 @@ public class ThanksStASSForTheNiceMethod : MonoBehaviour
var MethodJSON = JsonConvert.DeserializeObject<MethodJSON>(request.downloadHandler.text); var MethodJSON = JsonConvert.DeserializeObject<MethodJSON>(request.downloadHandler.text);
try try
{ {
foreach (Item x in MethodJSON.respose.items) //Ïàðñèíã äàííûõ foreach (Item tagItem in MethodJSON.respose.items) //Ïàðñèíã äàííûõ
{ {
LocationsMO.Add(new Vector3(x.x_mo, x.z_mo, x.y_mo)); TagRecord record = new TagRecord();
LocationsRTLS.Add(new Vector3(x.x, x.z, x.y)); record.LocationsMO = new Vector3(tagItem.x_mo, tagItem.z_mo, tagItem.y_mo);
Time.Add(x.time.ToLocalTime().ToString()); record.LocationsRTLS = new Vector3(tagItem.x, tagItem.z, tagItem.y);
if (x.block_names_aliases.Count > 1) record.Time = tagItem.time.ToLocalTime().ToString();
if (tagItem.block_names_aliases.Count > 1)
{ {
BlockNamesAliases.Add(x.block_names_aliases[0] + " " + x.block_names_aliases[1]); record.BlockNamesAliases = tagItem.block_names_aliases[0] + " " + tagItem.block_names_aliases[1];
} }
else else
{ {
BlockNamesAliases.Add(x.block_names_aliases[0]); record.BlockNamesAliases = tagItem.block_names_aliases[0];
} }
UIka.SetResponseCode(request.responseCode.ToString());
mapDateTimeRecords.Add(tagItem.time, record);
} }
UIka.SetResponseCode(request.responseCode.ToString());
} }
catch (NullReferenceException) catch (NullReferenceException)
{ {
Debug.Log("ItemsNull"); Debug.Log("ItemsNull");
UIka.loadimg.visible = false; //UIka.loadimg.visible = false;
UIka.DoActionsOnRequestFailed("Äàííûõ çà ïåðèîä íåò");
} }
try try
{ {
foreach (MarksTime y in MethodJSON.respose.marks_time) foreach (MarksTime mark in MethodJSON.respose.marks_time)
{ {
MarksTime.Add(y.name + "!" + y.count_seconds); MarksTime.Add(mark.name + "!" + mark.count_seconds);
} }
} }
catch (NullReferenceException) catch (NullReferenceException)
{ {
Debug.Log("MarksTimeNull"); Debug.Log("MarksTimeNull");
UIka.loadimg.visible = false; UIka.DoActionsOnRequestFailed("Îøèáêà ïîëó÷åíèÿ äàííûõ");
} }
MarksHronology = MethodJSON.respose.marks_hronology;
if (LocationsMO.Count > 1)
if (mapDateTimeRecords.Count > 1)
{ {
Debug.Log("No problemo"); Debug.Log("No problemo");
UIka.SetResponseCode(request.responseCode.ToString()); //Óñòàíîâêà êîäà UIka.SetResponseCode(request.responseCode.ToString()); //Óñòàíîâêà êîäà
UI.visualTreeAsset = GameUIPrefab; //Óñòàíîâêà ýêðàíà äëÿ ïåðåìåùåíèÿ
Personchikn.InitMePlease(); //Âûçîâ èíèöèàëèçàöèÿ â ÈÈ Personchikn.InitMePlease(); //Âûçîâ èíèöèàëèçàöèÿ â ÈÈ
UIka.DoActionsOnRequestSuccess();
Debug.Log("Got data, here go"); Debug.Log("Got data, here go");
} }
else else
{ {
UIka.RequestButton.SetEnabled(true); UIka.DoActionsOnRequestFailed("Íåò äàííûõ çà çàïðàøèâàåìûé ïåðèîä");
UIka.forcodes.visible = true;
UIka.forcodes.text = "Â äàííûõ îáíàðóæåíà îøèáêà.";
UIka.forcodes.text = MethodJSON.error;
UIka.loadimg.visible = false;
} }
} }

1560
Uiika.cs

File diff suppressed because it is too large Load Diff