Files
SAMKWANG/Assets/Scripts/BranchSelection/UI/Panel_BranchSelection.cs
2025-11-13 18:11:49 +09:00

87 lines
2.8 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using WI;
namespace Samkwang
{
public class Panel_BranchSelection : MonoBehaviour
{
public CanvasGroup BranchSelection;
public ScrollRect ScrollView_Selected;
public UI_BranchLocationButton prf_branchLocationButton;
public List<UI_BranchLocationButton> branchLocationButtons = new List<UI_BranchLocationButton>();
public float fadeOutDuration = 0.8f;
public Action onClickExitButton;
private static bool hasPlayedOnce = false;
public void Init()
{
BranchSelection = transform.GetComponentInChildren<CanvasGroup>();
ScrollView_Selected = transform.GetComponentInChildren<ScrollRect>();
prf_branchLocationButton = Resources.Load<UI_BranchLocationButton>("Prefabs/UI/PRF_UI_BranchLocationButton");
BranchSelection.alpha = hasPlayedOnce ? 1f : 0f;
}
public void FadeInSelection()
{
hasPlayedOnce = true;
StopAllCoroutines();
StartCoroutine(FadeIn());
}
IEnumerator FadeIn()
{
float t = 0f;
float start = BranchSelection.alpha;
while (t < fadeOutDuration)
{
t += Time.deltaTime;
BranchSelection.alpha = Mathf.Lerp(start, 1f, t / fadeOutDuration);
yield return null;
}
BranchSelection.alpha = 1f;
}
public void CreateBranchLocationButton(List<UI_BranchLocation> branchLocations)
{
foreach(var branchLocation in branchLocations)
{
var branchName = ChangedBranchName(branchLocation.name);
var branchLocationButton = Instantiate(prf_branchLocationButton, ScrollView_Selected.content);
branchLocationButton.SetBranchLocationButton(branchName, branchLocation);
}
}
private string ChangedBranchName(string name)
{
var replacedName = name.Replace("Location_", "");
var changedName = "";
switch (replacedName)
{
case "Korea":
changedName = "한국 본사";
break;
case "Vietnam":
changedName = "베트남 사업부";
break;
case "India":
changedName = "인도 사업부";
break;
case "USA":
changedName = "미국 사업부";
break;
case "Mexico":
changedName = "멕시코 사업부";
break;
}
return changedName;
}
}
}