270 lines
9.3 KiB
C#
270 lines
9.3 KiB
C#
using ChunilENG;
|
|
using Cysharp.Threading.Tasks;
|
|
using HyundaiWIA;
|
|
using KEPCO;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace OCTOPUS_TWIN.UI
|
|
{
|
|
public class ProjectListController : MonoBehaviour
|
|
{
|
|
[Header("Settings")]
|
|
[SerializeField] private ProjectItemView itemPrefab; // 복제할 원본 버튼 프리팹
|
|
[SerializeField] private Transform contentParent; // 버튼들이 생성될 위치
|
|
[SerializeField] private List<ProjectData> projectDataList;
|
|
|
|
[Header("UI References")]
|
|
[SerializeField] private ToastPopup toastPopup; // 만들어둔 토스트 팝업 연결
|
|
|
|
[Header("References")]
|
|
[SerializeField] private GameObject homeRoot; // 홈 화면
|
|
|
|
[Tooltip("Chunil, KEPCO 등의 SceneMain들이 자식으로 있는 부모 오브젝트")]
|
|
[SerializeField] private Transform sceneMainRoot;
|
|
|
|
//[Tooltip("Chunil, KEPCO 등의 모델들이 자식으로 있는 부모 오브젝트")]
|
|
//[SerializeField] private Transform modelRoot;
|
|
|
|
[Tooltip("Chunil, KEPCO 등의 StaticCanvas들이 자식으로 있는 부모 오브젝트")]
|
|
[SerializeField] private Transform staticCanvasRoot;
|
|
|
|
[Tooltip("Chunil, KEPCO 등의 PopupCanvas들이 자식으로 있는 부모 오브젝트")]
|
|
[SerializeField] private Transform popupCanvasRoot;
|
|
|
|
[SerializeField] private Transform labelCanvasRoot;
|
|
|
|
[SerializeField] private Transform modalCanvasRoot;
|
|
|
|
public ProjectData currentProjectData;
|
|
[SerializeField]
|
|
private Volume volume;
|
|
private SceneController sceneController = new();
|
|
|
|
private void Start()
|
|
{
|
|
GenerateList();
|
|
|
|
if (sceneMainRoot != null)
|
|
{
|
|
foreach (Transform child in sceneMainRoot)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
//if (modelRoot != null)
|
|
//{
|
|
// foreach (Transform child in modelRoot)
|
|
// {
|
|
// child.gameObject.SetActive(false);
|
|
// }
|
|
//}
|
|
|
|
if (staticCanvasRoot != null)
|
|
{
|
|
foreach (Transform child in staticCanvasRoot)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if (popupCanvasRoot != null)
|
|
{
|
|
foreach (Transform child in popupCanvasRoot)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if (labelCanvasRoot != null)
|
|
{
|
|
foreach (Transform child in labelCanvasRoot)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
if (modalCanvasRoot != null)
|
|
{
|
|
foreach (Transform child in modalCanvasRoot)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
if (volume == null)
|
|
{
|
|
volume = FindAnyObjectByType<Volume>();
|
|
}
|
|
|
|
var allToastPopup = modalCanvasRoot.GetComponentsInChildren<ToastPopup>(true);
|
|
toastPopup = allToastPopup.FirstOrDefault(x => x.name == "UnOpenProjectToastPanel");
|
|
}
|
|
|
|
private void GenerateList()
|
|
{
|
|
// 기존에 혹시 테스트로 놔둔 버튼이 있다면 지우기
|
|
foreach (Transform child in contentParent)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
|
|
// 데이터 개수만큼 버튼 생성
|
|
foreach (var data in projectDataList)
|
|
{
|
|
// 프리팹 복제
|
|
ProjectItemView newItem = Instantiate(itemPrefab, contentParent);
|
|
|
|
// 데이터 주입 및 클릭 이벤트 연결
|
|
if (data.isLocked)
|
|
{
|
|
// 클릭 불가한 프로젝트 버튼
|
|
newItem.Setup(data, () =>
|
|
{
|
|
if (toastPopup != null) toastPopup.gameObject.SetActive(true);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
newItem.Setup(data, OnProjectClicked); // 클릭 가능한 프로젝트 버튼
|
|
}
|
|
}
|
|
}
|
|
|
|
// 버튼이 클릭되었을 때 실행될 함수
|
|
private async void OnProjectClicked(ProjectData selectedData)
|
|
{
|
|
//if (modelRoot == null)
|
|
//{
|
|
// Debug.LogError("Model Root가 연결되지 않았습니다");
|
|
// return;
|
|
//}
|
|
|
|
// 로딩 매니저 호출
|
|
if (UILoading.Instance != null)
|
|
{
|
|
await UILoading.Instance.LoadProject(() =>
|
|
{
|
|
// 홈 화면 끄기
|
|
if (homeRoot != null)
|
|
{
|
|
homeRoot.SetActive(false);
|
|
}
|
|
|
|
// 씬에 있는 오브젝트 프리팹 on/off
|
|
SwitchModel(selectedData);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// 로딩 시스템 없을 때 바로 전환
|
|
if (homeRoot != null) homeRoot.SetActive(false);
|
|
SwitchModel(selectedData);
|
|
}
|
|
}
|
|
|
|
private void CanvasReset()
|
|
{
|
|
if (currentProjectData != null)
|
|
{
|
|
//SetActiveProgjectDataObject(modelRoot, currentProjectData.modelPrefab.name, false);
|
|
SetActiveProgjectDataObject(staticCanvasRoot, currentProjectData.staticCanvasPrefab.name, false);
|
|
SetActiveProgjectDataObject(popupCanvasRoot, currentProjectData.popupCanvasPrefab.name, false);
|
|
SetActiveProgjectDataObject(sceneMainRoot, currentProjectData.sceneMain.name, false);
|
|
SetActiveProgjectDataObject(labelCanvasRoot, currentProjectData.labelCanvas.name, false);
|
|
}
|
|
}
|
|
|
|
// 실제 모델을 교체하는 함수
|
|
private async UniTask SwitchModel(ProjectData data)
|
|
{
|
|
// 기존에 켜져 있던 모델들 모두 끄기 (초기화)
|
|
CanvasReset();
|
|
|
|
await LoadActiveProjectScene(data.sceneNames[0], data.curSceneStatus);
|
|
volume.profile = data.volumeProfiles[0];
|
|
currentProjectData = data;
|
|
SetActiveProgjectDataObject(staticCanvasRoot, currentProjectData.staticCanvasPrefab.name, true);
|
|
SetActiveProgjectDataObject(sceneMainRoot, currentProjectData.sceneMain.name, true);
|
|
SetActiveProgjectDataObject(popupCanvasRoot, currentProjectData.popupCanvasPrefab.name, true);
|
|
SetActiveProgjectDataObject(labelCanvasRoot, currentProjectData.labelCanvas.name, true);
|
|
|
|
switch (data.curSceneStatus)
|
|
{
|
|
case SceneStatus.Chunil:
|
|
ChunilENGSceneMain.Instance.InitSceneMain();
|
|
break;
|
|
case SceneStatus.KepCo:
|
|
KEPCOSceneMain.Instance.InitSceneMain();
|
|
break;
|
|
case SceneStatus.HyundaiWia:
|
|
HyundaiWIASceneMain.Instance.InitSceneMain();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public string CursceneName;
|
|
|
|
public async UniTask SceneTransition(int index)
|
|
{
|
|
var sceneIndex = index == 2 ? 0 : 1;
|
|
if (currentProjectData.sceneNames.Count > sceneIndex)
|
|
{
|
|
var transitionScene = currentProjectData.sceneNames[sceneIndex];
|
|
await LoadActiveProjectScene(transitionScene, currentProjectData.curSceneStatus);
|
|
volume.profile = null;
|
|
volume.profile = currentProjectData.volumeProfiles[sceneIndex];
|
|
}
|
|
}
|
|
|
|
private async UniTask LoadActiveProjectScene(string mainScene, SceneStatus status)
|
|
{
|
|
await sceneController.SceneChange(mainScene, status);
|
|
CursceneName = mainScene;
|
|
}
|
|
|
|
private void SetActiveProgjectDataObject(Transform parent, string targetName, bool isOn)
|
|
{
|
|
Transform targetModel = FindInChildren(parent, targetName);
|
|
|
|
if (targetModel != null)
|
|
{
|
|
targetModel.gameObject.SetActive(isOn);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"'{parent.name}' 아래에서 '{targetName}' 오브젝트를 찾을 수 없습니다. 이름을 확인해주세요.");
|
|
}
|
|
}
|
|
private Transform FindInChildren(Transform parent, string name)
|
|
{
|
|
foreach (Transform child in parent.GetComponentsInChildren<Transform>(true))
|
|
{
|
|
if (child.name == name)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void ReturnHome()
|
|
{
|
|
CanvasReset();
|
|
sceneController.OnClickHome();
|
|
|
|
//// 모델 다 끄기
|
|
//if (modelRoot != null)
|
|
//{
|
|
// foreach (Transform child in modelRoot)
|
|
// {
|
|
// child.gameObject.SetActive(false);
|
|
// }
|
|
//}
|
|
|
|
// 홈 화면 켜기
|
|
if (homeRoot != null) homeRoot.SetActive(true);
|
|
}
|
|
}
|
|
}
|