Version: 2017.1

ScrollRect.onValueChanged

切换到手册
public UI.ScrollRect.ScrollRectEvent onValueChanged ;

描述

在子项的位置更改时执行的回调。

onValueChanged 用于监视 ScrollRect 对象中的更改。 onValueChanged 调用将使用 UnityEvent.AddListener API 来监视 更改。发生更改时,将调用用户提供的脚本代码。 ScrollRect.onValueChanged 的 UnityEvent.AddListener API 要求一个 Vector2 参数。

Note: The editor allows the onValueChanged value to be set up manually. For example the value can be set to run only a runtime. The object and script function to call are also provided here.

The onValueChanged variable can be alternatively set-up at runtime. The script example below shows how this can be done. The script is attached to the ScrollRect object.

using UnityEngine;
using UnityEngine.UI;

public class ExampleScript : MonoBehaviour { static ScrollRect scrollRect;

void Start() { scrollRect = GetComponent<ScrollRect>(); scrollRect.onValueChanged.AddListener(ListenerMethod); }

public void ListenerMethod(Vector2 value) { Debug.Log("ListenerMethod: " + value); } }