164 lines
3.6 KiB
C#
164 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BitStrap;
|
|
using I2.Loc;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CreditsManager : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class CreditsJobGroup
|
|
{
|
|
public List<string> jobs = new List<string>();
|
|
|
|
public List<string> names = new List<string>();
|
|
}
|
|
|
|
[Serializable]
|
|
public class JobGroup
|
|
{
|
|
public List<string> jobNames = new List<string>();
|
|
|
|
public List<string> jobPeople = new List<string>();
|
|
}
|
|
|
|
public Text jobTextPrefab;
|
|
|
|
public Text nameTextPrefab;
|
|
|
|
public List<GameObject> creditsTabs = new List<GameObject>();
|
|
|
|
[ReadOnly]
|
|
public int currentTab;
|
|
|
|
public GameObject startPosition;
|
|
|
|
public int jobsDistance = 20;
|
|
|
|
public int jobNameDistance = 10;
|
|
|
|
public int namesDistance = 10;
|
|
|
|
private Vector3 currentPosition = Vector3.zero;
|
|
|
|
public List<CreditsJobGroup> jobGroups = new List<CreditsJobGroup>();
|
|
|
|
[Space(10f)]
|
|
public bool isScrollable;
|
|
|
|
public GameObject scrollParent;
|
|
|
|
public float scrollStartY;
|
|
|
|
public float scrollFinishY = 500f;
|
|
|
|
public float scrollSpeed = 10f;
|
|
|
|
public List<CreditsList> creditsLists = new List<CreditsList>();
|
|
|
|
private void Awake()
|
|
{
|
|
creditsLists = GetComponentsInChildren<CreditsList>().ToList();
|
|
foreach (CreditsList creditsList in creditsLists)
|
|
{
|
|
creditsList.creditsManager = this;
|
|
creditsList.Refresh();
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (creditsLists != null)
|
|
{
|
|
foreach (CreditsList creditsList in creditsLists)
|
|
{
|
|
creditsList.Refresh();
|
|
}
|
|
}
|
|
currentTab = 0;
|
|
RefreshTabs();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
}
|
|
|
|
public void RefreshTabs()
|
|
{
|
|
foreach (GameObject creditsTab in creditsTabs)
|
|
{
|
|
creditsTab.SetActive(false);
|
|
}
|
|
creditsTabs[currentTab].SetActive(true);
|
|
}
|
|
|
|
public void ChangeTab(bool next)
|
|
{
|
|
if (next)
|
|
{
|
|
currentTab++;
|
|
}
|
|
else
|
|
{
|
|
currentTab--;
|
|
}
|
|
RefreshTabs();
|
|
}
|
|
|
|
public void StartScroll()
|
|
{
|
|
if (isScrollable && (bool)scrollParent)
|
|
{
|
|
iTween.Stop(scrollParent);
|
|
scrollParent.transform.localPosition = new Vector3(scrollParent.transform.localPosition.x, scrollStartY, scrollParent.transform.localPosition.z);
|
|
iTween.MoveTo(scrollParent, iTween.Hash("y", scrollFinishY, "islocal", true, "speed", scrollSpeed, "easeType", iTween.EaseType.linear, "looptype", iTween.LoopType.loop, "oncomplete", "ScrollFinished"));
|
|
}
|
|
}
|
|
|
|
public void ScrollFinished()
|
|
{
|
|
}
|
|
|
|
public void RefreshCredits()
|
|
{
|
|
currentPosition = Vector3.zero;
|
|
for (int i = 0; i < jobGroups.Count; i++)
|
|
{
|
|
CreditsJobGroup creditsJobGroup = jobGroups[i];
|
|
for (int j = 0; j < creditsJobGroup.jobs.Count; j++)
|
|
{
|
|
Text text = UnityEngine.Object.Instantiate(jobTextPrefab);
|
|
text.transform.parent = startPosition.transform;
|
|
text.transform.localScale = Vector3.one;
|
|
text.transform.localPosition = currentPosition;
|
|
text.gameObject.SetActive(true);
|
|
text.GetComponent<Localize>().SetTerm(creditsJobGroup.jobs[j]);
|
|
currentPosition.y -= jobNameDistance;
|
|
}
|
|
for (int k = 0; k < creditsJobGroup.names.Count; k++)
|
|
{
|
|
Text text2 = UnityEngine.Object.Instantiate(nameTextPrefab);
|
|
text2.transform.parent = startPosition.transform;
|
|
text2.transform.localScale = Vector3.one;
|
|
text2.transform.localPosition = currentPosition;
|
|
text2.gameObject.SetActive(true);
|
|
if (LocalizationManager.GetTermTranslation(creditsJobGroup.names[k]) == string.Empty)
|
|
{
|
|
text2.text = creditsJobGroup.names[k];
|
|
}
|
|
else
|
|
{
|
|
text2.text = LocalizationManager.GetTermTranslation(creditsJobGroup.names[k]);
|
|
}
|
|
currentPosition.y -= namesDistance;
|
|
}
|
|
if (i < jobGroups.Count - 1)
|
|
{
|
|
currentPosition.y -= jobsDistance;
|
|
}
|
|
}
|
|
}
|
|
}
|