28.04.2025
This commit is contained in:
parent
6df08a2ee4
commit
99199eed0d
@ -150,7 +150,7 @@ public class TeleportationChecker
|
||||
|
||||
}
|
||||
float currentDistance = Vector3.Distance(_agent.transform.position, targetPoint);
|
||||
Debug.Log($"{currentDistance} {maxDistance}");
|
||||
//Debug.Log($"{currentDistance} {maxDistance}");
|
||||
if (currentDistance - textScale * _agent.radius < maxDistance )
|
||||
{
|
||||
Debug.Log("Move");
|
||||
|
||||
386
PlayerScript.cs
386
PlayerScript.cs
@ -1,4 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@ -11,12 +10,240 @@ public class PlayerScript : MonoBehaviour
|
||||
public float zoom = 0.25f; // чувствительность при увеличении, колесиком мышки
|
||||
public float zoomMax = 10; // макс. увеличение
|
||||
public float zoomMin = 3; // мин. увеличение
|
||||
private float X, Y;
|
||||
public float X, Y;
|
||||
|
||||
void Start()
|
||||
RayClusterFinder rayClusterFinder;
|
||||
void Start()
|
||||
{
|
||||
rayClusterFinder = new RayClusterFinder();
|
||||
}
|
||||
|
||||
}
|
||||
Vector3 playerOffset = new Vector3(0,1.5f,0);
|
||||
Vector3 lastPlayerPosition = new Vector3(), lastCameraPosition = new Vector3();
|
||||
|
||||
public static Quaternion GetRotationBetweenVectors(Vector3 a, Vector3 b)
|
||||
{
|
||||
// Íîðìàëèçóåì âåêòîðû (íà ñëó÷àé, åñëè îíè íå íîðìàëèçîâàíû)
|
||||
a = a.normalized;
|
||||
b = b.normalized;
|
||||
|
||||
// Åñëè âåêòîðû êîëëèíåàðíû:
|
||||
if (a == b)
|
||||
return Quaternion.identity; // Íåò âðàùåíèÿ
|
||||
|
||||
if (a == -b)
|
||||
{
|
||||
// Åñëè âåêòîðû ïðîòèâîïîëîæíû, âûáèðàåì ïðîèçâîëüíóþ îñü, ïåðïåíäèêóëÿðíóþ `a`
|
||||
Vector3 axis1 = (Mathf.Abs(a.x) > 0.9f) ? Vector3.Cross(a, Vector3.up).normalized
|
||||
: Vector3.Cross(a, Vector3.right).normalized;
|
||||
return Quaternion.AngleAxis(180f, axis1);
|
||||
}
|
||||
|
||||
// Îñü âðàùåíèÿ (íîðìàëèçîâàííîå âåêòîðíîå ïðîèçâåäåíèå)
|
||||
Vector3 axis = Vector3.Cross(a, b).normalized;
|
||||
|
||||
// Óãîë âðàùåíèÿ (÷åðåç ñêàëÿðíîå ïðîèçâåäåíèå)
|
||||
float angle = Mathf.Acos(Vector3.Dot(a, b)) * Mathf.Rad2Deg;
|
||||
|
||||
// Âîçâðàùàåì êâàòåðíèîí
|
||||
return Quaternion.AngleAxis(angle, axis);
|
||||
}
|
||||
|
||||
public static Quaternion GetRotationBetweenVectorsWithZeroZ(Vector3 a, Vector3 b)
|
||||
{
|
||||
// Íîðìàëèçóåì âåêòîðû
|
||||
a = a.normalized;
|
||||
b = b.normalized;
|
||||
|
||||
// Åñëè âåêòîðû êîëëèíåàðíû
|
||||
if (a == b)
|
||||
return Quaternion.identity;
|
||||
|
||||
if (a == -b)
|
||||
{
|
||||
// Äëÿ ïðîòèâîïîëîæíûõ âåêòîðîâ âûáèðàåì îñü, ïåðïåíäèêóëÿðíóþ a è ëåæàùóþ â ïëîñêîñòè XY
|
||||
Vector3 axis1 = new Vector3(-a.y, a.x, 0).normalized;
|
||||
return Quaternion.AngleAxis(180f, axis1);
|
||||
}
|
||||
|
||||
// Íàõîäèì îñü âðàùåíèÿ
|
||||
Vector3 axis = Vector3.Cross(a, b).normalized;
|
||||
|
||||
// Ïðîåöèðóåì îñü íà ïëîñêîñòü XY, ÷òîáû èñêëþ÷èòü Z-êîìïîíåíòó
|
||||
Vector3 flatAxis = new Vector3(axis.x, axis.y, 0).normalized;
|
||||
|
||||
// Åñëè ïðîåêöèÿ íóëåâàÿ (âåêòîðû îòëè÷àþòñÿ òîëüêî ïî Z),
|
||||
// èñïîëüçóåì îñü X èëè Y
|
||||
if (flatAxis == Vector3.zero)
|
||||
{
|
||||
flatAxis = Vector3.up;
|
||||
}
|
||||
|
||||
// Âû÷èñëÿåì óãîë ìåæäó âåêòîðàìè
|
||||
float angle = Mathf.Acos(Vector3.Dot(a, b)) * Mathf.Rad2Deg;
|
||||
|
||||
// Ñîçäàåì êâàòåðíèîí ñ íóëåâûì ïîâîðîòîì âîêðóã Z
|
||||
Quaternion rotation = Quaternion.AngleAxis(angle, flatAxis);
|
||||
|
||||
// Äîïîëíèòåëüíî óáåäèìñÿ, ÷òî â êâàòåðíèîíå íåò ïîâîðîòà âîêðóã Z
|
||||
Vector3 euler = rotation.eulerAngles;
|
||||
return Quaternion.Euler(euler.x, euler.y, 0);
|
||||
}
|
||||
|
||||
static float GetDeltaAzimut(float a, float b)
|
||||
{
|
||||
// Íîðìàëèçóåì óãëû â äèàïàçîí [0, 360)
|
||||
a = (a % 360 + 360) % 360;
|
||||
b = (b % 360 + 360) % 360;
|
||||
|
||||
// Âû÷èñëÿåì ðàçíèöó
|
||||
float delta = b - a;
|
||||
|
||||
// Êîððåêòèðóåì ðàçíèöó äî ìèíèìàëüíîãî çíà÷åíèÿ
|
||||
if (delta > 180)
|
||||
delta -= 360;
|
||||
else if (delta < -180)
|
||||
delta += 360;
|
||||
|
||||
return delta;
|
||||
//if (a < 0)
|
||||
//{
|
||||
// a = a * -1 + 180;
|
||||
//}
|
||||
|
||||
//if (b < 0)
|
||||
//{
|
||||
// b = b * -1 + 180;
|
||||
//}
|
||||
|
||||
//return b - a;
|
||||
}
|
||||
|
||||
public static Quaternion GetRotationBetweenVectorsWithZeroZ1(Vector3 a, Vector3 b, out float deltaZenith, out float deltaAzimuth)
|
||||
{
|
||||
// Íîðìàëèçàöèÿ âåêòîðîâ
|
||||
a = a.normalized;
|
||||
b = b.normalized;
|
||||
|
||||
// Àçèìóò è çåíèò äëÿ A
|
||||
float azimuthA = Mathf.Atan2(a.z, a.x) * Mathf.Rad2Deg;
|
||||
float zenithA = Mathf.Acos(a.y) * Mathf.Rad2Deg;
|
||||
|
||||
// Àçèìóò è çåíèò äëÿ B
|
||||
float azimuthB = Mathf.Atan2(b.z, b.x) * Mathf.Rad2Deg;
|
||||
float zenithB = Mathf.Acos(b.y) * Mathf.Rad2Deg;
|
||||
|
||||
// Ðàçíèöà àçèìóòîâ (ñ ó÷¸òîì öèêëè÷íîñòè)
|
||||
//float deltaAzimuth = Mathf.DeltaAngle(azimuthA, azimuthB);
|
||||
|
||||
// Ðàçíèöà çåíèòîâ
|
||||
deltaZenith = zenithB - zenithA;
|
||||
|
||||
//Quaternion.Euler(0, 90f, 0f) * Vector3(0, 0, 1) == Vector3(1,0,0);
|
||||
deltaAzimuth = GetDeltaAzimut(azimuthA,azimuthB);
|
||||
|
||||
Quaternion finalRot = Quaternion.Euler(deltaZenith, -deltaAzimuth, 0f);
|
||||
|
||||
// Ïðîâåðêà (îïöèîíàëüíî)
|
||||
Vector3 rotatedA = finalRot * a;
|
||||
if ((rotatedA - b).magnitude > 0.01f)
|
||||
{
|
||||
deltaZenith *= -1;
|
||||
finalRot = Quaternion.Euler(deltaZenith, -deltaAzimuth, 0f);
|
||||
rotatedA = finalRot * a;
|
||||
if ((rotatedA - b).magnitude > 0.01f)
|
||||
{
|
||||
Debug.LogWarning("Ïîãðåøíîñòü ïðåâûøàåò äîïóñòèìóþ!");
|
||||
}
|
||||
}
|
||||
return finalRot;
|
||||
}
|
||||
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (SceneParams.Instance.cameraSettings.IsAutoRotateCamera == false || SceneParams.Instance.cameraSettings.IsStartPos) return;
|
||||
if (lastPlayerPosition == target.transform.position &&
|
||||
lastCameraPosition == transform.position) return;
|
||||
lastPlayerPosition = target.transform.position;
|
||||
lastCameraPosition = transform.position;
|
||||
Vector3 player = target.transform.position;
|
||||
player += playerOffset;
|
||||
|
||||
Vector3[] checkiablePoints = new Vector3[3]
|
||||
{
|
||||
new Vector3(player.x,player.y,player.z+0.1f),
|
||||
new Vector3(player.x,player.y,player.z+1.0f),
|
||||
new Vector3(player.x, player.y, player.z+1.8f)
|
||||
};
|
||||
|
||||
bool isCast = false;
|
||||
Vector3 direction;
|
||||
|
||||
foreach (var point in checkiablePoints)
|
||||
{
|
||||
direction = transform.position - point;
|
||||
if (Physics.Raycast(point, direction.normalized, out var hit, Vector3.Distance(point, transform.position))){
|
||||
isCast = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isCast)
|
||||
{
|
||||
Debug.Log($"{player} - {transform.position}");
|
||||
Vector3 newPosition = rayClusterFinder.Calculate(checkiablePoints);
|
||||
|
||||
// 1. Âû÷èñëÿåì íîâîå ñìåùåíèå
|
||||
float distance = Vector3.Distance(target.position, newPosition);
|
||||
|
||||
// 2. Óñòàíàâëèâàåì ñìåùåíèå ïî îñè Z
|
||||
// Ðàñ÷¸ò Z âåêòîðà äëÿ êîíñòàòíûõ äâóõ ïàðàìåòðîâ x,y (0,1,z)
|
||||
offset.z = Mathf.Sqrt(distance * distance - 1);
|
||||
|
||||
offset.z *= -1;
|
||||
|
||||
//transform.LookAt(target);
|
||||
//return;
|
||||
// 3. Âû÷èñëÿåì íàïðàâëåíèå îò íîâîé ïîçèöèè êàìåðû ê îáúåêòó
|
||||
Vector3 directionToTarget = (newPosition-target.position);
|
||||
// 4. Âû÷èñëÿåì âðàùåíèå íà îñíîâå íàïðàâëåíèÿ
|
||||
//Quaternion rotation = GetRotationBetweenVectors(offset, directionToTarget);
|
||||
Quaternion rotation = GetRotationBetweenVectorsWithZeroZ1(offset, directionToTarget, out var deltaZenith, out var deltaAzimuth);
|
||||
//Quaternion.Euler(deltaZenith, -deltaAzimuth, 0f);
|
||||
//Quaternion.Euler(-Y, X, 0f);
|
||||
// Y = deltaZenit
|
||||
// X = -deltaAzimut //
|
||||
//offset *= -1;
|
||||
//deltaZenith = 180.0f - deltaZenith;
|
||||
//deltaAzimuth = deltaAzimuth + 180.0f;
|
||||
//rotation = Quaternion.Inverse(rotation);
|
||||
//rotation = Quaternion.Euler(deltaZenith, -(deltaAzimuth), 0f);
|
||||
Y = -deltaZenith;
|
||||
X = -deltaAzimuth;
|
||||
// 5. Ïðèìåíÿåì âðàùåíèå ê ëîêàëüíîé ðîòàöèè îáúåêòà
|
||||
transform.localRotation = rotation;
|
||||
|
||||
// 6. Îáíîâëÿåì ïîçèöèþ êàìåðû ñ ó÷åòîì ñìåùåíèÿ
|
||||
// Çäåñü ìû èñïîëüçóåì ëîêàëüíóþ ðîòàöèþ äëÿ ðàñ÷åòà íîâîé ïîçèöèè
|
||||
Vector3 calculatedPosition = transform.localRotation * offset + target.position;
|
||||
|
||||
// 7. Óñòàíàâëèâàåì ïîçèöèþ êàìåðû
|
||||
//transform.position = calculatedPosition;
|
||||
lastCameraPosition = calculatedPosition;
|
||||
|
||||
// 8. Ïðîâåðÿåì, ñîâïàäàåò ëè ðàññ÷èòàííàÿ ïîçèöèÿ ñ çàäàííîé
|
||||
distance = Vector3.Distance(newPosition, calculatedPosition);
|
||||
if (distance < 0.01f)
|
||||
{
|
||||
Debug.Log("Ðàññ÷èòàíî âåðíî");
|
||||
} else
|
||||
{
|
||||
Debug.Log("Ðàññ÷èòàíî íå âåðíî");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetPlayerPosition()
|
||||
{
|
||||
@ -52,3 +279,154 @@ public class PlayerScript : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RayClusterFinder
|
||||
{
|
||||
public float proximityRadius = 5f; // Ðàäèóñ äëÿ ïîèñêà áëèæàéøèõ ëó÷åé
|
||||
|
||||
public float maxDistance = 10f; // Ìàêñèìàëüíàÿ äëèíà ëó÷à
|
||||
public float minDistance = 3f; // Ìàêñèìàëüíàÿ äëèíà ëó÷à
|
||||
public float upperZenithAngle = 5f; // Óãîë âåðõíåãî çåíèòà
|
||||
public float lowerZenithAngle = -35f; // Óãîë íèæíåãî çåíèòà
|
||||
public float azimuthStep = 10f; // Øàã ïî àçèìóòó
|
||||
|
||||
private List<Vector3> rayOrigins = new List<Vector3>(); // Ñïèñîê äëÿ õðàíåíèÿ íà÷àëüíûõ òî÷åê ëó÷åé
|
||||
|
||||
public RayClusterFinder()
|
||||
{
|
||||
}
|
||||
|
||||
Vector3 bestVertex;
|
||||
|
||||
public Vector3 Calculate(Vector3[] origin)
|
||||
{
|
||||
//CastRays();
|
||||
CastSphericalRays(origin);
|
||||
FindRayWithMostNeighbors(origin);
|
||||
return bestVertex;
|
||||
}
|
||||
|
||||
void CastSphericalRays(Vector3[] originArr)
|
||||
{
|
||||
rayOrigins.Clear();
|
||||
|
||||
foreach (var origin in originArr)
|
||||
{
|
||||
// Ïðåîáðàçóåì óãëû â ðàäèàíû
|
||||
float upperZenithRad = (upperZenithAngle + 90) * Mathf.Deg2Rad;
|
||||
float lowerZenithRad = (lowerZenithAngle + 90) * Mathf.Deg2Rad;
|
||||
float azimuthStepRad = azimuthStep * Mathf.Deg2Rad;
|
||||
|
||||
// Ãåíåðàöèÿ ëó÷åé
|
||||
for (float zenith = lowerZenithRad; zenith <= upperZenithRad; zenith += azimuthStepRad)
|
||||
{
|
||||
for (float azimuth = 0; azimuth < 360 * Mathf.Deg2Rad; azimuth += azimuthStepRad)
|
||||
{
|
||||
// Âû÷èñëÿåì íàïðàâëåíèå ëó÷à
|
||||
float x = Mathf.Sin(zenith) * Mathf.Cos(azimuth);
|
||||
float y = Mathf.Cos(zenith);
|
||||
float z = Mathf.Sin(zenith) * Mathf.Sin(azimuth);
|
||||
Vector3 direction = new Vector3(x, y, z).normalized;
|
||||
|
||||
// Ïîçèöèÿ íà÷àëà ëó÷à (öåíòð êàïñóëû)
|
||||
|
||||
// Îòïðàâëÿåì ëó÷
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(origin, direction, out hit, maxDistance))
|
||||
{
|
||||
// Ïðîâåðÿåì, åñëè ðàññòîÿíèå äî ñòîëêíîâåíèÿ ìåíüøå èëè ðàâíî maxDistance
|
||||
if (hit.distance <= maxDistance && hit.distance >= minDistance)
|
||||
{
|
||||
rayOrigins.Add(hit.point); // Ñîõðàíÿåì âàëèäíîå ñòîëêíîâåíèå
|
||||
//Debug.DrawLine(origin, hit.point, Color.red, 1000000); // Îòîáðàæàåì ëó÷ äî ñòîëêíîâåíèÿ
|
||||
//Debug.Log($"Hit: {hit.collider.name} at {hit.point}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rayOrigins.Add(origin + direction * maxDistance);
|
||||
//Debug.DrawRay(origin, direction * maxDistance, Color.green, 1000000); // Îòîáðàæàåì ëó÷, åñëè íåò ñòîëêíîâåíèÿ
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void FindRayWithMostNeighbors(Vector3[] originalCenterArr)
|
||||
{
|
||||
Vector3 originalCenter = Vector3.zero;
|
||||
|
||||
// 1. Calculate the center of all points
|
||||
foreach (var origin in originalCenterArr)
|
||||
{
|
||||
originalCenter += origin;
|
||||
}
|
||||
originalCenter /= rayOrigins.Count; // Divide by the number of points to get the center
|
||||
|
||||
|
||||
int maxNeighbors = 0;
|
||||
List<Vector3> neighborsVertex = new List<Vector3>();
|
||||
Vector3 center = Vector3.zero;
|
||||
|
||||
// 1. Calculate the center of all points
|
||||
foreach (var origin in rayOrigins)
|
||||
{
|
||||
center += origin;
|
||||
}
|
||||
center /= rayOrigins.Count; // Divide by the number of points to get the center
|
||||
|
||||
// 2. Find rays with the most neighbors
|
||||
foreach (var origin in rayOrigins)
|
||||
{
|
||||
int neighborCount = 0;
|
||||
|
||||
foreach (var otherOrigin in rayOrigins)
|
||||
{
|
||||
if (origin != otherOrigin && Vector3.Distance(origin, otherOrigin) <= proximityRadius)
|
||||
{
|
||||
neighborCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (neighborCount > maxNeighbors)
|
||||
{
|
||||
neighborsVertex.Clear();
|
||||
maxNeighbors = neighborCount;
|
||||
neighborsVertex.Add(origin);
|
||||
}
|
||||
else if (neighborCount == maxNeighbors)
|
||||
{
|
||||
neighborsVertex.Add(origin);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Find the vector from the original center to the calculated center
|
||||
Vector3 directionToCenter = (center - originalCenter).normalized;
|
||||
|
||||
// 4. Find the point that has the closest direction to this vector
|
||||
Vector3 closestVertex = Vector3.zero;
|
||||
float closestAngle = float.MaxValue;
|
||||
|
||||
foreach (var vertex in neighborsVertex)
|
||||
{
|
||||
Debug.DrawLine(originalCenter, vertex, Color.green, 15);
|
||||
Vector3 directionFromOriginal = (vertex - originalCenter).normalized; // Direction from original center to the vertex
|
||||
float angle = Vector3.Angle(directionToCenter, directionFromOriginal); // Calculate the angle between the two directions
|
||||
|
||||
if (angle < closestAngle)
|
||||
{
|
||||
closestAngle = angle;
|
||||
closestVertex = vertex;
|
||||
}
|
||||
}
|
||||
|
||||
//Debug.Log($"Closest direction to the center: {closestVertex}");
|
||||
//Debug.Log($"Center0: {originalCenter}");
|
||||
//Debug.Log($"Center1: {center}");
|
||||
//Debug.Log($"vector: {center - originalCenter}");
|
||||
|
||||
bestVertex = closestVertex;
|
||||
Debug.DrawLine(originalCenter, originalCenter + (center-originalCenter).normalized * 10f, Color.red, 15);
|
||||
Debug.DrawLine(originalCenter, originalCenter + (closestVertex- originalCenter) * 1.5f, Color.blue, 15);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ class SceneParams
|
||||
get => isBlockMove;
|
||||
set
|
||||
{
|
||||
if (Instance.IsDataHistoryLoadged)
|
||||
if (Instance.IsDataHistoryLoaded)
|
||||
isBlockMove = value;
|
||||
}
|
||||
}
|
||||
@ -45,6 +45,8 @@ class SceneParams
|
||||
|
||||
public Transform DefaultTransform = null;
|
||||
public bool IsStartPos { get; set; } = true;
|
||||
|
||||
public bool IsAutoRotateCamera { get; set; } = true;
|
||||
}
|
||||
|
||||
public class SpawnMovePoint
|
||||
|
||||
82
SphericalRaycaster.cs
Normal file
82
SphericalRaycaster.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SphericalRaycaster : MonoBehaviour
|
||||
{
|
||||
public Transform player; // Ссылка на объект игрока (капсулу)
|
||||
public float maxDistance = 10f; // Максимальная длина луча
|
||||
public float minDistance = 3f; // Максимальная длина луча
|
||||
public float upperZenithAngle = 30f; // Угол верхнего зенита
|
||||
public float lowerZenithAngle = -30f; // Угол нижнего зенита
|
||||
public float azimuthStep = 15f; // Шаг по азимуту
|
||||
|
||||
//private List<RaycastHit> validHits = new List<RaycastHit>(); // Список для хранения валидных столкновений
|
||||
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
bool fa = true;
|
||||
private void Update()
|
||||
{
|
||||
if (fa)
|
||||
{
|
||||
CastSphericalRays();
|
||||
fa = false;
|
||||
}
|
||||
|
||||
Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
|
||||
float distance = 100f;
|
||||
Debug.DrawRay(ray.origin, ray.direction * distance, Color.red);
|
||||
//RaycastHit hit;
|
||||
}
|
||||
List<Vector3> rayOrigins = new List<Vector3>();
|
||||
void CastSphericalRays()
|
||||
{
|
||||
rayOrigins.Clear();
|
||||
|
||||
// Преобразуем углы в радианы
|
||||
float upperZenithRad = (upperZenithAngle+90) * Mathf.Deg2Rad;
|
||||
float lowerZenithRad = (lowerZenithAngle+90) * Mathf.Deg2Rad;
|
||||
float azimuthStepRad = azimuthStep * Mathf.Deg2Rad;
|
||||
|
||||
// Генерация лучей
|
||||
for (float zenith = lowerZenithRad; zenith <= upperZenithRad; zenith += azimuthStepRad)
|
||||
{
|
||||
for (float azimuth = 0; azimuth < 360 * Mathf.Deg2Rad; azimuth += azimuthStepRad)
|
||||
{
|
||||
// Вычисляем направление луча
|
||||
float x = Mathf.Sin(zenith) * Mathf.Cos(azimuth);
|
||||
float y = Mathf.Cos(zenith);
|
||||
float z = Mathf.Sin(zenith) * Mathf.Sin(azimuth);
|
||||
Vector3 direction = new Vector3(x, y, z).normalized;
|
||||
|
||||
// Позиция начала луча (центр капсулы)
|
||||
Vector3 origin = player.position;
|
||||
|
||||
// Отправляем луч
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(origin, direction, out hit, maxDistance))
|
||||
{
|
||||
// Проверяем, если расстояние до столкновения меньше или равно maxDistance
|
||||
if (hit.distance <= maxDistance && hit.distance >= minDistance)
|
||||
{
|
||||
rayOrigins.Add(hit.point); // Сохраняем валидное столкновение
|
||||
Debug.DrawLine(origin, hit.point, Color.red, 1000000); // Отображаем луч до столкновения
|
||||
Debug.Log($"Hit: {hit.collider.name} at {hit.point}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rayOrigins.Add(origin + direction * maxDistance);
|
||||
//Debug.DrawRay(origin, direction * maxDistance, Color.green, 1000000); // Отображаем луч, если нет столкновения
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Calculate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
11
SphericalRaycaster.cs.meta
Normal file
11
SphericalRaycaster.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c798093f65a17ae4a92da0a1ed7ffec5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
240
Uiika.cs
240
Uiika.cs
@ -9,6 +9,9 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Assets.Scripts;
|
||||
using UI.Dates;
|
||||
using Trackman;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
|
||||
class PlayBackControlUI
|
||||
{
|
||||
@ -27,6 +30,9 @@ class PlayBackControlUI
|
||||
public VisualElement Speedx16 { get; set; }
|
||||
public VisualElement Speedx32 { get; set; }
|
||||
public VisualElement Speedx64 { get; set; }
|
||||
public VisualElement RotateCamera { get; set; }
|
||||
public Button ButtonRotateCamera { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class TextInputModel
|
||||
@ -89,8 +95,10 @@ public class TextInputModel
|
||||
}
|
||||
}
|
||||
cursorIndex = newValue;
|
||||
Debug.Log(newValue);
|
||||
|
||||
}
|
||||
IsNeedSkeep = true;
|
||||
EventIndexChange.Invoke(cursorIndex);
|
||||
}
|
||||
}
|
||||
@ -98,7 +106,7 @@ public class TextInputModel
|
||||
public string Mask { get; set; } = null;
|
||||
public char Pattern = '*';
|
||||
|
||||
|
||||
public bool IsNeedSkeep = false;
|
||||
public bool IsDoImmidateUpdate = false;
|
||||
public string Value { get; set; } = "";
|
||||
|
||||
@ -158,6 +166,21 @@ public class ProgressBarModel
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCurrentTimeSeconds(int secondsFromBegin)
|
||||
{
|
||||
currentTime = dateBegin.AddSeconds(secondsFromBegin);
|
||||
|
||||
if (currentTime > dateEnd)
|
||||
{
|
||||
currentTime = dateEnd;
|
||||
FinishWatch.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentTimeChanged.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public float GetProgress()
|
||||
{
|
||||
return (float)(currentTime - dateBegin).TotalSeconds / (float)(dateEnd - dateBegin).TotalSeconds;
|
||||
@ -271,6 +294,42 @@ class ProgressBarController
|
||||
speedValueDictionary.Add(ui.PlayBackControl.Speedx32, 32);
|
||||
speedValueDictionary.Add(ui.PlayBackControl.Speedx64, 64);
|
||||
|
||||
ui.PlayBackControl.ButtonRotateCamera.clicked += () => {
|
||||
if (SceneParams.Instance.cameraSettings.IsAutoRotateCamera)
|
||||
{
|
||||
SceneParams.Instance.cameraSettings.IsAutoRotateCamera = false;
|
||||
// Выключаем поворот камеры
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneParams.Instance.cameraSettings.IsAutoRotateCamera = true;
|
||||
// Включаем поворот камеры
|
||||
}
|
||||
|
||||
DoUpdateRotateCamera();
|
||||
};
|
||||
|
||||
DoUpdateRotateCamera();
|
||||
|
||||
}
|
||||
|
||||
private void DoUpdateRotateCamera()
|
||||
{
|
||||
if (!SceneParams.Instance.cameraSettings.IsAutoRotateCamera)
|
||||
{
|
||||
if (ColorUtility.TryParseHtmlString("#FFFFFFFF", out Color color))
|
||||
{
|
||||
ui.PlayBackControl.RotateCamera.style.unityBackgroundImageTintColor = color;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ColorUtility.TryParseHtmlString("#00A1E7FF", out Color color))
|
||||
{
|
||||
ui.PlayBackControl.RotateCamera.style.unityBackgroundImageTintColor = color;
|
||||
};
|
||||
}
|
||||
ui.PlayBackControl.RotateCamera.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
void InitSpeedButton(VisualElement control)
|
||||
@ -332,11 +391,12 @@ class ProgressBarController
|
||||
if (evt.button == (int)UnityEngine.UIElements.MouseButton.LeftMouse)
|
||||
{
|
||||
isDragging = true; // Устанавливаем флаг перетаскивания
|
||||
SceneParams.Instance.cameraSettings.IsBlockMove = true;
|
||||
//SceneParams.Instance.cameraSettings.IsBlockMove = true;
|
||||
evt.StopPropagation(); // Останавливаем дальнейшую обработку события
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnMouseUp(MouseUpEvent evt)
|
||||
{
|
||||
// Проверяем, отпущена ли левая кнопка мыши
|
||||
@ -345,7 +405,7 @@ class ProgressBarController
|
||||
isDragging = false; // Сбрасываем флаг перетаскивания
|
||||
evt.StopPropagation(); // Останавливаем дальнейшую обработку события
|
||||
UpdateWithX(evt.localMousePosition.x);
|
||||
SceneParams.Instance.cameraSettings.IsBlockMove = false;
|
||||
//SceneParams.Instance.cameraSettings.IsBlockMove = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,7 +413,7 @@ class ProgressBarController
|
||||
{
|
||||
isDragging = false;
|
||||
evt.StopPropagation();
|
||||
SceneParams.Instance.cameraSettings.IsBlockMove = false;
|
||||
//SceneParams.Instance.cameraSettings.IsBlockMove = false;
|
||||
|
||||
}
|
||||
|
||||
@ -718,9 +778,18 @@ public class RequestFormController
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
model.Tag.CursorIndex = ui.TagTextField.cursorIndex;
|
||||
//if (model.Tag.IsNeedSkeep)
|
||||
//{
|
||||
// //model.Tag.IsNeedSkeep = false;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
model.Tag.CursorIndex = ui.TagTextField.cursorIndex;
|
||||
//}
|
||||
|
||||
model.DateBegin.CursorIndex = ui.DateBeginTextField.cursorIndex;
|
||||
model.DateEnd.CursorIndex = ui.DateEndTextField.cursorIndex;
|
||||
}
|
||||
@ -814,6 +883,8 @@ public class Uiika : MonoBehaviour
|
||||
public VisualTreeAsset tabletemplate;
|
||||
public VisualTreeAsset markPointOnBar;
|
||||
public GameObject CanvasCalendar;
|
||||
public Texture2D CursorSelect;
|
||||
|
||||
|
||||
public Label forcodes { get; set; } // <-- UI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@ -836,6 +907,7 @@ public class Uiika : MonoBehaviour
|
||||
|
||||
void TextFiledCursorIndexChanged(TextField textField, int pos)
|
||||
{
|
||||
textField.cursorIndex = pos;
|
||||
textField.SelectRange(pos, pos + 1);
|
||||
}
|
||||
|
||||
@ -1009,6 +1081,8 @@ public class Uiika : MonoBehaviour
|
||||
Speedx16 = GetVisualElementByName<VisualElement>("Speedx16"),
|
||||
Speedx32 = GetVisualElementByName<VisualElement>("Speedx32"),
|
||||
Speedx64 = GetVisualElementByName<VisualElement>("Speedx64"),
|
||||
RotateCamera = GetVisualElementByName<VisualElement>("rotate-camera"),
|
||||
ButtonRotateCamera = GetVisualElementByName<Button>("ButtonRotateCamera"),
|
||||
},
|
||||
RootElement = GetVisualElementByName<VisualElement>("PlayBackControl"),
|
||||
};
|
||||
@ -1076,12 +1150,12 @@ public class Uiika : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
void BlockZoom()
|
||||
public void BlockZoom()
|
||||
{
|
||||
SceneParams.Instance.cameraSettings.IsBlockMove = true;
|
||||
SceneParams.Instance.cameraSettings.IsBlockZoom = true;
|
||||
}
|
||||
private void UnBlockZoom()
|
||||
public void UnBlockZoom()
|
||||
{
|
||||
SceneParams.Instance.cameraSettings.IsBlockMove = false;
|
||||
SceneParams.Instance.cameraSettings.IsBlockZoom = false;
|
||||
@ -1134,6 +1208,7 @@ public class Uiika : MonoBehaviour
|
||||
|
||||
private void InitTextField(TextFieldData textField)
|
||||
{
|
||||
textField.Field.selectAllOnMouseUp = false;
|
||||
textField.Field.selectAllOnFocus = false;
|
||||
textField.Field.RegisterCallback<KeyDownEvent>((KeyDownEvent ev) =>
|
||||
{
|
||||
@ -1185,7 +1260,7 @@ public class Uiika : MonoBehaviour
|
||||
requestFormController.UI.TagTextField = field;
|
||||
field.SetValueWithoutNotify(requestFormController.Model.Tag.Value);
|
||||
field.cursorIndex = requestFormController.Model.Tag.CursorIndex;
|
||||
|
||||
//field.selectAllOnFocus = false;
|
||||
field.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
UpdateTextField(IsValidTag, tagTextField, evt.newValue);
|
||||
@ -1197,8 +1272,8 @@ public class Uiika : MonoBehaviour
|
||||
{
|
||||
dateBeginTextField = new TextFieldData() { Field = field, Model = requestFormController.Model.DateBegin };
|
||||
requestFormController.UI.DateBeginTextField = field;
|
||||
field.cursorIndex = requestFormController.Model.DateBegin.CursorIndex;
|
||||
field.SetValueWithoutNotify(requestFormController.Model.DateBegin.Value);
|
||||
field.cursorIndex = requestFormController.Model.DateBegin.CursorIndex;
|
||||
field.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
UpdateTextField(IsValidDate, dateBeginTextField, evt.newValue);
|
||||
@ -1389,6 +1464,13 @@ public class Uiika : MonoBehaviour
|
||||
|
||||
forcodes.text = "Ответ HTTP: " + Code;
|
||||
}
|
||||
|
||||
class MarkHronologyRecord
|
||||
{
|
||||
public int totalCountSeconds;
|
||||
public List<MarkItem> items;
|
||||
}
|
||||
|
||||
public void MakeTable()
|
||||
{
|
||||
tagHistoryController.UI.ScrollTable.Clear();
|
||||
@ -1403,10 +1485,11 @@ public class Uiika : MonoBehaviour
|
||||
// newElement.Q<Label>("MarkOtmetka").text = strArray[0];
|
||||
// newElement.style.width = new StyleLength(new Length(100, LengthUnit.Percent));
|
||||
// tagHistoryController.UI.ScrollTable.Add(newElement);
|
||||
|
||||
//}
|
||||
|
||||
Dictionary<string, int> timeSpentDictionary = new Dictionary<string, int>();
|
||||
|
||||
|
||||
Dictionary<string, MarkHronologyRecord> timeSpentDictionary = new Dictionary<string, MarkHronologyRecord>();
|
||||
|
||||
// Подсчет времени
|
||||
foreach (var item in Caller.MarksHronology)
|
||||
@ -1415,33 +1498,152 @@ public class Uiika : MonoBehaviour
|
||||
if (timeSpentDictionary.ContainsKey(item.name))
|
||||
{
|
||||
// Если есть, добавляем время
|
||||
timeSpentDictionary[item.name] += item.time_spend;
|
||||
var findedElm = timeSpentDictionary[item.name];
|
||||
findedElm.totalCountSeconds += item.time_spend;
|
||||
findedElm.items.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Если нет, создаем новую запись
|
||||
timeSpentDictionary[item.name] = item.time_spend;
|
||||
var newElement = new MarkHronologyRecord();
|
||||
newElement.totalCountSeconds = item.time_spend;
|
||||
newElement.items = new List<MarkItem>() { item};
|
||||
timeSpentDictionary.Add(item.name, newElement) ;
|
||||
}
|
||||
}
|
||||
|
||||
var sortedTimeSpent = timeSpentDictionary
|
||||
.OrderByDescending(entry => entry.Value) // Сортировка по убыванию
|
||||
var sortedTimeSpent = timeSpentDictionary
|
||||
.OrderByDescending(entry => entry.Value.totalCountSeconds) // Сортировка по убыванию
|
||||
.ToList();
|
||||
|
||||
|
||||
foreach (var entry in sortedTimeSpent)
|
||||
{
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(entry.Value);
|
||||
TimeSpan timeSpan = TimeSpan.FromSeconds(entry.Value.totalCountSeconds);
|
||||
|
||||
var newElement = tagHistoryController.UI.TableRowAsset.Instantiate();
|
||||
newElement.Q<Label>("MarkTimeSec").text = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);
|
||||
newElement.Q<Label>("MarkOtmetka").text = entry.Key;
|
||||
var markOtmetka = newElement.Q<Label>("MarkOtmetka");
|
||||
markOtmetka.text = entry.Key;
|
||||
|
||||
newElement.Q<Label>("CountElements").text = $"{entry.Value.items.Count}";
|
||||
|
||||
|
||||
newElement.pickingMode = PickingMode.Position;
|
||||
Button button = newElement.Q<Button>("Button");
|
||||
ScrollView scrollView = newElement.Q<ScrollView>("ScrollView");
|
||||
if (scrollView != null)
|
||||
{
|
||||
scrollView.style.height = new StyleLength(new Length(0, LengthUnit.Pixel));
|
||||
scrollView.style.visibility = Visibility.Hidden;
|
||||
VisualElement countBackground = newElement.Q<VisualElement>("CountBackground");
|
||||
button.clicked += () =>
|
||||
{
|
||||
|
||||
if (scrollView.style.visibility == Visibility.Hidden)
|
||||
{
|
||||
scrollView.style.height = StyleKeyword.Auto;//new StyleLength(new Length(400, LengthUnit.Pixel));
|
||||
scrollView.style.visibility = Visibility.Visible;
|
||||
|
||||
if (ColorUtility.TryParseHtmlString("#00A1E7", out var color))
|
||||
{
|
||||
countBackground.style.backgroundColor = color;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollView.style.height = new StyleLength(new Length(0, LengthUnit.Pixel));
|
||||
scrollView.style.visibility = Visibility.Hidden;
|
||||
|
||||
if (ColorUtility.TryParseHtmlString("#51575E", out var color))
|
||||
{
|
||||
countBackground.style.backgroundColor = color;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
foreach (var item in entry.Value.items)
|
||||
{
|
||||
Button newLabel = new Button();
|
||||
TimeSpan timeSpan1 = TimeSpan.FromSeconds(item.time_start);
|
||||
TimeSpan timeSpan2 = TimeSpan.FromSeconds(item.time_end);
|
||||
string text1 = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan1.Hours, timeSpan1.Minutes, timeSpan1.Seconds);
|
||||
string text2 = string.Format("{0:D2}:{1:D2}:{2:D2}", timeSpan2.Hours, timeSpan2.Minutes, timeSpan2.Seconds);
|
||||
|
||||
newLabel.text = $"{text1} - {text2}";
|
||||
//newLabel.AddToClassList(".unity-base-override");
|
||||
//newLabel.AddToClassList(".Frame-782");
|
||||
//newLabel.AddToClassList(".n-nine");
|
||||
|
||||
Color color;
|
||||
if (ColorUtility.TryParseHtmlString("#6D757E", out color))
|
||||
{
|
||||
newLabel.style.backgroundColor = color;
|
||||
};
|
||||
|
||||
if (ColorUtility.TryParseHtmlString("#FFFFFF", out color))
|
||||
{
|
||||
newLabel.style.color = color;
|
||||
};
|
||||
|
||||
newLabel.style.paddingBottom = 6;
|
||||
newLabel.style.paddingTop = 6;
|
||||
newLabel.style.paddingLeft = 0;
|
||||
newLabel.style.paddingRight = 0;
|
||||
newLabel.style.marginTop = 4;
|
||||
newLabel.style.marginBottom = 0;
|
||||
newLabel.style.marginLeft = 4;
|
||||
newLabel.style.marginRight = 4;
|
||||
|
||||
newLabel.style.SetBorderWidth(0);
|
||||
newLabel.clicked += () =>
|
||||
{
|
||||
OnMarkTimeLineClicked(item);
|
||||
};
|
||||
;
|
||||
UnityEngine.Cursor.SetCursor(CursorSelect, Vector2.zero, CursorMode.Auto);
|
||||
|
||||
scrollView.Add(newLabel);
|
||||
}
|
||||
} else
|
||||
{
|
||||
Debug.Log("scrollView is NULL");
|
||||
}
|
||||
|
||||
newElement.style.width = new StyleLength(new Length(100, LengthUnit.Percent));
|
||||
|
||||
// регистрируем изменение курсора
|
||||
//newElement.RegisterCallback<MouseEnterEvent>(OnMouseEnterAddCustomCursor);
|
||||
//newElement.RegisterCallback<MouseLeaveEvent>(OnMouseLeaveAddCursor);
|
||||
tagHistoryController.UI.ScrollTable.Add(newElement);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnMouseEnterAddCustomCursor(MouseEnterEvent evt)
|
||||
{
|
||||
// Set the custom cursor when the mouse enters the element
|
||||
UnityEngine.Cursor.SetCursor(CursorSelect, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
|
||||
private void OnMouseLeaveAddCursor(MouseLeaveEvent evt)
|
||||
{
|
||||
// Reset the cursor when the mouse leaves the element
|
||||
UnityEngine.Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
|
||||
//public void SetCursor(VisualElement element, MouseCursor cursor)
|
||||
//{
|
||||
// object objCursor = new UnityEngine.UIElements.Cursor();
|
||||
// PropertyInfo fields = typeof(UnityEngine.UIElements.Cursor).GetProperty("defaultCursorId", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
// fields.SetValue(objCursor, (int)cursor);
|
||||
// element.style.cursor = new StyleCursor((UnityEngine.UIElements.Cursor)objCursor);
|
||||
//}
|
||||
|
||||
void OnMarkTimeLineClicked(MarkItem item)
|
||||
{
|
||||
progressBarController.Model.UpdateCurrentTimeSeconds(item.time_start);
|
||||
}
|
||||
|
||||
|
||||
public void AddMarkPointOnBar()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user