/// <summary> /// Abstract method to return raw data from the device. /// Returns the trigger based raw device value. /// </summary> /// <returns>Raw (untransformed) device data</returns> public override object GetRawValue() { /// Get current device state bool curVal = ClusterInput.GetButton(id); int curFrame = Time.frameCount; bool retVal = false; /// If the value has already been retreived this frame, the return /// the result. if (curFrame == lastFrame) { retVal = lastRetVal; } else { /// Otherwise get the value of the button and save state. if (Trigger == ToggleState.Value) { retVal = curVal; } else if (Trigger == ToggleState.Press) { retVal = curVal && !lastValue; } else if (Trigger == ToggleState.Release) { retVal = !curVal && lastValue; } else { retVal = false; } lastValue = curVal; lastFrame = curFrame; lastRetVal = retVal; } /// return the button value. return(retVal); }
// Update is called once per frame void Update() { List <Device> vrpnDevices = (from device in InputManager.map.Devices where device is VRPN select device).ToList(); if (VRPNTimeline == VRPNTimelineType.Off || timelines.Count != vrpnDevices.Count()) { foreach (TimeLine iv in timelines) { Destroy(iv.gameObject); } timelines.Clear(); } if (VRPNTimeline != VRPNTimelineType.Off) { if (timelines.Count < vrpnDevices.Count) { for (int i = 0; i < vrpnDevices.Count; i++) { GameObject plot = new GameObject(); plot.transform.parent = transform; plot.name = vrpnDevices[i].ToString(); TimeLine iv = plot.AddComponent <TimeLine>(); timelines.Add(iv); plot.transform.localPosition = new Vector3(0, -i * .3f); } } for (int i = 0; i < vrpnDevices.Count; i++) { // Only VRPN devices are shown. VRPN device = vrpnDevices[i] as VRPN; float value = 0f; if (VRPNTimeline == VRPNTimelineType.FromClusterInput) { if (device.InputType == ClusterInputType.Axis) { value = ClusterInput.GetAxis(device.id); } if (device.InputType == ClusterInputType.Button) { value = ClusterInput.GetButton(device.id) ? 1f : 0f; } } else { object valueObject = null; if (VRPNTimeline == VRPNTimelineType.FromDeviceClassRaw) { valueObject = device.GetRawValue(); } if (VRPNTimeline == VRPNTimelineType.FromDeviceClassTransformed) { valueObject = device.GetValue(); } value = (device.GetRawValue() as float?).GetValueOrDefault(); if (valueObject is bool) { value = (valueObject as bool?).GetValueOrDefault() ? 1.0f : 0f; } } timelines[i].AddPt(value); } } }
public bool GetValue() { return(ClusterInput.GetButton(this.inputName)); }