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

            SceneManager.LoadScene(scene, LoadSceneMode.Single);
            Time.timeScale = 1;
        }
Пример #15
0
 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");
        }
    }
Пример #17
0
        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);
                }
            }
        }
Пример #19
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);
    }
Пример #21
0
        public void PlayDelayed(float delaySecond = 0)
        {
            if (clip == null)
            {
                BhapticsLogger.LogInfo("clip is null.");
                return;
            }

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

            isLooping = true;

            loopCoroutine = StartCoroutine(PlayLoopCoroutine());
        }
Пример #25
0
        void Start()
        {
#if UNITY_ANDROID
            if (Application.platform != RuntimePlatform.Android)
            {
                // only for debugging
                BhapticsLogger.LogDebug("InvokeRefresh for debuggin usage.");

                InvokeRepeating("InvokeRefresh", 1f, 1f);
            }
#endif
        }
Пример #26
0
 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;
     }
 }
Пример #27
0
 public void TurnOff()
 {
     if (androidJavaObject != null)
     {
         try
         {
             androidJavaObject.Call("turnOffAll");
         }
         catch (Exception e)
         {
             BhapticsLogger.LogError("turnOffAll() : {0}", e.Message);
         }
     }
 }
Пример #28
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();
             }
         }
     }
 }
Пример #29
0
 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();
         }
     }
 }
Пример #30
0
 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);
     }
 }