2017-08-02 17:21:45 +08:00
|
|
|
|
namespace UnityEngine.UI.Extensions.Examples
|
|
|
|
|
{
|
|
|
|
|
public class Example03ScrollViewCell
|
|
|
|
|
: FancyScrollViewCell<Example03CellDto, Example03ScrollViewContext>
|
|
|
|
|
{
|
|
|
|
|
[SerializeField]
|
2018-01-20 20:08:44 +08:00
|
|
|
|
Animator animator = null;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
[SerializeField]
|
2018-01-20 20:08:44 +08:00
|
|
|
|
Text message = null;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
[SerializeField]
|
2018-01-20 20:08:44 +08:00
|
|
|
|
Image image = null;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
[SerializeField]
|
2018-01-20 20:08:44 +08:00
|
|
|
|
Button button = null;
|
2017-08-02 17:21:45 +08:00
|
|
|
|
|
|
|
|
|
readonly int scrollTriggerHash = Animator.StringToHash("scroll");
|
|
|
|
|
Example03ScrollViewContext 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// コンテキストを設定します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
public override void SetContext(Example03ScrollViewContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// セルの内容を更新します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemData"></param>
|
|
|
|
|
public override void UpdateContent(Example03CellDto 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// セルの位置を更新します
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="position"></param>
|
|
|
|
|
public override void UpdatePosition(float position)
|
|
|
|
|
{
|
|
|
|
|
animator.Play(scrollTriggerHash, -1, position);
|
|
|
|
|
animator.speed = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnPressedCell()
|
|
|
|
|
{
|
|
|
|
|
if (context != null)
|
|
|
|
|
{
|
|
|
|
|
context.OnPressedCell(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|