코드 개선

This commit is contained in:
logonkhi
2025-08-12 20:02:42 +09:00
parent 6f019476b0
commit 29a08c22e5
7 changed files with 53 additions and 8 deletions

View File

@@ -42,7 +42,7 @@ namespace UVC.Factory
[Tooltip("카메라 최대 높이")]
[SerializeField]
private float maxCameraY = 50f;
private float maxCameraY = 80f;
[Tooltip("카메라의 최소 수직 회전 각도 (X축)")]
[SerializeField]

View File

@@ -1,5 +1,6 @@
#nullable enable
using EPOOutline;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
@@ -22,7 +23,7 @@ namespace UVC.Factory.Component
{
// 서버에서 받은 좌표(예: 밀리미터 단위)를 Unity 씬의 단위(미터)로 변환하기 위한 스케일 값입니다.
// 예를 들어, 서버 좌표 1000이 Unity에서 1미터가 되려면 0.001f로 설정합니다.
private float scaleFactor = 0.0005f; // Unity에서 사용하는 단위로 변환하기 위한 스케일 팩터
private float scaleFactor = 0.001f; // Unity에서 사용하는 단위로 변환하기 위한 스케일 팩터
// 데이터로부터 수신한 AGV의 목표 위치와 목표 회전값입니다.
// AGV는 현재 위치에서 이 목표 지점을 향해 부드럽게 움직입니다.
@@ -60,6 +61,9 @@ namespace UVC.Factory.Component
private Outlinable? outlinable;
private float agvFloorOffset = 200f; //agv의 층을 구별하기 위한 값
private float agvZOffset = -197.5f; //층을 옮긴 agv의 위치를 잡아주기 위한 값
/// <summary>
/// AGV 객체가 생성될 때 처음 한 번 호출되는 초기화 메서드입니다.
/// </summary>
@@ -151,6 +155,7 @@ namespace UVC.Factory.Component
/// <summary>
/// 데이터 객체로부터 위치(X, Y) 및 각도(DEGREE) 값을 읽어와 AGV의 목표 위치와 회전을 설정합니다.
/// 이전 데이터의 timestamp를 이용해 업데이트 간격을 계산하고, 속도와 회전 속도를 조절합니다.
/// </summary>
/// <param name="newData">위치와 각도 정보가 포함된 데이터 객체입니다.</param>
private void UpdatePositionAndRotation(DataObject newData)
@@ -173,6 +178,23 @@ namespace UVC.Factory.Component
}
else // 이후 업데이트의 경우
{
// 타임스탬프를 이용해 데이터 업데이트 간격을 계산합니다.
DateTime? newTimestamp = newData.GetDateTime("TIMESTAMP");
DateTime? currentTimestamp = data.GetDateTime("TIMESTAMP");
float updateInterval = 1.0f; // 기본 간격은 1초로 설정
if (newTimestamp.HasValue && currentTimestamp.HasValue)
{
// 두 타임스탬프의 차이를 초 단위로 계산합니다.
TimeSpan interval = newTimestamp.Value - currentTimestamp.Value;
updateInterval = (float)interval.TotalSeconds;
// 간격이 0 이하일 경우(오류 방지), 기본값 1초를 사용합니다.
if (updateInterval <= 0)
{
updateInterval = 1.0f;
}
}
bool changed = false;
@@ -193,6 +215,9 @@ namespace UVC.Factory.Component
float distanceToTarget = Vector3.Distance(transform.position, newTargetPosition);
if (distanceToTarget > 0)
{
// 이동 속도(moveSpeed)를 계산된 시간 간격을 기반으로 설정합니다.
moveSpeed = updateInterval * 0.9f; // 90%의 시간 동안 도달하도록 설정
// 거리가 설정된 임계값을 초과하면, 보간을 건너뛰고 즉시 위치을 설정합니다.
if (distanceToTarget > teleportDistanceThreshold)
{
@@ -220,6 +245,9 @@ namespace UVC.Factory.Component
// 현재 회전과 새로운 목표 회전 사이의 각도 차이를 계산합니다.
if (distanceToTargetRotation > 0)
{
// 회전 속도(rotationSpeed)를 계산된 시간 간격을 기반으로 설정합니다.
rotationSpeed = updateInterval * 0.5f; // 50%의 시간 동안 회전하도록 설정
// 각도 차이가 설정된 임계값을 초과하면, 보간을 건너뛰고 즉시 회전을 설정합니다.
if (distanceToTargetRotation > teleportRotationThreshold)
{

View File

@@ -1,6 +1,8 @@
#nullable enable
using UnityEngine;
using UVC.Data;
using UVC.Factory.Component;
using UVC.Factory.Modal;
using UVC.Factory.Playback.UI;
using UVC.UI.Commands;
using UVC.UI.Loading;

View File

@@ -48,7 +48,8 @@ namespace UVC.Factory.Playback
private string time;
private string fileName;
public Action OnExitPlayback;
public Action? OnStartPlayback;
public Action? OnExitPlayback;
private float timeScale = 1.0f;
/// <summary>
@@ -199,6 +200,7 @@ namespace UVC.Factory.Playback
timeScale = 1.0f; //기본 시간 스케일 설정
UIPlayback.Instance.Show();
await UIPlayback.Instance.SetData(data.date, data.time, data.sqlFileName);
OnStartPlayback?.Invoke();
}
/// <summary>
@@ -345,7 +347,7 @@ namespace UVC.Factory.Playback
if (OnComplete != null) OnComplete.Invoke(errorMessage);
}
},
(string? error) =>
(string error) =>
{
Debug.Log($"DownloadPlaybackData OnError:{error}");
if (OnComplete != null) OnComplete.Invoke(error);
@@ -353,6 +355,5 @@ namespace UVC.Factory.Playback
}
}
}
}