本文整理汇总了C#中Touch类的典型用法代码示例。如果您正苦于以下问题:C# Touch类的具体用法?C# Touch怎么用?C# Touch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Touch类属于命名空间,在下文中一共展示了Touch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestForTouchOrSwipeGesture
private void TestForTouchOrSwipeGesture(Touch touch)
{
Vector2 lastPosition = touch.position;
float distance = Vector2.Distance(lastPosition, touchStartPosition);
if (distance > minimumSwipeDistanceInPixels)
{
float dy = lastPosition.y - touchStartPosition.y;
float dx = lastPosition.x - touchStartPosition.x;
float angle = Mathf.Rad2Deg * Mathf.Atan2(dx, dy);
angle = (360 + angle - 45) % 360;
if (angle < 90)
OnSwipeDetectedRaise(Swipe.Right);
else if (angle < 180)
OnSwipeDetectedRaise(Swipe.Down);
else if (angle < 270)
OnSwipeDetectedRaise(Swipe.Left);
else
OnSwipeDetectedRaise(Swipe.Up);
}
else
{
OnTouchDetectedRaise(touch);
}
}
示例2: Update
private void Update() {
if(Interactable) {
foreach(Touch touch in Input.touches) {
if(rectTransform.rect.Contains((Vector3) touch.position - rectTransform.position) && touch.phase == TouchPhase.Began) {
followTouch = touch;
OnPointerDown();
}
}
foreach (Touch touch in Input.touches) {
if (followTouch.fingerId == touch.fingerId && rectTransform.rect.Contains((Vector3)touch.position - rectTransform.position)) {
if (OnHold != null)
OnHold.Invoke();
}
}
foreach (Touch touch in Input.touches) {
if(followTouch.fingerId == touch.fingerId &&
(touch.phase == TouchPhase.Ended
|| touch.phase == TouchPhase.Canceled
|| !rectTransform.rect.Contains((Vector3) touch.position - rectTransform.position))) {
OnPointerUp();
}
}
}
}
示例3: Update
void Update ()
{
if (Input.touchCount > 0)
{
myTouch = Input.GetTouch(0);
myFIngerID = myTouch.fingerId;
}
else
{
iWasTouched = false;
hasMoved = false;
}
if (EventSystem.current.IsPointerOverGameObject(myFIngerID) && Input.touchCount > 0)
{
iWasTouched = true;
return;
}
gameObject.transform.GetChild(0).GetComponent<Text>().text = iWasTouched.ToString();
if (iWasTouched == true && myTouch.phase == TouchPhase.Moved)
{
hasMoved = true;
gameObject.transform.position = myTouch.position;
}
}
示例4: Update
void Update() {
if (Input.touchCount <= 0) {
ID = -1;
}
else if (ID == -1 && Input.touchCount > 0) {
for (var i = 0; i < Input.touchCount; ++i) {
Vector2 temp = new Vector2(Input.touches[i].position.x, Input.touches[i].position.y) - startPos;
if (temp.magnitude < radius * canvas.scaleFactor) {
if (Input.touches[i].phase == TouchPhase.Began) {
ID = Input.touches[i].fingerId;
action = true;
TouchOnJoystick = Input.touches[i];
Debug.Log(TouchOnJoystick.fingerId);
}
}
}
}
for (var i = 0; i < Input.touchCount; ++i) {
if (ID == Input.touches[i].fingerId && action) {
FollowFinger(Input.touches[i].position);
}
}
for (var i = 0; i < Input.touchCount; ++i) {
if (ID == Input.touches[i].fingerId && action) {
if(Input.touches[i].phase == TouchPhase.Canceled || Input.touches[i].phase == TouchPhase.Ended) {
action = false;
if (joystickImage) {
joystickImage.CrossFadeAlpha(0.2f, .1f, true);
}
transform.position = startPos;
ID = -1;
}
}
}
UpdateInput();
#if UNITY_EDITOR
/*//Mouse
if (Input.GetMouseButtonDown(0)) {
if (Mathf.Abs(Input.mousePosition.x - startPos.x) < radius &&
Mathf.Abs(Input.mousePosition.y - startPos.y) < radius) {
FollowFinger(Input.mousePosition);
action = true;
}
}
if(Input.GetMouseButton(0) && action) {
FollowFinger(Input.mousePosition);
}
if(Input.GetMouseButtonUp(0)) {
gameObject.transform.position = startPos;
action = false;
}*/
#endif
}
示例5: MoveInputAt
void MoveInputAt(Touch touch, int n)
{
Ray ray = InputCamera.ScreenPointToRay(touch.position);
RaycastHit hit;
//Handle Swipe
if (Mathf.Abs(touch.position.x - SwipeInfos[n].StartPos.x) > comfortZone) { //Cant be swipe is deviate too much from a straith line
SwipeInfos[n].canBeSwipe_Vertical = false;
//Debug.Log("Swipe Cancelled by mouv : " + n);
}
if (Mathf.Abs(touch.position.y - SwipeInfos[n].StartPos.y) > comfortZone) { //Cant be swipe is deviate too much from a straith line
SwipeInfos[n].canBeSwipe_Horizontal = false;
//Debug.Log("Swipe Cancelled by mouv : " + n);
}
SwipeInfos[n].idleTime = 0;
//check Button presses
if (Physics.Raycast(ray, out hit, TouchInputMask)) {
GameObject newRecipient = hit.collider.transform.gameObject;
if (touchesTargets[n] != null && touchesTargets[n] == newRecipient) {
return;//We are on the same target even though we moved, handle swipes here
} else {
RemoveInputFromButton(touch, n);
newRecipient.SendMessage("FingerOn", n, SendMessageOptions.DontRequireReceiver);
touchesTargets[n] = newRecipient;
}
}
}
示例6: OnTouchEnd
void OnTouchEnd(Touch touch)
{
if (IsPlayer(touch)) {
player.outsideMotion = Vector3.zero;
player = null;
}
}
示例7: assignTouch
private float startTime; // Time when touch first occured
#endregion Fields
#region Methods
// Assign a new touch to track
public void assignTouch(Touch touch)
{
myTouch = touch;
free = false;
processTouch ();
}
示例8: onTouchEnded
public override void onTouchEnded( Touch touch, Vector2 touchPos, bool touchWasInsideTouchFrame )
{
base.onTouchEnded( touch, touchPos, touchWasInsideTouchFrame );
if( onlyFireStartAndEndEvents && onActivationEnded != null )
onActivationEnded( this );
}
示例9: Update
// Update is called once per frame
public void Update(Touch touch)
{
// Is Touch over UI
int pointerID = touch.fingerId;
if (EventSystem.current.IsPointerOverGameObject(pointerID))
{
return;
}
var phase = touch.phase;
switch (phase)
{
case TouchPhase.Began:
Began = true;
break;
case TouchPhase.Moved:
Moved = true;
break;
case TouchPhase.Stationary:
Stationary = true;
break;
case TouchPhase.Ended:
Ended = true;
break;
}
}
示例10: ForEachTouch
protected override void ForEachTouch(Touch touch, Vector2 guiTouchPos)
{
bool shouldLatchFinger = gui.HitTest(touch.position);
if (shouldLatchFinger && (lastFingerId == -1 || lastFingerId != touch.fingerId)) {
lastFingerId = touch.fingerId;
// Tell other joysticks we've latched this finger
for (int index = 0; index < joysticks.Length; index++) {
if (joysticks[index] != this) {
joysticks[index].LatchedFinger (touch.fingerId);
}
}
}
if (lastFingerId == touch.fingerId) {
// Change the location of the joystick graphic to match where the touch is
gui.pixelInset = new Rect (
Mathf.Clamp (guiTouchPos.x, guiBoundary.xMin, guiBoundary.xMax),
Mathf.Clamp (guiTouchPos.y, guiBoundary.yMin, guiBoundary.yMax),
gui.pixelInset.width,
gui.pixelInset.height);
// if the touch is over then reset the joystick to its default position
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) {
ResetJoystick ();
}
}
}
示例11: onTouchBegan
// Touch handlers
public override void onTouchBegan( Touch touch, Vector2 touchPos )
{
base.onTouchBegan( touch, touchPos );
if( onlyFireStartAndEndEvents && onActivationStarted != null )
onActivationStarted( this );
}
示例12: RegisterSpins
void RegisterSpins()
{
if (Input.touchCount == 2)
{
touchOne = Input.GetTouch(0);
touchTwo = Input.GetTouch(1);
touchOnePrev = touchOne.position - touchOne.deltaPosition;
touchTwoPrev = touchTwo.position - touchTwo.deltaPosition;
currentAngle = Angle(touchOne.position, touchTwo.position);
prevAngle = Angle(touchOnePrev, touchTwoPrev);
deltaAngle = Mathf.DeltaAngle(currentAngle, prevAngle);
if (Mathf.Abs(deltaAngle) > minAngle){
spinInput = deltaAngle * (Mathf.PI / 2);
spinning = true;
}
else {
spinInput = 0;
deltaAngle = 0;
spinning = false;
}
}
else {
spinInput = 0;
}
}
示例13: Orbit
/**
* Method: Orbit
* FullName: Orbit
* Access: public
* Qualifier:
* @param Touch touch
* @return void
*/
void Orbit(Touch touch)
{
// rotates around the building
x += touch.deltaPosition.x * xSpeed * 0.02f /* * distance*/;
// rotates up and down (roof top)
y -= touch.deltaPosition.y * ySpeed * 0.02f /* * distance*/;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation = Quaternion.Euler(y, x, 0);
RaycastHit hit;
if (Physics.Linecast(target.position, transform.position, out hit))
{
// distance -= hit.distance;
}
Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
transform.rotation = rotation;
transform.position = position;
}
示例14: ForEachTouch
protected override void ForEachTouch(Touch touch, Vector2 guiTouchPos)
{
base.ForEachTouch(touch, guiTouchPos);
if (lastFingerId == touch.fingerId)
{
// absolute position of touch relative to touchpad defines the input amount:
Vector2 newAbsTouchPos = new Vector2((touch.position.x - touchZoneRect.center.x) / sensitivityRelativeX, (touch.position.y - touchZoneRect.center.y) / sensitivityRelativeY) * 2;
Vector2 newPosition = Vector2.Lerp(position, newAbsTouchPos * sensitivity, Time.deltaTime * interpolateTime);
// scale & clamp the touch position inside the allowed touch zone, between -1 and 1
if (useX)
{
position.x = Mathf.Clamp(newPosition.x, -1, 1);
}
if (useY)
{
position.y = Mathf.Clamp(newPosition.y, -1, 1);
}
// if the touch is over then reset the joystick to its default position
if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
{
ResetJoystick();
}
}
}
示例15: GetTouchPointerEventData
protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
{
PointerEventData pointerData;
var created = GetPointerData(input.fingerId, out pointerData, true);
pointerData.Reset();
pressed = created || (input.phase == TouchPhase.Began);
released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);
if (created)
pointerData.position = input.position;
if (pressed)
pointerData.delta = Vector2.zero;
else
pointerData.delta = input.position - pointerData.position;
pointerData.position = input.position;
pointerData.button = PointerEventData.InputButton.Left;
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
var raycast = FindFirstRaycast(m_RaycastResultCache);
pointerData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
return pointerData;
}