| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /*
- * 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<ItemData, Context>
- {
- [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<TextAutoLanguage>().SetText(int.Parse(itemData.TextId));
- }
- else {
- title.gameObject.AddComponent<TextAutoLanguage2>().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);
- }
- }
|