private void HandleSimplePanStateChanged(object sender, TouchScript.Events.GestureStateChangeEventArgs e) { SimplePanGesture target = sender as SimplePanGesture; switch (e.State) { case Gesture.GestureState.Began: case Gesture.GestureState.Changed: if (target.LocalDeltaPosition != Vector3.zero) { FlowView.Instance.Flow(target.LocalDeltaPosition.x); } break; case Gesture.GestureState.Ended: float velocity = (target.LocalTransformCenter.x - target.PreviousLocalTransformCenter.x) * 0.5f; if (Mathf.Abs(velocity) > Threshold) { FlowView.Instance.Inertia(velocity); } else { FlowView.Instance.Flow(); } break; } }
void HandlePanned(object sender, System.EventArgs e) { SimplePanGesture gPan = sender as SimplePanGesture; deltaTouchPan = gPan.ScreenPosition - gPan.PreviousScreenPosition; MoveTo(deltaTouchPan); }
void HandlePanned(object sender, System.EventArgs e) { Debug.Log(" panned "); SimplePanGesture gesture = sender as SimplePanGesture; Debug.Log(gesture.ScreenPosition); Debug.Log(gesture.LocalDeltaPosition); }
void HandlePanned(object sender, System.EventArgs e) { if (allowPanning) { Debug.Log("Panned"); SimplePanGesture gesture = sender as SimplePanGesture; panValue = gesture.LocalDeltaPosition; targetPosition -= new Vector3(panValue.x, panValue.y, panValue.z); } }
/// <summary> /// Initializes the components. /// </summary> private void InitializeComponents() { m_collider2D = gameObject.AddDerivedIfNoBase <Collider2D, BoxCollider2D>(); m_collider2D.isTrigger = true; m_pressGesture = gameObject.AddComponentNoDupe <PressGesture>(); m_releaseGesture = gameObject.AddComponentNoDupe <ReleaseGesture>(); m_panGesture = gameObject.AddComponentNoDupe <SimplePanGesture>(); m_pressGesture.Pressed += OnPlayerPress; m_releaseGesture.Released += OnPlayerRelease; m_panGesture.Panned += OnPlayerSwipe; }
public override void OnEnter() { gesture = GestureUtils.GetGesture <SimplePanGesture>(Fsm, GameObject, Component, true); if (gesture == null) { LogError("Gesture is missing"); return; } gesture.PanStarted += gesturePanStartedHandler; gesture.Panned += gesturePannedHandler; gesture.PanCompleted += gesturePanCompletedHandler; }
/// <summary> /// Updates this element's draggable property. /// </summary> private void UpdateDraggable() { if (m_isDraggable && (m_simplePanGesture == null || !m_simplePanGesture.enabled)) { m_simplePanGesture = this.gameObject.AddComponentNoDupe <SimplePanGesture>(); m_simplePanGesture.enabled = true; } else if (!m_isDraggable && m_simplePanGesture != null) { Destroy(m_simplePanGesture); m_simplePanGesture = null; } }
void HandlePanned(object sender, System.EventArgs e) { SimplePanGesture panGesture = sender as SimplePanGesture; Debug.Log("HandlePanned: " + panGesture.LocalDeltaPosition); GameObject.Find("Main Camera").transform.position -= panGesture.LocalDeltaPosition; if (panGesture.ActiveTouches.Count > 2) { // } }
void OnDisable() { if (CanPress) { GetComponent <PressGesture>().Pressed -= HandlePressed; GetComponent <ReleaseGesture>().Released -= HandleReleased; } if (IsPannable) { SimplePanGesture panGesture = GetComponent <SimplePanGesture>(); panGesture.Panned -= HandlePanned; panGesture.PanCompleted -= HandlePanCompleted; panGesture.PanStarted -= HandlePanStarted; } }
/// <summary> /// Initialize all components. /// </summary> protected virtual void InitializeComponents() { m_isPressablePrev = m_isPressable; m_isDraggablePrev = m_isDraggable; m_isFlickablePrev = m_isFlickable; // Make sure element has a SpriteRenderer component m_spriteRenderer = this.GetComponent <SpriteRenderer>(); if (m_spriteRenderer == null) { m_spriteRenderer = this.GetComponentInChildren <SpriteRenderer>(); if (m_spriteRenderer == null) { m_spriteRenderer = this.gameObject.AddComponent <SpriteRenderer>(); } } // Make sure the elment has a Collider2D component if it needs one if (m_isPressable || m_isDraggable || m_isFlickable) { AddOrGetComponentCollider2D(); } // Make sure element has a PressGesture component if it needs one if (m_isPressable) { m_pressGesture = this.gameObject.AddComponentNoDupe <PressGesture>(); AddPressDelegate(OnObjectPress); AddReleaseDelegate(OnObjectRelease); } // Make sure element has a SimplePanGesture component if it needs one // Make sure element has a Transformer2D component if it needs one if (m_isDraggable) { m_simplePanGesture = this.gameObject.AddComponentNoDupe <SimplePanGesture>(); m_transformer2D = this.gameObject.AddComponentNoDupe <Transformer2D>(); } // Make sure element has a FlickGesture component if it needs one if (m_isFlickable) { m_flickGesture = this.gameObject.AddComponentNoDupe <FlickGesture>(); } // No need for ReleaseGesture - this script has a different implementation for release }
/// <summary> /// Updates the IsDraggable property /// Components are added/enabled/disabled as needed /// </summary> protected void UpdateIsDraggableField() { if (m_isDraggable == m_isDraggablePrev) { return; } if (m_isDraggable) { AddOrGetComponentCollider2D(); m_simplePanGesture = this.gameObject.AddComponentNoDupe <SimplePanGesture>(); m_transformer2D = this.gameObject.AddComponentNoDupe <Transformer2D>(); m_simplePanGesture.enabled = true; } else { if (m_simplePanGesture != null) { m_simplePanGesture.enabled = false; } } m_isDraggablePrev = m_isDraggable; }