移动ScrollRect组件
using UnityEngine;
using UnityEngine.UI;
public class Script_05_05 :ScrollRect
{
protected float mRadius=0f;
protected override void Start()
{
base.Start();
//计算摇杆块的半径
mRadius = (transform as RectTransform).sizeDelta.x * 0.5f; //各锚点之间的距离,相当于宽度
Debug.Log(mRadius);
}
public override void OnDrag (UnityEngine.EventSystems.PointerEventData eventData)
{
base.OnDrag (eventData);
var contentPostion = this.content.anchoredPosition; //content距锚点(中心)的距离
if (contentPostion.magnitude > mRadius){
contentPostion = contentPostion.normalized * mRadius ;
SetContentAnchoredPosition(contentPostion);
}
}
}