123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- /// <summary>
- ///
- /// </summary>
- public class UI_ScrollFlow_Item : MonoBehaviour
- {
- /// <summary>
- ///
- /// </summary>
- private UI_ScrollFlow parent;
- /// <summary>
- ///
- /// </summary>
- [HideInInspector]
- public RectTransform rect;
-
- /// <summary>
- ///
- /// </summary>
- public List<Image> imgList = new List<Image>();
- /// <summary>
- ///
- /// </summary>
- public List<Text> txtList = new List<Text>();
- /// <summary>
- ///
- /// </summary>
- public float v = 0;
- /// <summary>
- ///
- /// </summary>
- private Vector3 p, s;
- /// <summary>
- /// 缩放值
- /// </summary>
- public float sv;
- /// <summary>
- ///
- /// </summary>
- private Color color;
- /// <summary>
- ///
- /// </summary>
- public int _index;
-
- /// <summary>
- /// 元素列表优化对象
- /// </summary>
- public UI_ScrollFlow ScrollFlowParent
- {
- set
- {
- parent = value;
- }
- }
- /// <summary>
- /// 拖拽到指定位置
- /// 将子对象,指定到时间轴的某个点上.
- /// </summary>
- /// <param name="value"></param>
- 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);
- }
- }
-
- /////// <summary>
- /////// 更改 显示的绘制顺序
- /////// </summary>
- /////// <param name="v"></param>
- ////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;
- ////}
- /// <summary>
- /// 指的是刷新,
- /// 该子对象在时间轴上
- /// 对应的位置等信息
- /// </summary>
- public void Refresh()
- {
- if (rect == null)
- {
- rect = GetComponent<RectTransform>();
- }
- 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;
- }
- /// <summary>
- /// 数据索引
- /// </summary>
- public int Index
- {
- get
- {
- return _index;
- }
- set
- {
- _index = value;
- if (_index < 0)
- {
- ResetDrag();
- }
- if (parent.onInitializeItem != null && _index >= 0)
- {
- parent.onInitializeItem(gameObject, _index);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- private void ResetDrag()
- {
- v = 0;
- Refresh();
- this.gameObject.SetActive(false);
- }
- }
|