/* * FancyScrollView (https://github.com/setchi/FancyScrollView) * Copyright (c) 2020 setchi * Licensed under MIT (https://github.com/setchi/FancyScrollView/blob/master/LICENSE) */ using System; using System.Collections; using System.Collections.Generic; using DG.Tweening; using UnityEngine; using UnityEngine.UI; using Bansonic; class UI_Panel_Character : MonoBehaviour { [SerializeField] float anim_Time = 0.5f; [SerializeField, Range(0f, 1f)] float illustrationFadeStartAlpha = 0.25f; [SerializeField] float illustrationBgTargetXOffset = 0f; [SerializeField] float illustrationBgTargetYOffset = 0f; float Anim_Speed => 1f / anim_Time; [SerializeField] List ui_Anim; [SerializeField] Transform content_Character_Slot; [SerializeField] GameObject button_Character_Slot_Prefab; [SerializeField] Text text_Character_Name; [SerializeField] Text text_char_name; [SerializeField] Image Image_Character_Illustration; [SerializeField] Image Image_Character_Illustration_BG; //[Header("")] [Header("buttons")] public Button change_thisHero_skin; public Button thisHero_detail; public Button confirm_thisHero; [Header("quit")] [SerializeField] Button quitButton; [Header("Data Paths")] [Tooltip("Path relative to Resources folder for Editor mode")] public string editorResourcePath = "so/ally"; [Tooltip("Path relative to Resources folder for Runtime mode")] public string runtimeResourcePath = "so/ally"; private readonly List allyHeroList = new List(); private readonly List heroDisplayPrefabs = new List(); private Vector2 originalIllustrationPos; private Vector2 originalIllustrationBGPos; private bool hasCachedPositions; private Coroutine c_Character_Illustration_Anim; private int previewCharacterIndex = -1; private CanvasGroup illustrationCanvasGroup; private const string SAVED_HERO_ID_KEY = "SelectedMainHeroID"; private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { ClosePanel(); } } void Start() { UnityEngine.Debug.Log($"[UI_Panel_Character] Start called. Illustration: {Image_Character_Illustration}"); if (change_thisHero_skin != null) change_thisHero_skin.onClick.AddListener(() => gNotice.warning.display("\u6b64\u7248\u672c\u672a\u5f00\u653e\u76ae\u80a4\u5207\u6362\u529f\u80fd")); if (thisHero_detail != null) thisHero_detail.onClick.AddListener(() => gNotice.warning.display("\u6b64\u7248\u672c\u672a\u5f00\u653e\u8be6\u60c5\u67e5\u770b\u529f\u80fd")); if (confirm_thisHero != null) confirm_thisHero.onClick.AddListener(OnConfirmHeroClicked); if (quitButton != null) quitButton.onClick.AddListener(ClosePanel); if (Image_Character_Illustration != null) { Image_Character_Illustration.rectTransform.anchoredPosition = new Vector2(376, -306); originalIllustrationPos = Image_Character_Illustration.rectTransform.anchoredPosition; if (Image_Character_Illustration.transform.parent != null && Image_Character_Illustration.transform.parent.TryGetComponent(out CanvasGroup canvasGroup)) { illustrationCanvasGroup = canvasGroup; illustrationCanvasGroup.alpha = 0; } } if (Image_Character_Illustration_BG != null) { Vector2 pos = Image_Character_Illustration_BG.rectTransform.anchoredPosition; pos.x = 376; Image_Character_Illustration_BG.rectTransform.anchoredPosition = pos; originalIllustrationBGPos = Image_Character_Illustration_BG.rectTransform.anchoredPosition; } hasCachedPositions = true; foreach (var item in ui_Anim) { if (item != null) item.speed = Anim_Speed; } if (content_Character_Slot != null) content_Character_Slot.Get_Childrens_Component(true, true); var loadedData = RuntimeResourcesCache.LoadAllAllyHeroes(); allyHeroList.Clear(); allyHeroList.AddRange(loadedData); heroDisplayPrefabs.Clear(); UnityEngine.Debug.Log($"[UI_Panel_Character] Loaded {allyHeroList.Count} heroes"); allyHeroList.Sort((a, b) => a.ally_heroID.CompareTo(b.ally_heroID)); int savedHeroID = PlayerPrefs.GetInt(SAVED_HERO_ID_KEY, -1); int initialIndex = 0; for (int i = 0; i < allyHeroList.Count; i++) { var slotObject = Instantiate(button_Character_Slot_Prefab, content_Character_Slot); UI_OrderedEntryAnimator.PlayFadeOnly(slotObject, i, 0.16f, 0.012f, true); var displayPrefab = slotObject.GetComponent(); var slotButton = displayPrefab != null ? displayPrefab.characterProfileButton : slotObject.GetComponent