2025-11-14 19:54:04 +09:00
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using SHI.modal;
|
2025-11-13 20:16:25 +09:00
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.IO;
|
2025-11-12 12:28:17 +09:00
|
|
|
using UnityEngine;
|
2025-11-13 20:16:25 +09:00
|
|
|
using UnityEngine.UI;
|
2025-11-12 12:28:17 +09:00
|
|
|
|
2025-11-14 19:54:04 +09:00
|
|
|
/// <summary>
|
|
|
|
|
/// 샘플 장면 드라이버: 버튼 클릭으로 SHI BlockDetail 모달을 생성/표시하고,
|
|
|
|
|
/// StreamingAssets에서 glb/간트 JSON을 읽어 모달에 전달합니다.
|
|
|
|
|
/// </summary>
|
2025-11-12 12:28:17 +09:00
|
|
|
public class ShiPopupSample : MonoBehaviour
|
|
|
|
|
{
|
2025-11-13 20:16:25 +09:00
|
|
|
[SerializeField]
|
|
|
|
|
private GameObject blockDetailModalPrefab;
|
|
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Button openModalButton;
|
|
|
|
|
|
|
|
|
|
private BlockDetailModal blockDetailModal;
|
|
|
|
|
|
2025-11-14 19:54:04 +09:00
|
|
|
private void Start()
|
2025-11-12 12:28:17 +09:00
|
|
|
{
|
2025-11-13 20:16:25 +09:00
|
|
|
if (openModalButton != null)
|
|
|
|
|
{
|
|
|
|
|
openModalButton.onClick.AddListener(() =>
|
2025-11-14 19:54:04 +09:00
|
|
|
{
|
2025-11-13 20:16:25 +09:00
|
|
|
if (blockDetailModal == null && blockDetailModalPrefab != null)
|
|
|
|
|
{
|
|
|
|
|
Canvas canvas = Canvas.FindFirstObjectByType<Canvas>();
|
|
|
|
|
Debug.Log($"Creating BlockDetailModal under Canvas:{canvas}");
|
|
|
|
|
blockDetailModal = Instantiate(blockDetailModalPrefab, canvas.transform).GetComponent<BlockDetailModal>();
|
|
|
|
|
}
|
|
|
|
|
blockDetailModal.gameObject.SetActive(true);
|
|
|
|
|
SetupData().Forget();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
2025-11-14 19:54:04 +09:00
|
|
|
public class RawScheduleSegment
|
2025-11-13 20:16:25 +09:00
|
|
|
{
|
|
|
|
|
public string ItemId;
|
|
|
|
|
public string Start;
|
|
|
|
|
public string End;
|
|
|
|
|
public float Progress;
|
|
|
|
|
public string Type;
|
2025-11-12 12:28:17 +09:00
|
|
|
}
|
|
|
|
|
|
2025-11-13 20:16:25 +09:00
|
|
|
[Serializable]
|
2025-11-14 19:54:04 +09:00
|
|
|
public class RawGanttChartData
|
2025-11-13 20:16:25 +09:00
|
|
|
{
|
|
|
|
|
public RawScheduleSegment[] Segments;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 19:54:04 +09:00
|
|
|
/// <summary>
|
|
|
|
|
/// StreamingAssets에서 샘플 간트 JSON과 모델을 읽어 모달에 적용합니다.
|
|
|
|
|
/// </summary>
|
2025-11-13 20:16:25 +09:00
|
|
|
private async UniTaskVoid SetupData()
|
|
|
|
|
{
|
|
|
|
|
if (blockDetailModal == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning("BlockDetailModal is not assigned.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string sa = Application.streamingAssetsPath;
|
|
|
|
|
string glbPath = Path.Combine(sa, "block.glb");
|
|
|
|
|
string jsonPath = Path.Combine(sa, "sample_gantt_data.json");
|
|
|
|
|
|
2025-11-14 19:54:04 +09:00
|
|
|
// 플랫폼에 따라 UnityWebRequest 사용이 필요할 수 있음(여기선 Editor/Standalone 가정)
|
2025-11-13 20:16:25 +09:00
|
|
|
RawGanttChartData raw = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(jsonPath))
|
|
|
|
|
raw = JsonUtility.FromJson<RawGanttChartData>(File.ReadAllText(jsonPath));
|
|
|
|
|
else
|
|
|
|
|
Debug.LogWarning($"Sample JSON not found: {jsonPath}");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"Failed reading JSON: {ex}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var gantt = new GanttChartData();
|
|
|
|
|
if (raw?.Segments != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var s in raw.Segments)
|
|
|
|
|
{
|
|
|
|
|
DateTime start, end;
|
|
|
|
|
if (!DateTime.TryParse(s.Start, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out start))
|
|
|
|
|
start = DateTime.UtcNow;
|
|
|
|
|
if (!DateTime.TryParse(s.End, null, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out end))
|
|
|
|
|
end = start.AddDays(1);
|
|
|
|
|
gantt.Segments.Add(new ScheduleSegment
|
|
|
|
|
{
|
|
|
|
|
ItemKey = s.ItemId,
|
|
|
|
|
Start = start,
|
|
|
|
|
End = end,
|
|
|
|
|
Progress = s.Progress,
|
|
|
|
|
Type = s.Type ?? string.Empty
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Debug.Log($"Loaded blockDetailModal:{blockDetailModal} {gantt.Segments.Count} gantt segments.");
|
|
|
|
|
await blockDetailModal.LoadData(glbPath, gantt);
|
|
|
|
|
}
|
2025-11-12 12:28:17 +09:00
|
|
|
}
|