private void UiElementOnManipulationCompleted(object sender, ManipulationCompletedEventArgs e) { var gesture = gestureRecognizer.Gesture; if (isDoubleTapping && Math.Abs(e.TotalManipulation.Translation.X) < 0.02) { PinchAction?.Invoke(); } else if (gesture == TouchGestureType.MoveRightToLeft) { SwipeLeftAction?.Invoke(); } else if (gesture == TouchGestureType.MoveLeftToRight) { SwipeRightAction?.Invoke(); } else if (gesture == TouchGestureType.MoveBottomToUp) { SwipeUpAction?.Invoke(); } else if (gesture == TouchGestureType.MoveTopToBottom) { SwipeDownAction?.Invoke(); } else if (gesture == TouchGestureType.SingleTap) { SingleTapAction?.Invoke(); } }
public void CreatePinchableObject(PrimitiveType shapeType, PinchAction pinchAction) { try { GameObject obj = GameObject.CreatePrimitive(shapeType); float distanceInPrecentage = (float)pinchAction.DifficultyLevel / (float)(_DifficultyMax); float wantedDistance = distanceInPrecentage * maxDistance; switch (shapeType) { case PrimitiveType.Cylinder: obj.AddComponent <CapsuleCollider>(); // for trigger obj.transform.localScale = new Vector3(0.02f, 0.05f, 0.02f); break; case PrimitiveType.Cube: obj.AddComponent <BoxCollider>(); // for trigger obj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); //obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); break; case PrimitiveType.Sphere: obj.AddComponent <SphereCollider>(); // for trigger obj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); //obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); break; case PrimitiveType.Capsule: obj.AddComponent <CapsuleCollider>(); // for trigger obj.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); break; } obj.GetComponent <Collider>().isTrigger = true; obj.AddComponent <Rigidbody>(); obj.GetComponent <Rigidbody>().useGravity = true; obj.AddComponent <PinchGrabable>(); obj.GetComponent <PinchGrabable>().enabled = true; obj.GetComponent <PinchGrabable>().PinchAction = pinchAction; obj.GetComponent <Renderer>().material.color = pinchToColorDict[pinchAction.Type]; m_PinchableObjList.Add(obj); obj.transform.parent = m_PinchableParent.transform; //obj.transform.localPosition = Vector3.zero; // obj.transform.localPosition = new Vector3(Random.Range(minX, maxX), Random.Range(minY, maxY), Random.Range(minZ, maxZ)); obj.transform.localPosition = GetRandomLocation(pinchAction, wantedDistance); } catch (Exception e) { MainController.PrintToLog(e.ToString(), MainController.LogType.Error); } }
private Vector3 GetRandomLocation(PinchAction pinchAction, float radius) { float xCenter = 0; float x = 0; float z = 0; int count = 0; bool finished = false; switch (pinchAction.Type) { case PinchType.Pad2: xCenter = m_pad2_XAnchor; break; case PinchType.Pad3: xCenter = m_pad3_XAnchor; break; case PinchType.Tip2: xCenter = m_tip2_XAnchor; break; case PinchType.Tip3: xCenter = m_tip3_XAnchor; break; } while (!finished /*&& count < 10*/) { count++; Random.InitState(System.DateTime.Now.Millisecond); float angle = Random.Range((float)Math.PI, (float)(2 * Math.PI)); x = (float)Math.Cos(angle) * radius + xCenter; z = Math.Min((float)Math.Sin(angle) * radius, m_PinchableParent.transform.position.z); //x = xCenter; //z = -maxDistance; if (CheckIfPointInArea(x, z)) { finished = true; } } return(new Vector3(x, 0, z)); }
private Vector3 GetRandomLocation(PinchAction pinchAction, float radius) { float xCenter = 0; float x = 0; float z = 0; int count = 0; bool finished = false; switch (pinchAction.Type) { case PinchType.Pad2: xCenter = m_pad2_XAnchor; break; case PinchType.Pad3: xCenter = m_pad3_XAnchor; break; case PinchType.Tip2: xCenter = m_tip2_XAnchor; break; case PinchType.Tip3: xCenter = m_tip3_XAnchor; break; } while (!finished && count < 5) { count++; float angle = Random.Range((float)Math.PI, (float)(2 * Math.PI)); x = (float)Math.Cos(angle) * radius + xCenter; z = (float)Math.Sin(angle) * radius; if (CheckIfPointInArea(x, z)) { finished = true; } } return(new Vector3(x, m_PinchableParent.transform.position.y, z)); }
private void PinchGestureRecognizer_PinchUpdated(object sender, PinchGestureUpdatedEventArgs e) { PinchAction?.Invoke(e); }