using Cysharp.Threading.Tasks; using SHI.modal; using System; using System.Globalization; using System.IO; using UnityEngine; using UnityEngine.UI; /// /// 샘플 장면 드라이버: 버튼 클릭으로 SHI BlockDetail 모달을 생성/표시하고, /// StreamingAssets에서 glb/간트 JSON을 읽어 모달에 전달합니다. /// public class ShiPopupSample : MonoBehaviour { [SerializeField] private GameObject blockDetailModalPrefab; [SerializeField] private Button openModalButton; private BlockDetailModal blockDetailModal; private void Start() { if (openModalButton != null) { openModalButton.onClick.AddListener(() => { if (blockDetailModal == null && blockDetailModalPrefab != null) { Canvas canvas = Canvas.FindFirstObjectByType(); Debug.Log($"Creating BlockDetailModal under Canvas:{canvas}"); blockDetailModal = Instantiate(blockDetailModalPrefab, canvas.transform).GetComponent(); } blockDetailModal.gameObject.SetActive(true); SetupData().Forget(); }); } } [Serializable] public class RawScheduleSegment { public string ItemId; public string Start; public string End; public float Progress; public string Type; } [Serializable] public class RawGanttChartData { public RawScheduleSegment[] Segments; } /// /// StreamingAssets에서 샘플 간트 JSON과 모델을 읽어 모달에 적용합니다. /// 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"); // 플랫폼에 따라 UnityWebRequest 사용이 필요할 수 있음(여기선 Editor/Standalone 가정) RawGanttChartData raw = null; try { if (File.Exists(jsonPath)) raw = JsonUtility.FromJson(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); } }