namespace UnityEngine.UI.Extensions.Examples { public class Example02ScrollViewCell : FancyScrollViewCell { [SerializeField] Animator animator = null; [SerializeField] Text message = null; [SerializeField] Image image = null; [SerializeField] Button button = null; readonly int scrollTriggerHash = Animator.StringToHash("scroll"); Example02ScrollViewContext context; void Start() { var rectTransform = transform as RectTransform; rectTransform.anchorMax = Vector2.one; rectTransform.anchorMin = Vector2.zero; rectTransform.anchoredPosition3D = Vector3.zero; UpdatePosition(0); button.onClick.AddListener(OnPressedCell); } /// /// コンテキストを設定します /// /// public override void SetContext(Example02ScrollViewContext context) { this.context = context; } /// /// セルの内容を更新します /// /// public override void UpdateContent(Example02CellDto itemData) { message.text = itemData.Message; if (context != null) { var isSelected = context.SelectedIndex == DataIndex; image.color = isSelected ? new Color32(0, 255, 255, 100) : new Color32(255, 255, 255, 77); } } /// /// セルの位置を更新します /// /// public override void UpdatePosition(float position) { animator.Play(scrollTriggerHash, -1, position); animator.speed = 0; } public void OnPressedCell() { if (context != null) { context.OnPressedCell(this); } } } }