EasyTouch On_Drag监听设置

监听On_Drag需要注意一下三点:

  1. Enable auto-select,[勾选].
    3d物体时能被触摸识别

  2. pickable layers 3D ,[设置需要的层级].
    能够被触摸识别的3d物体层级

  3. 相机Camera,[一定要设置],界面或代码设置皆可.

     EasyTouch.AddCamera(_camera);
     EasyTouch.RemoveCamera(_camera);
    
EasyTouch On_Drag监听设置_第1张图片
EasyTouch Drag设置.png

On_Drag监听:

 EasyTouch.On_Drag += FurnitureTrigger.Instance.OnDrag;
 EasyTouch.On_Drag -= FurnitureTrigger.Instance.OnDrag;

 public void OnDrag(Gesture gesture)
 { 
    if (gesture.touchCount > 1 || gesture.pickedObject == null)
    {
        return;
    }
 }

注意事项解析:

private void CreateGesture(int touchIndex,EvtType message,Finger finger, SwipeDirection swipe, float swipeLength, Vector2 swipeVector)
{
    ...
    // Auto update picked object
    if (autoUpdatePickedObject && autoSelect){
        if (message != EvtType.On_Drag && message != EvtType.On_DragEnd && message != EvtType.On_DragStart){
            if (GetPickedGameObject(finger)){
                gesture.pickedObject = pickedObject.pickedObj;
                gesture.pickedCamera = pickedObject.pickedCamera;
                gesture.isGuiCamera = pickedObject.isGUI;
            }
            else{
                gesture.pickedObject = null;
                gesture.pickedCamera = null;
                gesture.isGuiCamera = false;
            }
        }
    }
    ...
}

为什么要设置相机Camera和pickable layers?

  1. 在GetPickedGameObject中判断touchCameras.Count数量以及是否有有效的touchCamerastouchCameras[i].camera!=null && touchCameras[i].camera.enabled

  2. 在GetGameObjectAt中Physics.Raycast( ray, out hit,float.MaxValue,mask )射线检测mask层 (pickable layers,LayerMask mask = pickableLayers3D;),获取并设置pickedObjpickedObject.pickedObj = hit.collider.gameObject

  3. 在OneFinger中,若pickedObject 存在,则说明是Drag(If an object is selected we drag);否则是Swipe。
    if (fingers[fingerIndex].pickedObject){ fingers[fingerIndex].gesture = GestureType.Drag;}

private bool GetPickedGameObject(Finger finger, bool isTowFinger=false){

    ...
    
    if (touchCameras.Count>0){
        for (int i=0;i0){
            pickedObject.pickedCamera = cam;
            pickedObject.isGUI = isGuiCam;
            pickedObject.pickedObj = hit2D[0].collider.gameObject;
            return true;
        }
    }
    
    LayerMask mask = pickableLayers3D;
    
    if( Physics.Raycast( ray, out hit,float.MaxValue,mask ) ){
        pickedObject.pickedCamera = cam;
        pickedObject.isGUI =isGuiCam;
        pickedObject.pickedObj = hit.collider.gameObject;
        return true;
    }

    return false;
}

private void OneFinger(int fingerIndex){
    ...
    // If an object is selected we drag
    if (fingers[fingerIndex].pickedObject){
      fingers[fingerIndex].gesture = GestureType.Drag;
    }
    ...
}

你可能感兴趣的:(EasyTouch On_Drag监听设置)