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 jobs = new List(); public List names = new List(); } [Serializable] public class JobGroup { public List jobNames = new List(); public List jobPeople = new List(); } public Text jobTextPrefab; public Text nameTextPrefab; public List creditsTabs = new List(); [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 jobGroups = new List(); [Space(10f)] public bool isScrollable; public GameObject scrollParent; public float scrollStartY; public float scrollFinishY = 500f; public float scrollSpeed = 10f; public List creditsLists = new List(); private void Awake() { creditsLists = GetComponentsInChildren().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().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; } } } }