using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
///
///
public class UI_ScrollFlow_Item : MonoBehaviour
{
///
///
///
private UI_ScrollFlow parent;
///
///
///
[HideInInspector]
public RectTransform rect;
///
///
///
public List imgList = new List();
///
///
///
public List txtList = new List();
///
///
///
public float v = 0;
///
///
///
private Vector3 p, s;
///
/// 缩放值
///
public float sv;
///
///
///
private Color color;
///
///
///
public int _index;
///
/// 元素列表优化对象
///
public UI_ScrollFlow ScrollFlowParent
{
set
{
parent = value;
}
}
///
/// 拖拽到指定位置
/// 将子对象,指定到时间轴的某个点上.
///
///
public void Drag(float value)
{
//// Debug.LogError("Item drag::" + value + " curV:::" + v);
v += value;
Refresh();
if (Index == 0 && v > parent.startValue)
{
parent.OnReceiveUpdateState(true, this);
return;
}
if (Index == parent.mDataCount - 1 && v < parent.startValue)
{
parent.OnReceiveUpdateState(true, this);
return;
}
float abs = Mathf.Abs(0.5f - v);
if (abs < 0.05f)
{
parent.OnReceiveUpdateState(true, this);
}
else
{
parent.OnReceiveUpdateState(false, this);
}
}
///////
/////// 更改 显示的绘制顺序
///////
///////
////public int ResetSiblingIndex()
////{
//// int tempIndex = -1;
//// if (Index == parent.CurSelectElementIndex)
//// {
//// tempIndex = parent.mDataCount - 1;
//// }
//// else
//// {
//// if (Index < parent.CurSelectElementIndex)
//// {
//// tempIndex = Index;
//// }
//// else if (Index > parent.CurSelectElementIndex)
//// {
//// tempIndex = parent.mDataCount - (Index + 1) - parent.CurSelectElementIndex;
//// }
//// else
//// {
//// }
//// }
//// //// Debug.LogError("获得卡牌绘制的顺序!! 卡牌::" + Index + " 绘制顺序::" + tempIndex);
//// return tempIndex;
////}
///
/// 指的是刷新,
/// 该子对象在时间轴上
/// 对应的位置等信息
///
public void Refresh()
{
if (rect == null)
{
rect = GetComponent();
}
p = rect.localPosition;
p.x = parent.GetPositionX(v, _index);
rect.localPosition = p;
for (int i = 0; i < imgList.Count; i++)
{
imgList[i].color = new Color(imgList[i].color.r, imgList[i].color.g, imgList[i].color.b, color.a); ;
}
for (int i = 0; i < txtList.Count; i++)
{
txtList[i].color = new Color(txtList[i].color.r, txtList[i].color.g, txtList[i].color.b, color.a);
}
sv = parent.GetScale(v);
s.x = 1;
s.y = sv;
s.z = 1;
rect.localScale = s;
}
///
/// 数据索引
///
public int Index
{
get
{
return _index;
}
set
{
_index = value;
if (_index < 0)
{
ResetDrag();
}
if (parent.onInitializeItem != null && _index >= 0)
{
parent.onInitializeItem(gameObject, _index);
}
}
}
///
///
///
private void ResetDrag()
{
v = 0;
Refresh();
this.gameObject.SetActive(false);
}
}