diff --git a/API/MTEGetMarksLabelsByArrPoint/Data.cs b/API/MTEGetMarksLabelsByArrPoint/Data.cs index 9b856c9..9d352ca 100644 --- a/API/MTEGetMarksLabelsByArrPoint/Data.cs +++ b/API/MTEGetMarksLabelsByArrPoint/Data.cs @@ -36,3 +36,4 @@ namespace Assets.Scripts.API.MTEGetMarksLabelsByArrPoint public float z; } } + diff --git a/MethodJSON.cs b/MethodJSON.cs index e280773..b832c8b 100644 --- a/MethodJSON.cs +++ b/MethodJSON.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using System; +using NpgsqlTypes; // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); public class Item @@ -18,6 +19,14 @@ public class Item 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 int count_seconds { get; set; } @@ -31,6 +40,7 @@ public class ResposeMethod public string time_begin { get; set; } public string time_end { get; set; } public List marks_time { get; set; } + public List marks_hronology { get; set; } } public class MethodJSON diff --git a/PersonScript.cs b/PersonScript.cs index b3ca576..a969877 100644 --- a/PersonScript.cs +++ b/PersonScript.cs @@ -1,11 +1,179 @@ -using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; using System; -using System.Globalization; 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 { [Header("Данные сотрудника")] @@ -17,23 +185,25 @@ public class PersonScript : MonoBehaviour [SerializeField] private int CurrentPoint; //Текущая точка [SerializeField] private ThanksStASSForTheNiceMethod Delogger; //Скрипт с данными [SerializeField] private Uiika Uiika; + + [SerializeField] private Canvas NoSignalCanvas; 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 компоненты + //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")] @@ -50,212 +220,298 @@ public class PersonScript : MonoBehaviour public void InitMePlease() //Инициализация UI и установка начальных значений { - var root = UI.rootVisualElement; - - TimeText = root.Q