Unity/UniRx/EventTrigger
提供: 初心者エンジニアの簡易メモ
サンプル
オブジェクトに、触れたときとか、外れたときとかのイベントを取得できる。 ObservableEventTriggerを、オブジェクトに、事前にAddComponentしておいても良い。
using UniRx.Triggers; GameObject eventTextObj = GameObject.Find("EventText"); var eventTrigger = eventTextObj.AddComponent<ObservableEventTrigger>(); eventTrigger.OnPointerEnterAsObservable() .Subscribe(pointerEventData => Debug.Log("PointerEnter " + pointerEventData.position)); // 触れた時 PointerExit (666.0, 1013.0) eventTrigger.OnPointerExitAsObservable() .Subscribe(pointerEventData => Debug.Log("PointerExit " + pointerEventData.position)); // 外れた時 eventTrigger.OnDragAsObservable() .Subscribe(pointerEventData => Debug.Log("Drag " + pointerEventData.position)); eventTrigger.OnPointerDownAsObservable() .Subscribe(pointerEventData => Debug.Log("PointerDown " + pointerEventData.position)); // downした時 eventTrigger.OnPointerClickAsObservable() .Subscribe(pointerEventData => Debug.Log("PointerClick " + pointerEventData.position)); // upした時だが、PointerUpの後に実行 eventTrigger.OnPointerUpAsObservable() .Subscribe(pointerEventData => Debug.Log("PointerUp " + pointerEventData.position)); // upした時 eventTrigger.OnBeginDragAsObservable() .Subscribe(pointerEventData => Debug.Log("BeginDrag " + pointerEventData.position)); eventTrigger.OnEndDragAsObservable() .Subscribe(pointerEventData => Debug.Log("EndDrag " + pointerEventData.position)); eventTrigger.OnDropAsObservable() .Subscribe(pointerEventData => Debug.Log("Drop " + pointerEventData.position)); // EndDragとほぼ同じで、EndDragより早い。 eventTrigger.OnInitializePotentialDragAsObservable() .Subscribe(pointerEventData => Debug.Log("Initialize " + pointerEventData.position)); // downした時とほぼ同じで、少し後 eventTrigger.OnScrollAsObservable() .Subscribe(pointerEventData => Debug.Log("Scroll " + pointerEventData.position)); // オブジェクト上でscrollした時 // 以下は、反応しない eventTrigger.OnDeselectAsObservable() .Subscribe(baseEventData => Debug.Log("Deselect " + baseEventData.selectedObject)); eventTrigger.OnSelectAsObservable() .Subscribe(baseEventData => Debug.Log("Select " + baseEventData.selectedObject)); eventTrigger.OnSubmitAsObservable() .Subscribe(baseEventData => Debug.Log("Submit " + baseEventData.selectedObject)); eventTrigger.OnCancelAsObservable() .Subscribe(baseEventData => Debug.Log("Cancel " + baseEventData.selectedObject)); eventTrigger.OnUpdateSelectedAsObservable() .Subscribe(baseEventData => Debug.Log("UpdateSelected " + baseEventData.selectedObject)); eventTrigger.OnMoveAsObservable() .Subscribe(axisEventData => Debug.Log("Move " + axisEventData.moveVector));