Exemplo n.º 1
0
 public CubeManager(ConnectType type = ConnectType.Auto)
 {
     this.scanner    = new CubeScanner(type);
     this.connecter  = new CubeConnecter(type);
     this.cubes      = new List <Cube>();
     this.handles    = new List <CubeHandle>();
     this.navigators = new List <CubeNavigator>();
     this.cubeTable  = new Dictionary <string, Cube>();
 }
Exemplo n.º 2
0
 // --- public methods ---
 public CubeManager(CubeScannerInterface scanner, CubeConnecterInterface connecter)
 {
     this.scanner    = scanner;
     this.connecter  = connecter;
     this.cubes      = new List <Cube>();
     this.handles    = new List <CubeHandle>();
     this.navigators = new List <CubeNavigator>();
     this.cubeTable  = new Dictionary <string, Cube>();
 }
Exemplo n.º 3
0
 public CubeConnecter(CubeConnecterInterface impl = null)
 {
     if (null != impl)
     {
         // CubeConnecterの内部実装を外部入力から変更
         this.impl = impl;
     }
     else
     {
         // プリセットで用意したマルチプラットフォーム内部実装(UnityEditor/Mobile/WebGL)
         this.impl = new Impl();
     }
 }
        public CubeConnecter(ConnectType type = ConnectType.Auto)
        {
            if (ConnectType.Auto == type)
            {
#if (UNITY_EDITOR || UNITY_STANDALONE)
                this.impl = new SimImpl();
#elif (UNITY_IOS || UNITY_ANDROID || UNITY_WEBGL)
                this.impl = new RealImpl();
#endif
            }
            else if (ConnectType.Simulator == type)
            {
                this.impl = new SimImpl();
            }
            else if (ConnectType.Real == type)
            {
                this.impl = new RealImpl();
            }
        }
        public virtual async UniTask <Cube> SingleConnect()
        {
            if (null == this.nearestScanner)
            {
                this.nearestScanner = new NearestScanner();
            }
            if (null == this.connecter)
            {
                this.connecter = new CubeConnecter();
            }
            var peripheral = await this.nearestScanner.Scan();

            if (null == peripheral)
            {
                return(null);
            }
            var cube = await this.connecter.Connect(peripheral);

            this.AddCube(cube);
            return(cube);
        }
        public virtual async UniTask <Cube[]> MultiConnect(int cubeNum)
        {
#if UNITY_WEBGL
            Debug.Log("[CubeManager.MultiConnect]MultiConnect doesn't run on the web");
#endif
            if (null == this.nearScanner)
            {
                this.nearScanner = new NearScanner(cubeNum);
            }
            if (null == this.connecter)
            {
                this.connecter = new CubeConnecter();
            }
            var peripheral = await this.nearScanner.Scan();

            var cubes = await this.connecter.Connect(peripheral);

            this.AddCube(cubes);

            return(cubes);
        }
        // --- private methods ---
        protected async void OnPeripheralScanned(BLEPeripheralInterface peripheral)
        {
            if (null == this.connecter)
            {
                this.connecter = new CubeConnecter();
            }
            if (this.cubeTable.ContainsKey(peripheral.device_address))
            {
                var cube = this.cubeTable[peripheral.device_address];
                await this.connecter.ReConnect(cube, peripheral);

                this.connectedAction(cube, new CONNECTION_STATUS(CONNECTION_STATUS.RE_CONNECTED));
            }
            else
            {
                var cube = await this.connecter.Connect(peripheral);

                this.AddCube(cube);
                if (null != this.connectedAction)
                {
                    this.connectedAction(cube, new CONNECTION_STATUS(CONNECTION_STATUS.NEW_CONNECTED));
                }
            }
        }
 public void SetCubeConnecter(CubeConnecterInterface _connecter)
 {
     this.connecter = _connecter;
 }