void Initalize()//初始化 { List <GestureRecognizer> recogniers = new List <GestureRecognizer>(GetComponents <GestureRecognizer>()); DragRecognizer drag = recogniers.Find(r => r.EventMessageName == "OnDrag") as DragRecognizer; DragRecognizer twoFingerDrag = recogniers.Find(r => r.EventMessageName == "OnTwoFingerDrag") as DragRecognizer; PinchRecognizer pinch = recogniers.Find(r => r.EventMessageName == "OnPinch") as PinchRecognizer; //以下是监听器脚本的属性设置 //if (!drag) //{ // drag = gameObject.AddComponent<DragRecognizer>(); // drag.RequiredFingerCount = 1;//手指数量 // drag.IsExclusive = true;//是否根据手指数量触发事件 // drag.MaxSimultaneousGestures = 1;//最多同时触发的事件 // drag.SendMessageToSelection = GestureRecognizer.SelectionType.None; //} //if (!pinch) // pinch = gameObject.AddComponent<PinchRecognizer>(); //if (!twoFingerDrag) //{ // twoFingerDrag = gameObject.AddComponent<DragRecognizer>(); // twoFingerDrag.RequiredFingerCount = 2; // twoFingerDrag.IsExclusive = true; // twoFingerDrag.MaxSimultaneousGestures = 1; // twoFingerDrag.ApplySameDirectionConstraint = true; // twoFingerDrag.EventMessageName = "OnTwoFingerDrag"; //} }
void InstallGestureRecognizers() { List <GestureRecognizer> recogniers = new List <GestureRecognizer>(GetComponents <GestureRecognizer>()); DragRecognizer drag = recogniers.Find(r => r.EventMessageName == "OnDrag") as DragRecognizer; DragRecognizer twoFingerDrag = recogniers.Find(r => r.EventMessageName == "OnTwoFingerDrag") as DragRecognizer; PinchRecognizer pinch = recogniers.Find(r => r.EventMessageName == "OnPinch") as PinchRecognizer; if (!drag) { drag = gameObject.AddComponent <DragRecognizer>(); drag.RequiredFingerCount = 1; drag.IsExclusive = true; drag.MaxSimultaneousGestures = 1; drag.SendMessageToSelection = GestureRecognizer.SelectionType.None; } if (!pinch) { pinch = gameObject.AddComponent <PinchRecognizer>(); } if (!twoFingerDrag) { twoFingerDrag = gameObject.AddComponent <DragRecognizer>(); twoFingerDrag.RequiredFingerCount = 2; twoFingerDrag.IsExclusive = true; twoFingerDrag.MaxSimultaneousGestures = 1; twoFingerDrag.ApplySameDirectionConstraint = false; twoFingerDrag.EventMessageName = "OnTwoFingerDrag"; } }
void Awake() { //下面使用delegate 的方法触发回调比 SendMessage 效率更高。把下面注释掉就是使用SendMessage触发。 //使用delegate方法,回调方法名不能写成跟SendMessage目标方法名一样,否则点一下回调会触发两次 gameObject.AddComponent <ScreenRaycaster>(); fingerDownDetector = gameObject.AddComponent <FingerDownDetector>(); fingerDownDetector.enabled = false; fingerDownDetector.OnFingerDown += FingerDownEventHandler; fingerHoverDetector = gameObject.AddComponent <FingerHoverDetector>(); fingerHoverDetector.enabled = false; fingerHoverDetector.OnFingerHover += FingerHoverEventHandler; fingerMotionDetector = gameObject.AddComponent <FingerMotionDetector>(); fingerMotionDetector.enabled = false; fingerMotionDetector.OnFingerMove += FingerMoveEventHandler; fingerMotionDetector.OnFingerStationary += FingerStationaryEventHandler; fingerUpDetector = gameObject.AddComponent <FingerUpDetector>(); fingerUpDetector.enabled = false; fingerUpDetector.OnFingerUp += FingerUpEventHandler; dragRecognizer = gameObject.AddComponent <DragRecognizer>(); dragRecognizer.enabled = false; //只有在固定finger数的情况下才会触发。 dragRecognizer.IsExclusive = true; dragRecognizer.MoveTolerance = 0; dragRecognizer.OnGesture += FirstFingerDragEventHandler; longPressRecognizer = gameObject.AddComponent <LongPressRecognizer>(); longPressRecognizer.enabled = false; longPressRecognizer.OnGesture += LongPressEventHandler; tapRecognizer = gameObject.AddComponent <TapRecognizer>(); tapRecognizer.enabled = false; tapRecognizer.IsExclusive = true; tapRecognizer.OnGesture += TapEventHandler; doubleTapRecognizer = gameObject.AddComponent <TapRecognizer>(); doubleTapRecognizer.enabled = false; doubleTapRecognizer.RequiredTaps = 2; doubleTapRecognizer.OnGesture += DoubleTapEventHandler; swipeRecognizer = gameObject.AddComponent <SwipeRecognizer>(); swipeRecognizer.enabled = false; swipeRecognizer.OnGesture += SwipeEventHandler; pinchRecognizer = gameObject.AddComponent <PinchRecognizer>(); pinchRecognizer.enabled = false; pinchRecognizer.MinDistance = 0; pinchRecognizer.MinDOT = 0; pinchRecognizer.OnGesture += PinchEventHandler; twistRecognizer = gameObject.AddComponent <TwistRecognizer>(); twistRecognizer.enabled = false; twistRecognizer.OnGesture += TwistEventHandler; }
public override void SetRoot(Transform parent) { base.SetRoot(parent); m_DragRecognizer = GetComponent <DragRecognizer>(); m_PinchRecognizer = GetComponent <PinchRecognizer>(); m_FingerDownDetector = GetComponent <FingerDownDetector>(); m_FingerUpDetector = GetComponent <FingerUpDetector>(); m_DragRecognizer.OnGesture += OnDrag; m_PinchRecognizer.OnGesture += OnPinch; m_FingerDownDetector.OnFingerDown += OnFingerDown; m_FingerUpDetector.OnFingerUp += OnFingerUp; }
void Start() { if (!MessageTarget) { MessageTarget = this.gameObject; } screenRaycaster = GetComponent <ScreenRaycaster>(); if (!screenRaycaster) { screenRaycaster = gameObject.AddComponent <ScreenRaycaster>(); } // Create the FG instance if not already available if (!FingerGestures.Instance) { gameObject.AddComponent <FingerGestures>(); } GameObject fingerEventsNode = CreateChildNode("Finger Event Detectors"); { FingerDown = AddFingerEventDetector <FingerDownDetector>(fingerEventsNode); FingerUp = AddFingerEventDetector <FingerUpDetector>(fingerEventsNode); FingerMotion = AddFingerEventDetector <FingerMotionDetector>(fingerEventsNode); FingerHover = AddFingerEventDetector <FingerHoverDetector>(fingerEventsNode); } GameObject singleFingerGestureNode = CreateChildNode("Single Finger Gestures"); { Drag = AddSingleFingerGesture <DragRecognizer>(singleFingerGestureNode); Tap = AddSingleFingerGesture <TapRecognizer>(singleFingerGestureNode); Swipe = AddSingleFingerGesture <SwipeRecognizer>(singleFingerGestureNode); LongPress = AddSingleFingerGesture <LongPressRecognizer>(singleFingerGestureNode); DoubleTap = AddSingleFingerGesture <TapRecognizer>(singleFingerGestureNode); DoubleTap.RequiredTaps = 2; DoubleTap.EventMessageName = "OnDoubleTap"; } GameObject twoFingerGestures = CreateChildNode("Two-Finger Gestures"); { Pinch = AddTwoFingerGesture <PinchRecognizer>(twoFingerGestures); Twist = AddTwoFingerGesture <TwistRecognizer>(twoFingerGestures); TwoFingerDrag = AddTwoFingerGesture <DragRecognizer>(twoFingerGestures, "OnTwoFingerDrag"); TwoFingerTap = AddTwoFingerGesture <TapRecognizer>(twoFingerGestures, "OnTwoFingerTap"); TwoFingerSwipe = AddTwoFingerGesture <SwipeRecognizer>(twoFingerGestures, "OnTwoFingerSwipe"); TwoFingerLongPress = AddTwoFingerGesture <LongPressRecognizer>(twoFingerGestures, "OnTwoFingerLongPress"); } // we're done, remove component (but not game object) // Destroy( this ); }
private void SwitchSceneComplete(SceneInfo pInfo) { GameObject pGameObject = ResourceManager.GetInstance().LoadFromResource("GameSystem/FingerGestures", null, true) as GameObject; _fingerGestures = pGameObject.GetComponent <FingerGestures>(); GameObject.DontDestroyOnLoad(pGameObject); GameSceneManager.GetInstance().SwitchSceneCompleteEvent -= SwitchSceneComplete; _fingerGestures.gameObject.GetComponent <ScreenRaycaster>().Cameras = new Camera[] { Camera.main }; _swipeRecognizer = _fingerGestures.gameObject.GetComponent <SwipeRecognizer>(); _pinchRecognizer = _fingerGestures.gameObject.GetComponent <PinchRecognizer>(); (_fingerGestures.gameObject.GetComponent <DragRecognizer>()).OnGesture += OnDrag; _swipeRecognizer.OnGesture += OnSwip; _pinchRecognizer.OnGesture += OnPinch; }
protected override void OnRegister() { base.OnRegister(); enableGestureController.AddListener(EnableGestureSignalEvent); mTapRecognizer = gameObject.AddComponent <TapRecognizer> (); mTapRecognizer.UseSendMessage = false; mTapRecognizer.IsExclusive = true; mSwipeRecognizer = gameObject.AddComponent <SwipeRecognizer> (); mSwipeRecognizer.UseSendMessage = false; mSwipeRecognizer.IsExclusive = true; mDragRecognizer = gameObject.AddComponent <DragRecognizer> (); mDragRecognizer.UseSendMessage = false; mDragRecognizer.IsExclusive = true; mTwoFingerDragRecognizer = gameObject.AddComponent <DragRecognizer> (); mTwoFingerDragRecognizer.RequiredFingerCount = 2; mTwoFingerDragRecognizer.UseSendMessage = false; mTwoFingerDragRecognizer.IsExclusive = true; mPinchRecognizer = gameObject.AddComponent <PinchRecognizer> (); mPinchRecognizer.UseSendMessage = false; mPinchRecognizer.IsExclusive = true; mTwistRecognizer = gameObject.AddComponent <TwistRecognizer> (); mTwistRecognizer.UseSendMessage = false; mTwistRecognizer.IsExclusive = true; // mPressRecognizer = gameObject.AddComponent<LongPressRecognizer> (); // mPressRecognizer.UseSendMessage = false; // mPressRecognizer.IsExclusive = true; mFingeDown = gameObject.AddComponent <FingerDownDetector> (); mFingeUp = gameObject.AddComponent <FingerUpDetector> (); mTapRecognizer.OnGesture += OnSceneTap; mDragRecognizer.OnGesture += OnSceneDrag; mPinchRecognizer.OnGesture += OnScenePinch; mSwipeRecognizer.OnGesture += OnSceneSwipe; mTwoFingerDragRecognizer.OnGesture += OnSceneTwoFingerDrag; mTwistRecognizer.OnGesture += OnSceneTwist; mFingeDown.OnFingerDown += OnSceneDown; mFingeUp.OnFingerUp += OnSceneUp; }
private void InstallGestureRecognizers() { //xg_IC = GameObject.Find(str_Intell_Control).GetComponent<XgIntellControl>(); //xg_Pc = GameObject.Find(str_Pic_Control).GetComponent<XgPictrueControl>(); List <GestureRecognizer> recogniers = new List <GestureRecognizer>(GetComponents <GestureRecognizer>()); DragRecognizer drag = recogniers.Find(r => r.EventMessageName == "OnDrag") as DragRecognizer; DragRecognizer twoFingerDrag = recogniers.Find(r => r.EventMessageName == "OnTwoFingerDrag") as DragRecognizer; PinchRecognizer pinch = recogniers.Find(r => r.EventMessageName == "OnPinch") as PinchRecognizer; // check if we need to automatically add a screenraycaster if (OnlyRotateWhenDragStartsOnObject) { ScreenRaycaster raycaster = gameObject.GetComponent <ScreenRaycaster>(); if (!raycaster) { raycaster = gameObject.AddComponent <ScreenRaycaster>(); } } if (!drag) { drag = gameObject.AddComponent <DragRecognizer>(); drag.RequiredFingerCount = 1; drag.IsExclusive = true; drag.MaxSimultaneousGestures = 1; drag.SendMessageToSelection = GestureRecognizer.SelectionType.None; } if (!pinch) { pinch = gameObject.AddComponent <PinchRecognizer>(); } if (!twoFingerDrag) { twoFingerDrag = gameObject.AddComponent <DragRecognizer>(); twoFingerDrag.RequiredFingerCount = 2; twoFingerDrag.IsExclusive = true; twoFingerDrag.MaxSimultaneousGestures = 1; twoFingerDrag.ApplySameDirectionConstraint = true; twoFingerDrag.EventMessageName = "OnTwoFingerDrag"; } }
void Awake() { instance = this; FingerDownDetector downDetector = GetComponent <FingerDownDetector>(); downDetector.UseSendMessage = false; FingerUpDetector upDetector = GetComponent <FingerUpDetector>(); upDetector.UseSendMessage = false; SwipeRecognizer swipeRecognizer = GetComponent <SwipeRecognizer>(); swipeRecognizer.UseSendMessage = false; //swipeRecognizer.Delegate = gameObject.AddComponent<SwipeGestureRecognizerDelegate>(); PinchRecognizer pinchRecognizer = GetComponent <PinchRecognizer>(); pinchRecognizer.UseSendMessage = false; //pinchRecognizer.Delegate = gameObject.AddComponent<PinchGestureRecognizerDelegate>(); }
private void SwitchFingerGesture(bool sw) { GameObject gesture = GameObject.FindGameObjectWithTag(Config.TAG_GESTURE); if (gesture != null) { TapRecognizer tr = gesture.GetComponent <TapRecognizer>(); if (tr != null) { tr.UseSendMessage = sw; } LongPressRecognizer lpr = gesture.GetComponent <LongPressRecognizer>(); if (lpr != null) { lpr.UseSendMessage = sw; } } GameObject mainCamera = GameObject.FindGameObjectWithTag(Config.TAG_MAIN_CAMERA); if (mainCamera != null) { CustomTBOrbit ct = mainCamera.GetComponent <CustomTBOrbit>(); if (ct != null) { ct.enabled = sw; } DragRecognizer dr = mainCamera.GetComponent <DragRecognizer>(); if (dr != null) { dr.UseSendMessage = sw; } PinchRecognizer pr = mainCamera.GetComponent <PinchRecognizer>(); if (pr != null) { pr.UseSendMessage = sw; } } }
private void InitTouch() { // Pan PanRecognizer panRecognizer = new PanRecognizer(); panRecognizer.zIndex = 2; panRecognizer.gestureBeginEvent += (r) => { // Debug.Log("Pan Begin : " + r); }; panRecognizer.gestureRecognizedEvent += (r) => { if (isUIHandleDrag) { DragItem(r.position); return; } if (IsPointerOverUIObject()) { isOverUI = true; } if (isOverUI) { return; } if (isEditItemHandleDrag) { } else { Vector2 delta = -(r.deltaPosition) * 0.1f; camera.Rotate(delta); studioPanel.SetResetButtonActive(true); } }; panRecognizer.gestureEndEvent += r => { isUIHandleDrag = false; isOverUI = false; }; PanRecognizer panTwoRecognizer = new PanRecognizer(2); panTwoRecognizer.zIndex = 3; panTwoRecognizer.gestureRecognizedEvent += (r) => { camera.Move(r.deltaPosition * 0.05f); studioPanel.SetResetButtonActive(true); }; PinchRecognizer pinchRecognizer = new PinchRecognizer(); pinchRecognizer.zIndex = 4; pinchRecognizer.gestureRecognizedEvent += (r) => { camera.Zoom(r.deltaDistance * 0.05f); studioPanel.SetResetButtonActive(true); }; TapRecognizer tapRecognizer = new TapRecognizer(); tapRecognizer.gestureRecognizedEvent += (r) => { if (isOverUI) { isOverUI = false; return; } if (IsPointerOverUIObject()) { return; } if (isItemEdited) { return; } studioPanel.Back(); }; TouchSystem.addRecognizer(panRecognizer); TouchSystem.addRecognizer(panTwoRecognizer); TouchSystem.addRecognizer(pinchRecognizer); TouchSystem.addRecognizer(tapRecognizer); }
void Start() { demoCamera = FindObjectOfType(typeof(DemoCamera)) as DemoCamera; TapRecognizer tapRecognizer = new TapRecognizer(); tapRecognizer.zIndex = 1; tapRecognizer.gestureRecognizedEvent += r => { Debug.Log("Tap: " + r); }; PanRecognizer panRecognizer = new PanRecognizer(); panRecognizer.zIndex = 2; panRecognizer.gestureBeginEvent += r => { Debug.Log("Pan Begin -----: " + r); }; panRecognizer.gestureRecognizedEvent += r => { Debug.Log("Pan : " + r); demoCamera.Rotate(-(r.deltaPosition) * 0.1f); }; panRecognizer.gestureEndEvent += r => { Debug.Log("Pan End -----: " + r); }; PanRecognizer panTwoRecognizer = new PanRecognizer(2); panTwoRecognizer.zIndex = 3; panTwoRecognizer.gestureBeginEvent += r => { Debug.Log("Pan Two Begin -----: " + r); }; panTwoRecognizer.gestureRecognizedEvent += r => { Debug.Log("Pan Two : " + r); demoCamera.Move(r.deltaPosition * 0.05f); }; panTwoRecognizer.gestureEndEvent += r => { Debug.Log("Pan Two End -----: " + r); }; PinchRecognizer pinchRecognizer = new PinchRecognizer(); pinchRecognizer.zIndex = 4; pinchRecognizer.gestureBeginEvent += r => { Debug.Log("Pinch Begin -----: " + r); }; pinchRecognizer.gestureRecognizedEvent += r => { Debug.Log("Pinch : " + r); demoCamera.Zoom(r.deltaDistance * 0.05f); }; pinchRecognizer.gestureEndEvent += r => { Debug.Log("Pinch End -----: " + r); }; TouchSystem.addRecognizer(tapRecognizer); TouchSystem.addRecognizer(panRecognizer); TouchSystem.addRecognizer(panTwoRecognizer); TouchSystem.addRecognizer(pinchRecognizer); }