using UnityEngine;
using UnityEngine.EventSystems; public class ObliqueScroll : MonoBehaviour,IDragHandler
{
public RectTransform viewport;
public ObliqueScrollContent content; private Transform target;
private float space_min;
private float space_max; private Vector3 position_c; private void OnValidate()
{
if (content != null)
{
target = content.transform;
space_min = ;
space_max = target.childCount * (content.v_cell.y + content.v_space) - viewport.rect.height;
if (space_max < )
{
space_max = ;
}
}
} public void OnDrag(PointerEventData eventData)
{
float move_c = eventData.delta.y;
position_c = target.localPosition;
position_c.y += move_c;
position_c = CheckOut(position_c);
target.localPosition = position_c;
} private Vector3 CheckOut(Vector3 position)
{
if (position.y <= space_min)
{
position.y = space_min;
}
if (position.y >= space_max)
{
position.y = space_max;
}
return position;
}
}
using UnityEngine;

public class ObliqueScrollContent : MonoBehaviour
{
public Vector2 v_cell;
public float v_space;
public float v_offset; private Vector2 half = new Vector2(0.5f, 0.5f); private void OnValidate()
{
Refresh();
} private void Refresh()
{
for (int i = ; i < transform.childCount; i++)
{
Transform cell = transform.GetChild(i);
float pos_x = -i * v_offset;
float pos_y = -i * (v_cell.y + v_space);
RefreshCell(cell, new Vector3(pos_x, pos_y, ));
}
} private void RefreshCell(Transform cell, Vector3 position)
{
RectTransform rt = (RectTransform)cell;
rt.anchorMin = half;
rt.anchorMax = half;
rt.pivot = half;
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, v_cell.x);
rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, v_cell.y);
rt.localPosition = position;
}
}

只是一个思路,拖动很生硬

Scroll(加ObliqueScroll, 倾斜X度)

  viewport(加mask)

    content(加ObliqueScrollContent, 倾斜-X度)

      item1

      item2

      item3

04-25 20:24