// Update is called once per frame void Update() { if (deviceController != null && deviceController.GetDevice() != null) { CVirtDevice virtDevice = deviceController.GetDevice(); float sumForce = 0; foreach (CVirtHapticEmitter emitter in emitters) { float distance = Vector3.Distance(this.transform.position, emitter.transform.position); if (distance < maxRange && distance < emitter.distance) { float force = emitter.EvaluateForce(this.transform.position); if (sumForce < force) { sumForce = force; } //sumForce = SumUpDecibal(force, force); } } if (virtDevice.HasHaptic()) { virtDevice.HapticSetVolume(Mathf.FloorToInt(100f * sumForce)); } } }
void OnDestroy() { if (deviceController != null && deviceController.GetDevice() != null) { CVirtDevice virtDevice = deviceController.GetDevice(); if (virtDevice.HasHaptic()) { virtDevice.HapticStop(); } } }
public void OnCVirtDeviceControllerCallback(CVirtDevice virtDevice, CVirtDeviceController.CVirtDeviceControllerCallbackType callbackType) { switch (callbackType) { case CVirtDeviceController.CVirtDeviceControllerCallbackType.Connect: virtDevice.HapticSetGain(4); virtDevice.HapticSetFrequency(60); virtDevice.HapticSetVolume(0); // virtDevice.HapticPlay(); break; case CVirtDeviceController.CVirtDeviceControllerCallbackType.Disconnect: virtDevice.HapticStop(); break; } }