
#region 列表滑动方式
public void BeginDrag_ScrollRect(PointerEventData eventData)
{
beginSmooth = false;
pointBeginDragX = Input.mousePosition.x;
Vector2 mouseDown = eventData.position;
Vector2 mouseUguiPos = new Vector2();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ContentRectTrans.parent.GetComponent<RectTransform>(), mouseDown, eventData.enterEventCamera, out mouseUguiPos);
if (isRect)
{
offsetMouse = m_ContentRectTrans.anchoredPosition - mouseUguiPos;
isToNext = false;
}
}
public void OnDrag_ScrollRect(PointerEventData eventData)
{
float x = m_ContentRectTrans.anchoredPosition.x;
float y = m_ContentRectTrans.anchoredPosition.y;
int index = curIndex;
float distance = (m_CellObjectWidth + m_Spacing) / 2f ;
if (Input.mousePosition.x - pointBeginDragX > distance)
{
if (index > 0)
{
pointBeginDragX = Input.mousePosition.x;
isToNext = true;
JumpCenterIndex(index - 1);
}
}
else if ((Input.mousePosition.x - pointBeginDragX) < distance && (Input.mousePosition.x - pointBeginDragX) > 0)
{
SelectContentPos_InDrag(eventData, y);
}
else if ((Input.mousePosition.x - pointBeginDragX) > -distance && (Input.mousePosition.x - pointBeginDragX) < 0)
{
SelectContentPos_InDrag(eventData, y);
}
else if (Input.mousePosition.x - pointBeginDragX < -distance)
{
if (index < m_CellInfos.Length-1)
{
pointBeginDragX = Input.mousePosition.x;
isToNext = true;
JumpCenterIndex(index + 1);
}
}
}
public void SelectContentPos_InDrag(PointerEventData eventData, float y)
{
if (!isToNext)
{
Vector2 mouseDrag = eventData.position;
Vector2 uguiPos = new Vector2();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ContentRectTrans.parent.GetComponent<RectTransform>(), mouseDrag, eventData.enterEventCamera, out uguiPos);
if (isRect)
{
m_ContentRectTrans.anchoredPosition = new Vector2((offsetMouse + uguiPos).x, y);
if ((offsetMouse + uguiPos).x > rangs[0])
{
m_ContentRectTrans.anchoredPosition = new Vector2(rangs[0], y);
}
if ((offsetMouse + uguiPos).x < rangs.Last())
{
m_ContentRectTrans.anchoredPosition = new Vector2(rangs.Last(), y);
}
}
}
else
{
Vector2 mouseDown = eventData.position;
Vector2 mouseUguiPos = new Vector2();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(m_ContentRectTrans.parent.GetComponent<RectTransform>(), mouseDown, eventData.enterEventCamera, out mouseUguiPos);
if (isRect)
{
offsetMouse = m_ContentRectTrans.anchoredPosition - mouseUguiPos;
}
}
}
public void EndDrag_ScrollRect(PointerEventData eventData)
{
offsetMouse = Vector2.zero;
StartSmoothDamp();
}
public void SetRangsContent()
{
rangs = new List<float>();
for (int i = 0; i < m_CellInfos.Length; i++)
{
float dragContent = (m_PlaneWidth - m_CellObjectWidth) / 2f - (m_CellObjectWidth + m_Spacing) * i;
rangs.Add(dragContent);
}
}
public void StartSmoothDamp()
{
if (smooth != null)
{
CoroutingTool.Instance.StopCoroutine(smooth);
}
smooth = SmoothDamp();
beginSmooth = true;
CoroutingTool.Instance.StartCoroutine(SmoothDamp());
}
public IEnumerator SmoothDamp()
{
float mMoveSpeed = 0f;
float SMOOTH_TIME = 0.2f;
while (beginSmooth)
{
float x = m_ContentRectTrans.anchoredPosition.x;
float y = m_ContentRectTrans.anchoredPosition.y;
int index = curIndex;
if (Mathf.Abs((int)x - rangs[index]) < 2f)
{
x = rangs[index];
beginSmooth = false;
isToNext = false;
yield break;
}
m_ContentRectTrans.anchoredPosition =
new Vector2(Mathf.SmoothDamp(x, rangs[index], ref mMoveSpeed, SMOOTH_TIME), y);
yield return 0;
}
}
#endregion