Пример #1
0
        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.");
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
    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);
    }
Пример #4
0
    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
    }
Пример #5
0
        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.");
            }
        }
Пример #6
0
        void ReloadScene()
        {
            BhapticsLogger.LogInfo("Reloading scene.");
            int scene = SceneManager.GetActiveScene().buildIndex;

            SceneManager.LoadScene(scene, LoadSceneMode.Single);
            Time.timeScale = 1;
        }
    void Awake()
    {
        var col = GetComponent <Collider>();

        if (col == null)
        {
            BhapticsLogger.LogInfo("collider is not detected");
        }
    }
Пример #8
0
        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);
    }
Пример #10
0
        public void PlayDelayed(float delaySecond = 0)
        {
            if (clip == null)
            {
                BhapticsLogger.LogInfo("clip is null.");
                return;
            }

            currentCoroutine = StartCoroutine(PlayCoroutine(delaySecond));
        }
Пример #11
0
        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);
        }
Пример #12
0
 public static void Dispose()
 {
     if (Haptic != null)
     {
         Init = false;
         Haptic.TurnOff();
         BhapticsLogger.LogInfo("Dispose() bHaptics plugin.");
         Haptic.Dispose();
         Haptic = null;
     }
 }
Пример #13
0
        public void PlayLoop()
        {
            if (clip == null)
            {
                BhapticsLogger.LogInfo("clip is null.");
                return;
            }

            isLooping = true;

            loopCoroutine = StartCoroutine(PlayLoopCoroutine());
        }
Пример #14
0
 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();
             }
         }
     }
 }
Пример #15
0
        public void OnChange()
        {
            try
            {
                var androidHapticPlayer = BhapticsManager.GetHaptic() as AndroidHaptic;
                if (androidHapticPlayer == null)
                {
                    return;
                }

                androidHapticPlayer.CheckChange();
            }
            catch (Exception e)
            {
                BhapticsLogger.LogInfo("OnChange {0}", e.Message);
            }
        }
Пример #16
0
    public static IHaptic GetHaptic()
    {
        if (Haptic == null)
        {
            Init = true;
            if (Application.platform == RuntimePlatform.Android)
            {
                BhapticsLogger.LogInfo("Android initialized.");
                Haptic = new AndroidHaptic();
            }
            else
            {
                BhapticsLogger.LogInfo("Initialized.");
                Haptic = new BhapticsHaptic();
            }
        }

        return(Haptic);
    }
Пример #17
0
        protected void PlayUI()
        {
            GUILayout.BeginHorizontal();
            if (targetScript == null)
            {
                BhapticsLogger.LogInfo("hapticClip null");
                GUILayout.EndHorizontal();
                return;
            }

            if (GUILayout.Button("Play"))
            {
                targetScript.Play();
            }
            if (GUILayout.Button("Stop"))
            {
                targetScript.Stop();
            }
            GUILayout.EndHorizontal();
        }
Пример #18
0
        public static void LaunchPlayer(bool tryLaunch)
        {
            if (!tryLaunch)
            {
                return;
            }

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
            try
            {
                var myProcess = new System.Diagnostics.Process();
                myProcess.StartInfo.FileName = GetExePath();
                myProcess.Start();
            }
            catch (Exception e)
            {
                BhapticsLogger.LogInfo("LaunchPlayer() " + e.Message);
            }
#endif
        }
        public void OnChangeResponse(string message)
        {
            if (message == "")
            {
                return;
            }
            var response = PlayerResponse.ToObject(message);

            try
            {
                var androidHapticPlayer = BhapticsManager.GetHaptic() as AndroidHaptic;
                if (androidHapticPlayer == null)
                {
                    return;
                }
                androidHapticPlayer.Receive(response);
            }
            catch (Exception e)
            {
                BhapticsLogger.LogInfo("{0} {1}", message, e.Message);
            }
        }
        protected void PlayUi()
        {
            GUILayout.BeginHorizontal();
            var tactClip = serializedObject.targetObject as HapticClip;

            if (tactClip == null)
            {
                BhapticsLogger.LogInfo("tactClip null");
                GUILayout.EndHorizontal();
                return;
            }

            if (GUILayout.Button("Play"))
            {
                tactClip.Play();
            }
            if (GUILayout.Button("Stop"))
            {
                tactClip.Stop();
            }
            GUILayout.EndHorizontal();
        }