public void Receive(PlayerResponse response) { try { lock (activeKeys) { activeKeys.Clear(); activeKeys.AddRange(response.ActiveKeys); } lock (registered) { registered.Clear(); registered.AddRange(response.RegisteredKeys); } lock (status) { status = response.Status; } } catch (Exception e) { BhapticsLogger.LogInfo("Receive: {0}", e.Message); } }
private static void OnClickRefreshTactFiles() { var saveAsPath = EditorUtility.SaveFolderPanel("Save as *.tact File", @"\download\", ""); if (!string.IsNullOrEmpty(saveAsPath)) { var allInstances = GetAllInstances <FileHapticClip>(); foreach (var ins in allInstances) { var path = saveAsPath + @"\" + Path.GetDirectoryName(AssetDatabase.GetAssetPath(ins.GetInstanceID())); path = path.Replace("Assets/", ""); if (!Directory.Exists(path)) { //if it doesn't, create it Directory.CreateDirectory(path); } File.WriteAllText(path + "\\" + ins.name + ".tact", ins.JsonValue); } BhapticsLogger.LogInfo(".tact files saved count: {0}\n path: {1}", allInstances.Length, saveAsPath); } else { BhapticsLogger.LogError("Folder not selected."); } }
public void Submit(string key, PositionType position, List <PathPoint> points, int durationMillis) { if (androidJavaObject == null) { return; } try { float[] x = new float[points.Count]; float[] y = new float[points.Count]; int[] intensity = new int[points.Count]; for (var i = 0; i < points.Count; i++) { x[i] = points[i].X; y[i] = points[i].Y; intensity[i] = points[i].Intensity; } androidJavaObject.Call("submitPath", key, position.ToString(), x, y, intensity, durationMillis); } catch (Exception e) { BhapticsLogger.LogError("submitPath() : {0}", e.Message); } }
private static void OnClickRefreshTactFiles() { var saveAsPath = EditorUtility.SaveFolderPanel("Save as *.tact File", @"\download\", ""); if (!string.IsNullOrEmpty(saveAsPath)) { var allInstances = GetAllInstances <FileHapticClip>(); foreach (var allInstance in allInstances) { var path = saveAsPath + @"\" + allInstance.ClipType; if (!Directory.Exists(saveAsPath + @"\" + allInstance.ClipType)) { //if it doesn't, create it Directory.CreateDirectory(path); } File.WriteAllText(path + "\\" + allInstance.name + ".tact", allInstance.JsonValue); } BhapticsLogger.LogInfo("tact files saved to {0}", saveAsPath); } else { BhapticsLogger.LogError("Folder not selected."); } }
public static string GetExePath() { #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN if (isInit) { return(exeFilePath); } isInit = true; try { byte[] buf = new byte[500]; int size = 0; if (HapticApi.TryGetExePath(buf, ref size)) { byte[] cleanedArray = SubArray(buf, 0, size); exeFilePath = System.Text.Encoding.UTF8.GetString(cleanedArray).Trim(); return(exeFilePath); } } catch (Exception e) { BhapticsLogger.LogError(e.Message); } exeFilePath = ""; return(exeFilePath); #else return(""); #endif }
public void Submit(string key, PositionType position, List <DotPoint> points, int durationMillis) { if (androidJavaObject == null) { return; } try { int[] indexes = new int[points.Count]; int[] intensity = new int[points.Count]; for (var i = 0; i < points.Count; i++) { indexes[i] = points[i].Index; intensity[i] = points[i].Intensity; } androidJavaObject.Call("submitDot", key, position.ToString(), indexes, intensity, durationMillis); } catch (Exception e) { BhapticsLogger.LogError("submitDot() : {0}", e.Message); } }
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])); }
public static bool IsPlayerRunning() { #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN try { var fileName = Path.GetFileNameWithoutExtension(GetExePath()); if (Is64BitBuild()) { // 64 bit machine var processs = System.Diagnostics.Process.GetProcessesByName(fileName); if (processs.Length >= 1) { return(true); } return(false); } else { // 32 bit machine does not support GetProcessByName. return(true); } } catch (Exception e) { BhapticsLogger.LogError("IsPlayerRunning() " + e.Message); } return(true); #else return(true); #endif }
void Awake() { BhapticsManager.GetHaptic(); if (Bhaptics_Setup.instance == null) { var findObjectOfType = FindObjectOfType <Bhaptics_Setup>(); if (findObjectOfType == null) { var go = new GameObject("[bhaptics]"); go.SetActive(false); var setup = go.AddComponent <Bhaptics_Setup>(); var config = Resources.Load <BhapticsConfig>("BhapticsConfig"); if (config == null) { BhapticsLogger.LogError("Cannot find 'BhapticsConfig' in the Resources folder."); } setup.Config = config; go.SetActive(true); } } if (playOnAwake) { if (loop) { PlayLoop(); } else { PlayHapticClip(); } } }
private void Initialize() { BhapticsManager.Initialize(); if (Config == null) { BhapticsLogger.LogError("BHapticsConfig is not setup!"); return; } if (Application.platform != RuntimePlatform.Android) { if (Config.launchPlayerIfNotRunning && BhapticsUtils.IsPlayerInstalled() && !BhapticsUtils.IsPlayerRunning()) { BhapticsLogger.LogInfo("Try launching bhaptics player."); BhapticsUtils.LaunchPlayer(true); } } #if UNITY_ANDROID if (Config.AndroidManagerPrefab == null) { BhapticsLogger.LogError("[bhaptics] AndroidManagerPrefab is not setup!"); return; } var go = Instantiate(Config.AndroidManagerPrefab, transform); go.alwaysScanDisconnectedDevice = Config.AlwaysScanDisconnectedDevice; #endif }
public static IHaptic GetHaptic() { if (Haptic == null) { try { Init = true; if (Application.platform == RuntimePlatform.Android) { Haptic = new AndroidHaptic(); BhapticsLogger.LogInfo("Android initialized."); } else { Haptic = new BhapticsHaptic(); BhapticsLogger.LogInfo("Initialized."); } } catch (System.Exception e) { } } return(Haptic); }
private static void RegisterWatcher(string extenstion) { #if UNITY_2017_1_OR_NEWER tactFileWatcher = new FileSystemWatcher(Application.dataPath, "*" + extenstion); tactFileWatcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.Attributes | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size; tactFileWatcher.IncludeSubdirectories = true; //sWatcher.Changed += OnChanged; tactFileWatcher.Created += OnCreated; //sWatcher.Deleted += OnDeleted; //sWatcher.Renamed += OnRenamed; tactFileWatcher.EnableRaisingEvents = true; #else BhapticsLogger.LogError("FileSystemWatcher required .Net 4.6 or higher"); #endif }
void Awake() { button = GetComponent <Button>(); unPairButton.GetComponent <Button>().onClick.AddListener(OnUnpairDevice); button.onClick.AddListener(OnClickDevice); BhapticsLogger.LogDebug("start"); }
void ReloadScene() { BhapticsLogger.LogInfo("Reloading scene."); int scene = SceneManager.GetActiveScene().buildIndex; SceneManager.LoadScene(scene, LoadSceneMode.Single); Time.timeScale = 1; }
public void StartScan() { if (hapticPlayer != null) { BhapticsLogger.LogDebug("StartScan()"); hapticPlayer.Call("scan"); } }
void Awake() { var col = GetComponent <Collider>(); if (col == null) { BhapticsLogger.LogInfo("collider is not detected"); } }
static void UpdateWatchers() { BhapticsLogger.LogDebug("UpdateWatchers()"); RegisterWatcher(".tact"); RegisterTactClipDeleteWatcher(); EditorApplication.update += OnEditorApplicationUpdate; triggerRecompile = CheckChanged(); }
public void Refresh() { button = GetComponent <Button>(); BhapticsLogger.LogDebug("Refresh()"); var connectedDevices = BhapticsAndroidManager.GetConnectedDevices(DeviceType); if (connectedDevices.Count > 0) { button.image.sprite = pairImage; unPairButton.SetActive(true); var spriteState = button.spriteState; spriteState.highlightedSprite = pairHoverImage; button.spriteState = spriteState; canPairImage.gameObject.SetActive(false); for (int i = 0; i < pairDeviceCount.childCount; i++) { if (!pairDeviceCount.GetChild(i).gameObject.activeSelf) { break; } pairDeviceCount.GetChild(i).gameObject.SetActive(false); } for (int i = 0; i < connectedDevices.Count; i++) { if (pairDeviceCount.GetChild(i) != null) { pairDeviceCount.GetChild(i).gameObject.SetActive(true); } else { break; } } } else { BhapticsLogger.LogDebug("button + ", " + defaultImage"); button.image.sprite = defaultImage; unPairButton.SetActive(false); var spriteState = button.spriteState; spriteState.highlightedSprite = defaultHoverImage; button.spriteState = spriteState; canPairImage.gameObject.SetActive(BhapticsAndroidManager.CanPairDevice(DeviceType)); for (int i = 0; i < pairDeviceCount.childCount; i++) { pairDeviceCount.GetChild(i).gameObject.SetActive(false); } } }
private void PlayHapticClip() { if (clip == null) { BhapticsLogger.LogInfo("clip is null"); return; } clip.Play(); }
public void ShowAlert() { if (alertGameObject == null) { BhapticsLogger.LogInfo("ShowAlert null object"); return; } alertGameObject.SetActive(true); }
public void PlayDelayed(float delaySecond = 0) { if (clip == null) { BhapticsLogger.LogInfo("clip is null."); return; } currentCoroutine = StartCoroutine(PlayCoroutine(delaySecond)); }
public static void Dispose() { if (Haptic != null) { Init = false; Haptic.TurnOff(); BhapticsLogger.LogInfo("Dispose() bHaptics plugin."); Haptic.Dispose(); Haptic = null; } }
public void Play(PositionTag posTag, float angleX, float offsetY) { var clip = GetClip(posTag); if (clip == null) { BhapticsLogger.LogInfo("Cannot find TactClip {0} {1} {2}", posTag, angleX, offsetY); return; } clip.Play(1f, 1f, angleX, offsetY * yOffsetMultiplier); }
public void PlayLoop() { if (clip == null) { BhapticsLogger.LogInfo("clip is null."); return; } isLooping = true; loopCoroutine = StartCoroutine(PlayLoopCoroutine()); }
void Start() { #if UNITY_ANDROID if (Application.platform != RuntimePlatform.Android) { // only for debugging BhapticsLogger.LogDebug("InvokeRefresh for debuggin usage."); InvokeRepeating("InvokeRefresh", 1f, 1f); } #endif }
void Start() { if (visualMotorsObject == null) { BhapticsLogger.LogError("BhapticsVisualFeedbackOnMotors.cs / visualMotorsObject is null"); return; } visualMotors = new GameObject[visualMotorsObject.transform.childCount]; for (int i = 0; i < visualMotorsObject.transform.childCount; ++i) { visualMotors[i] = visualMotorsObject.transform.GetChild(i).gameObject; } }
public void TurnOff() { if (androidJavaObject != null) { try { androidJavaObject.Call("turnOffAll"); } catch (Exception e) { BhapticsLogger.LogError("turnOffAll() : {0}", e.Message); } } }
private void TriggerPlay() { if (hapticEnable) { BhapticsLogger.LogInfo("TriggerPlay"); for (int i = 0; i < numOfTactClips; i++) { foreach (var clip in tactClips) { clip.keyId = System.Guid.NewGuid().ToString() + i; clip.Play(); } } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { BhapticsLogger.LogDebug("Import Assets"); HapticClipManager.RefreshTactFiles(); } foreach (string str in deletedAssets) { BhapticsLogger.LogDebug("Delete Assets"); if (Directory.GetFiles("Assets/", "*.tact", SearchOption.AllDirectories).Length != 0) { HapticClipManager.RefreshTactFiles(); } } }
public static void CallNativeVoidMethod(IntPtr androidObjPtr, IntPtr methodPtr, object[] param) { jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(param); try { AndroidJNI.CallVoidMethod(androidObjPtr, methodPtr, args); } catch (Exception e) { BhapticsLogger.LogError("CallNativeVoidMethod() : {0}", e.Message); } finally { AndroidJNIHelper.DeleteJNIArgArray(param, args); } }