BluetoothDispatcher.cs 679 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class BluetoothDispatcher : MonoBehaviour
  6. {
  7. public static System.Action<byte[]> aim;
  8. public static System.Action<byte[]> shoot;
  9. void Start()
  10. {
  11. BluetoothClient.onDataReceived = Dispatch;
  12. }
  13. void Dispatch(byte sign, byte[] data)
  14. {
  15. string logStr = sign + ", LEN " + data.Length;
  16. logStr += ", Bytes " + String.Join(",", data);
  17. Debug.Log(logStr);
  18. if (sign == 0 && aim != null)
  19. {
  20. aim(data);
  21. } else if (sign == 1 && shoot != null)
  22. {
  23. shoot(data);
  24. }
  25. }
  26. }