void Start() { if (motorContainer == null) { BhapticsLogger.LogError("VisualFeedback.cs - Start() / motorContainer is null"); return; } var tmpMotorContainer = Instantiate(motorContainer, motorContainer.parent); tmpMotorContainer.localPosition = motorContainer.localPosition; tmpMotorContainer.localRotation = motorContainer.localRotation; var tmpList = new List <Transform>(); for (int i = 0; i < motorContainer.childCount; ++i) { tmpList.Add(motorContainer.GetChild(i)); } motors = tmpList.ToArray(); UpdateFeedback(new HapticFeedback(BhapticsUtils.ToPositionType(devicePos), new byte[motors.Length])); }
void Awake() { if (dontDestroyOnLoad) { if (_manager == null) { DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); return; } } var uninstalledMessage = "bHaptics Player is not installed. Plugin is now disabled. Please download here." + "\nhttp://bhaptics.com/app.html#download"; _manager = this; if (!BhapticsUtils.IsPlayerInstalled()) { Debug.LogError(uninstalledMessage); return; } if (!BhapticsUtils.IsPlayerRunning()) { Debug.Log("bHaptics Player is not running, try launching bHaptics Player."); BhapticsUtils.LaunchPlayer(launchPlayerIfNotRunning); } }
public void Play(ScaleOption option = null) { if (option == null) { option = new ScaleOption(Intensity, Duration); } switch (FeedbackType) { case FeedbackType.DotMode: if (DotPoints == null) { Debug.LogError("DotPoints not defined"); return; } player.Submit(_key, ToPositionType(Position), DotPoints, TimeMillis); break; case FeedbackType.PathMode: if (Points == null) { Debug.LogError("Points not defined"); return; } player.Submit(_key, ToPositionType(Position), new List <PathPoint>(Convert(Points)), TimeMillis); break; case FeedbackType.TactFile: if (!isOriginFileRegistered) { isOriginFileRegistered = true; var feedbackFile = CommonUtils.ConvertJsonStringToTactosyFile(FeedbackFile.Value); //Debug.Log("Register tact file " + FeedbackFile.Id + ", " + FeedbackFile.Key); player.Register(FeedbackFile.Id, feedbackFile.Project); } if (FeedbackFile.Type == BhapticsUtils.TypeVest) { player.SubmitRegisteredVestRotation(FeedbackFile.Id, _key, new RotationOption(VestRotationAngleX + TactFileOffsetX, VestRotationOffsetY + TactFileOffsetY), option); } else if (FeedbackFile.Type == BhapticsUtils.TypeTactosy && IsReflectTactosy) { if (!isRegistered) { isRegistered = true; var project = BhapticsUtils.ReflectLeftRight(FeedbackFile.Value); player.Register(FeedbackFile.Id + "Reflect", project); } player.SubmitRegistered(FeedbackFile.Id + "Reflect", _key, option); } else { player.SubmitRegistered(FeedbackFile.Id, _key, option); } break; } }
public virtual void Play(Vector3 contactPos, Vector3 targetPos, Vector3 targetForward, float targetHeight) { Vector3 targetDir = contactPos - targetPos; var angle = BhapticsUtils.Angle(targetDir, targetForward); var offsetY = (contactPos.y - targetPos.y) / targetHeight; Play(1f, 1f, angle, offsetY); }
public override void Play(Vector3 contactPos, Vector3 targetPos, Vector3 targetForward, float targetHeight, string identifier = "") { Vector3 targetDir = contactPos - targetPos; var angle = BhapticsUtils.Angle(targetDir, targetForward); var offsetY = (contactPos.y - targetPos.y) / targetHeight; Play(this.Intensity, this.Duration, angle, offsetY, identifier); }
void Update() { if (!visualizeFeedback) { return; } if (!BhapticsUtils.IsPlayerInstalled()) { return; } if (Application.platform == RuntimePlatform.Android) { if (!Monitor.TryEnter(_changedFeedback)) { Debug.Log("failed to enter"); return; } try { foreach (var feedback in _changedFeedback) { foreach (var vis in visualFeedback) { if (vis.Position == feedback.Position) { vis.UpdateFeedback(feedback); } } } _changedFeedback.Clear(); } finally { Monitor.Exit(_changedFeedback); } } else { foreach (var vis in visualFeedback) { HapticApi.status status; HapticApi.TryGetResponseForPosition(vis.Position, out status); byte[] result = new byte[20]; for (int i = 0; i < result.Length; i++) { result[i] = (byte)status.values[i]; } HapticFeedback feedback = new HapticFeedback(vis.Position, result); vis.UpdateFeedback(feedback); } } }
/// <summary> /// Play the haptic feedback with optional values. /// </summary> /// <param name="intensity">Intensity value of haptic feedback.(Overwrite, not multiplication)</param> /// <param name="duration">Duration value of haptic feedback.(Overwrite, not multiplication)</param> /// <param name="contactPos"></param> /// <param name="targetPos"></param> /// <param name="targetForward"></param> /// <param name="targetHeight"></param> /// <param name="identifier">Use when playing haptic feedback independently.</param> public virtual void Play(float intensity, float duration, Vector3 contactPos, Vector3 targetPos, Vector3 targetForward, float targetHeight, string identifier = "") { Vector3 targetDir = contactPos - targetPos; var angle = BhapticsUtils.Angle(targetDir, targetForward); var offsetY = (contactPos.y - targetPos.y) / targetHeight; Play(intensity, duration, angle, offsetY, identifier); }
void OnDisable() { if (!BhapticsUtils.IsPlayerInstalled()) { return; } HapticPlayer.TurnOff(); HapticPlayer.Disable(); HapticPlayer.StatusReceived -= OnStatusChanged; }
public bool IsConnect(HapticDeviceType type, bool isLeft = true) { foreach (var device in deviceList) { if (device.Position == BhapticsUtils.ToPositionType(type, isLeft) && device.IsConnected) { return(true); } } return(false); }
private void Play(PositionTag posTag, Vector3 contactPos, Vector3 targetPos, Vector3 targetForward, float targetHeight) { var angle = 0f; var offsetY = 0f; if (posTag == PositionTag.Body) { Vector3 targetDir = contactPos - targetPos; angle = BhapticsUtils.Angle(targetDir, targetForward); offsetY = (contactPos.y - targetPos.y) / targetHeight; } Play(posTag, angle, offsetY); }
void OnEnable() { if (!BhapticsUtils.IsPlayerInstalled()) { gameObject.SetActive(false); return; } InitVisualFeedback(); HapticPlayer.StatusReceived += OnStatusChanged; HapticPlayer.Enable(); LoadFeedbackFile(); }
void Update() { if (!visualizeFeedbacks) { return; } if (!BhapticsUtils.IsPlayerInstalled()) { return; } if (_changedFeedbacks.Count <= 0) { return; } if (!Monitor.TryEnter(_changedFeedbacks)) { Debug.Log("failed to enter"); return; } try { foreach (var feedback in _changedFeedbacks) { foreach (var vis in visualFeedbacks) { if (vis.Position == feedback.Position) { vis.UpdateFeedbacks(feedback); } } } _changedFeedbacks.Clear(); } finally { Monitor.Exit(_changedFeedbacks); } }
void Awake() { if (dontDestroyOnLoad) { if (Instance == null) { DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); return; } } var uninstalledMessage = "bHaptics Player is not installed. Plugin is now disabled. Please download here." + "\nhttp://bhaptics.com/app.html#download"; Instance = this; if (!BhapticsUtils.IsPlayerInstalled()) { Debug.LogError(uninstalledMessage); return; } if (!BhapticsUtils.IsPlayerRunning()) { Debug.Log("bHaptics Player is not running, try launching bHaptics Player."); BhapticsUtils.LaunchPlayer(launchPlayerIfNotRunning); } if (Application.platform == RuntimePlatform.Android && BhapticsAndroidManager.Instance == null) { var bhapticsAndroidManager = Instantiate(bHapticsAndroidManagerPrefab, Vector3.zero, Quaternion.identity); bhapticsAndroidManager.name = "[bHapticsAndroidManager]"; bhapticsAndroidManager.transform.parent = transform; } }
void Awake() { var uninstalledMessage = "bHaptics Player is not installed. Plugin is now disabled. Please download here." + "\nhttp://bhaptics.com/app.html#download"; _manager = this; if (!BhapticsUtils.IsPlayerInstalled()) { Debug.LogError(uninstalledMessage); return; } if (!BhapticsUtils.IsPlayerRunning()) { Debug.Log("bHaptics Player is not running, try launching bHaptics Player."); BhapticsUtils.LaunchPlayer(launchPlayerIfNotRunning); } if (Application.platform == RuntimePlatform.Android) { Invoke("AndroidStopScan", 3f); } }
public override void Play(float intensity, float duration, float vestRotationAngleX, float vestRotationOffsetY, string identifier = "") { if (!BhapticsManager.Init) { BhapticsManager.Initialize(); //return; } var haptic = BhapticsManager.GetHaptic(); if (haptic == null) { return; } if (Mode == SimpleHapticType.DotMode) { haptic.Submit(keyId + identifier, BhapticsUtils.ToPositionType(Position), Convert(DotPoints), TimeMillis); } else { haptic.Submit(keyId + identifier, BhapticsUtils.ToPositionType(Position), Convert(Points), TimeMillis); } }
public bool IsConnect(HapticDeviceType type, bool isLeft = true) { return(HapticApi.IsDevicePlaying(BhapticsUtils.ToPositionType(type, isLeft))); }
public void RegisterTactFileStrReflected(string key, string tactFileStr) { var project = BhapticsUtils.ReflectLeftRight(tactFileStr); Register(key, project); }