/* * 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.Generic; using UnityEngine; using UnityEngine.UI; namespace FancyScrollView.FocusOn { class Cell : FancyCell { [SerializeField] Animator animator = default; [SerializeField] Text message = default; [SerializeField] Image image = default; [SerializeField] Button button = default; [SerializeField] Image icon = default; [SerializeField] Text title = default; [SerializeField] GameObject line = default; static class AnimatorHash { public static readonly int Scroll = Animator.StringToHash("scroll"); } public override void Initialize() { button.onClick.AddListener(() => Context.OnCellClicked?.Invoke(Index,true)); } public void onCellClickedEvent() { Context.OnCellClicked?.Invoke(Index, false); } public override void UpdateContent(ItemData itemData) { message.text = itemData.TextId; icon.sprite = itemData.Sprite; //title.text = itemData.Name; if (itemData.LanguageType == 0) { title.gameObject.AddComponent().SetText(int.Parse(itemData.TextId)); } else { title.gameObject.AddComponent().SetTextKey(itemData.TextId); } var selected = Context.SelectedIndex == Index; line.SetActive(selected); title.gameObject.SetActive(selected); //image.color = selected // ? new Color32(0, 255, 255, 100) // : new Color32(255, 255, 255, 77); } public override void UpdatePosition(float position) { currentPosition = position; if (animator.isActiveAndEnabled) { animator.Play(AnimatorHash.Scroll, -1, position); } animator.speed = 0; } // GameObject が非アクティブになると Animator がリセットされてしまうため // 現在位置を保持しておいて OnEnable のタイミングで現在位置を再設定します float currentPosition = 0; void OnEnable() => UpdatePosition(currentPosition); } }