BluetoothDispatcher.cs 688 B

123456789101112131415161718192021222324252627282930
  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. }
  22. else if (sign == 1 && shoot != null)
  23. {
  24. shoot(data);
  25. }
  26. }
  27. }