/// <summary> /// Are all of the keys being held down? /// </summary> /// <returns></returns> public bool IsBeingPressed() { var isButtonsPressed = _keyPressDefinitions.Any((definition) => definition.All(InputWrapper.GetKey)); var isAxisPressed = (_axisDefinition == null) ? true : InputWrapper.GetAxis(_axisDefinition) != 0; return(isButtonsPressed && isAxisPressed); }
/// <summary> /// If pressing a key you will get a 1f. If this includes an axis, then you will /// get -1f to 1f (but sometimes higher ranges depending on the axis) /// </summary> /// <returns></returns> public float GetPressedValue() { if (!IsBeingPressed()) { return(0); } if (_axisDefinition != null) { return(InputWrapper.GetAxis(_axisDefinition)); } return(1); }
void Update() { target = target.Clamp(min, max); offset = offset.TLerp(target, dampening); #if UNITY_ANDROID || UNITY_IOS if (enableTouchScrolling) { scrollVelocity += InputF.TouchVelocity(ScreenF.all).y *scrollSpeed; } #endif scrollVelocity += InputWrapper.GetAxis("Mouse ScrollWheel") * -scrollSpeed; target += scrollVelocity * Time.deltaTime; scrollVelocity = scrollVelocity.TLerp(0, velocityDampening); foreach (Transform t in angles.Keys) { if (t != null) { Vector3 pos = Vector3.zero; float angle = (offset + angles[t]).Clamp(-355, 355); float absAngle = angle.Abs(); t.localScale = Vector3.one * (1 + selectionGrow * (1 - absAngle / 355)); /* * if (absAngle < 5) { * if (selected != t) { * t.SetColor("_Color", Color.red); * if (selected != null) { * selected.SetColor("_Color", Color.white); * } * selected = t; * } * * } * //*/ pos.y = scales.y * (float)System.Math.Sinh(angle * Mathf.Deg2Rad); pos.z = scales.z * (float)System.Math.Cosh(angle * Mathf.Deg2Rad); t.localPosition = pos; } } }
private void Update() { if (!works) { // previousValX = trans } transform.localPosition = new Vector3(basePosition.x, basePosition.y + InputWrapper.GetAxis(analogY, Controller), basePosition.z - InputWrapper.GetAxis(analogX, Controller) * (Position == 0 ? 1 : -1)); float currentValX = transform.localPosition.z; works = InputWrapper.GetAxis(analogY, Controller) > 0; if (works) { boat.AddRelativeTorque(new Vector3(0, speed * 5 * Mathf.Clamp((currentValX - previousValX), -1, 1) * (Position == 0 ? 1 : -1))); boat.AddForce(owner.transform.forward * speed * Mathf.Clamp((currentValX - previousValX), -1, 1)); } previousValX = transform.localPosition.z; }
public void Record() { var noticedAxisThreshold = 0.5f; // don't consider an axis noticed for record for "blips" var noticedKeys = InputWrapper.KeyCodes .Where(InputWrapper.GetKey) .Where((k) => !KeyChord.IGNORED_KEYS.Contains(k)) .Where((k) => !Regex.IsMatch(k.ToString(), "^Joystick\\d")) // joy buttons register twice -- ignore most specific one .ToList(); var noticedAxis = InputWrapper.AxisNames .Where((n) => Mathf.Abs(InputWrapper.GetAxis(n)) >= noticedAxisThreshold) .FirstOrDefault(); if (InProgress && noticedKeys.Count == 0 && noticedAxis == null) { // looks like we just finished recording... don't // set the internal state anymore return; } if (noticedKeys.Count > 0) { InProgress = true; foreach (var k in noticedKeys) { _recordedKeys.Add(k); } } if (noticedAxis != null) { InProgress = true; _recordedAxis = noticedAxis; } return; }