Exemplo n.º 1
0
    /* Use this for initialization */
    void ViewSetup()
    {
#if UNITY_EDITOR
        if (!m_ignoreConnectionSceneInEditor)
#endif
        {
            // Get Connected Sphero
            Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();
            if (spheros.Length == 0)
            {
                Application.LoadLevel("SpheroConnectionScene");
                return;
            }
            else
            {
                spheros[0].SetRGBLED(1, 1, 1);
                spheros[0].Roll(0, 0f);
                //spheros[0].SetHeading(0);
            }
        }

        if (!ARUNBridge._ARUNBridgeStartVisionEngine())
        {
            Debug.LogError("Vision Failed to Start :(");
        }
    }
    /*
     * Called if the OS is Android to show the Connection Scene
     */
    void SetupAndroid()
    {
        // initialize the Sphero Provider (Cannot call in the initialization of member variables or you will get a crash!)
        m_SpheroProvider = SpheroProvider.GetSharedProvider();

        // Search for paired robots
        if (!m_SpheroProvider.IsAdapterEnabled())
        {
            m_Title      = "BLUETOOTH NOT ENABLED";
            m_RobotNames = new string[0];
        }
        else
        {
            m_Title = "CONNECT TO A SPHERO";
            // Refreshes the list of robots
            m_SpheroProvider.FindRobots();

            // Initialize the device messenger which sets up the callback
            SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage;

            // Make the spinner smaller to appear next to the clickable list
            if (m_MultipleSpheros)
            {
                m_SpinnerSize = new Vector2(m_SpheroLabelHeight - 10, m_SpheroLabelHeight - 10);
            }
            m_RobotNames = m_SpheroProvider.GetRobotNames();
            // Sphero Provider will try and connect to the first robot, so show that progress
            if (m_RobotNames.Length == 1)
            {
                m_SpheroProvider.PairedSpheros[0].ConnectionState = Sphero.Connection_State.Connecting;
                m_SpheroLabelSelected = 0;
                m_ConnectingRobotName = m_SpheroProvider.PairedSpheros[0].DeviceInfo.Name;
            }
        }
    }
Exemplo n.º 3
0
 void OnApplicationPause(bool pause)
 {
     if (pause)
     {
         // Unregister event handlers when the applications pauses.
         if (streaming)
         {
             // removes data streaming event handler
             SpheroDeviceMessenger.SharedInstance.AsyncDataReceived -=
                 ReceiveAsyncMessage;
             // Turns off controller mode data streaming. Stabilization is restored and the back LED is turn off.
             m_Sphero.DisableControllerStreaming();
             streaming = false;
         }
         // Stop listening for disconnnect notifications.
         SpheroDeviceMessenger.SharedInstance.NotificationReceived -=
             ReceiveNotificationMessage;
         // Disconnect from the Sphero
         SpheroProvider.GetSharedProvider().DisconnectSpheros();
     }
     else
     {
         ViewSetup();
         streaming = false;
     }
 }
Exemplo n.º 4
0
    IEnumerator DelaySpheroConnection()
    {
        yield return(new WaitForSeconds(1.0f));

        Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();
        spheros[0].SetRGBLED(1, 1, 1);
    }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        m_Spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();

        startScreenSize      = new Vector2(Camera.main.pixelRect.width, Camera.main.pixelRect.height);
        originalTransformPos = transform.position;
        SetJoystickSize();
    }
Exemplo n.º 6
0
 /* Use this for initialization */
 void ViewSetup()
 {
     SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage;
             #if UNITY_IPHONE
     // Connect first Sphero available on iOS
     SpheroProvider.GetSharedProvider().Connect(0);
             #endif
 }
Exemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        m_Spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();

        startScreenSize      = new Vector2(Screen.width, Screen.height);
        originalTransformPos = transform.position;
        SetCalibrateButtonSize();
    }
 /*
  * Called if the OS is iOS to immediately try to connect to the robot
  */
 void SetupIOS()
 {
     m_MultipleSpheros = false;
     // Initialize the device messenger which sets up the callback
     SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage;
     SpheroProvider.GetSharedProvider().Connect(0);
     Invoke("CheckForSpheroConnection", 1.5f);
 }
Exemplo n.º 9
0
 /* Use this for initialization */
 void ViewSetup()
 {
     // Get Connected Sphero
     SpheroDeviceMessenger.SharedInstance.NotificationReceived +=
         ReceiveNotificationMessage;
     if (SpheroProvider.GetSharedProvider().GetConnectedSpheros().Length == 0)
     {
         Application.LoadLevel("SpheroConnectionScene");
     }
 }
Exemplo n.º 10
0
	/* Use this to initialize the view */
	private void ViewSetup() {
		m_SpheroProvider = SpheroProvider.GetSharedProvider();
		#if UNITY_ANDROID
			SetupAndroid();
		#elif UNITY_IPHONE
			SetupIOS();
		#else
			// Display that it doesn't work with these platforms?
		#endif
	}
Exemplo n.º 11
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID);

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
            Application.LoadLevel("NoSpheroConnectedScene");
        }
    }
Exemplo n.º 12
0
 /* Use this to initialize the view */
 private void ViewSetup()
 {
     m_SpheroProvider = SpheroProvider.GetSharedProvider();
             #if UNITY_ANDROID
     SetupAndroid();
             #elif UNITY_IPHONE
     SetupIOS();
             #else
     // Display that it doesn't work with these platforms?
             #endif
 }
Exemplo n.º 13
0
 /* This is called when the application returns from or enters background */
 void OnApplicationPause(bool pause)
 {
     if (pause)
     {
         SpheroProvider.GetSharedProvider().DisconnectSpheros();
         // Initialize the device messenger which sets up the callback
         SpheroDeviceMessenger.SharedInstance.NotificationReceived -= ReceiveNotificationMessage;
     }
     else
     {
         ViewSetup();
     }
 }
Exemplo n.º 14
0
 /* This is called when the application returns from background or entered from NoSpheroConnectionScene */
 void OnApplicationPause(bool pause)
 {
     if (pause)
     {
         // Initialize the device messenger which sets up the callback
         SpheroProvider.GetSharedProvider().DisconnectSpheros();
         ARUNBridge._ARUNBridgeQuitVisionEngine();
     }
     else
     {
         ViewSetup();
     }
 }
Exemplo n.º 15
0
	/* Get the shared RobotProvider instance */
	public static SpheroProvider GetSharedProvider() {
		if( sharedProvider == null ) {
			#if UNITY_EDITOR
				sharedProvider = new SpheroProviderEditor();
				sharedProvider.m_PairedSpheros = new Sphero[0];
			#elif UNITY_ANDROID			
				sharedProvider = new SpheroProviderAndroid();
			#elif UNITY_IPHONE
				sharedProvider = new SpheroProviderIOS();
			#endif			
		}
		return sharedProvider;
	}
Exemplo n.º 16
0
    void touchManager()
    {
        if (Input.GetMouseButtonUp(0))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hitInfo))
            {
                string objectHitName = hitInfo.transform.gameObject.name;
                switch (objectHitName)
                {
                case "btnInfo":
                    switch (currentPage)
                    {
                    case Page.PLAY:
                        InfoGame();
                        break;

                    case Page.INFO:
                        UnInfoGame();
                        break;

                    default:
                        currentPage = Page.PLAY;
                        break;
                    }
                    break;

                case "btnRank":
                    UnInfoGame();
                    SceneManager.LoadScene("Settings-c#");
                    break;

                case "retryButtonPause":
                    UnInfoGame();
                    SceneManager.LoadScene("Menu-c#");
                    break;

                case "menuButtonPause":
                    UnInfoGame();
                    SceneManager.LoadScene("Menu-c#");
                    break;

                case "btnExit":
                    UnInfoGame();
                    Application.Quit();
                    SpheroProvider.GetSharedProvider().DisconnectSpheros();
                    break;
                }
            }
        }
    }
Exemplo n.º 17
0
 /* Use this for initialization */
 void ViewSetup()
 {
     // Get Connected Spheros
     m_Spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();
     SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage;
     if (m_Spheros.Length == 0)
     {
         Application.LoadLevel("SpheroConnectionScene");
     }
     foreach (Sphero sphero in m_Spheros)
     {
         sphero.SetRGBLED(BLUE.r, BLUE.g, BLUE.b);
     }
 }
Exemplo n.º 18
0
    /*
     * Callback to receive connection notifications
     */
    private void ReceiveNotificationMessage(object sender, SpheroDeviceMessenger.MessengerEventArgs eventArgs)
    {
        // Event handler that listens for disconnects. An example of when one would be received is when Sphero
        // goes to sleep.
        SpheroDeviceNotification message = (SpheroDeviceNotification)eventArgs.Message;
        Sphero notifiedSphero            = SpheroProvider.GetSharedProvider().GetSphero(message.RobotID);

        if (message.NotificationType == SpheroDeviceNotification.SpheroNotificationType.DISCONNECTED)
        {
            notifiedSphero.ConnectionState = Sphero.Connection_State.Disconnected;
            streaming = false;
            Application.LoadLevel("NoSpheroConnectedScene");
        }
    }
Exemplo n.º 19
0
 /* Get the shared RobotProvider instance */
 public static SpheroProvider GetSharedProvider()
 {
     if (sharedProvider == null)
     {
                     #if UNITY_EDITOR
         sharedProvider = new SpheroProviderEditor();
         sharedProvider.m_PairedSpheros = new Sphero[0];
                     #elif UNITY_ANDROID
         sharedProvider = new SpheroProviderAndroid();
                     #elif UNITY_IPHONE
         sharedProvider = new SpheroProviderIOS();
                     #endif
     }
     return(sharedProvider);
 }
Exemplo n.º 20
0
    /* This is called when the application returns from background or entered from NoSpheroConnectionScene */
    void OnApplicationPause(bool pause)
    {
#if !UNITY_EDITOR
        if (pause)
        {
            ARUNBridge._ARUNBridgePauseVisionEngine();
        }
        else
        {
            ARUNBridge._ARUNBridgeStartVisionEngine();
            SpheroProvider.GetSharedProvider().Connect(0);
            StartCoroutine(DelaySpheroConnection());
        }
#endif
    }
Exemplo n.º 21
0
    void Start()
    {
        ARUNController controller = ARUNController.Instance;

        if (controller != null)
        {
            controller.OnVisionUpdate += OnVisionUpdate;
        }
        else
        {
            //Debug.LogWarning("AureController.Instance not set");
        }
#if !UNITY_EDITOR
        // Get first connected Sphero
        Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros();
        if (spheros.Length > 0)
        {
            sphero = spheros[0];
            sphero.AddDataStreamingMask((ulong)kVisionMask);
            SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage;
        }
#endif
    }
Exemplo n.º 22
0
    // Update is called once per frame
    void Update()
    {
        if (!streaming &&
            SpheroProvider.GetSharedProvider().GetConnectedSpheros().Length > 0)
        {
            // Setup streaming for the first time once a Sphero is connected.
            //// Register the event handler call back with the SpheroDeviceMessenger
            SpheroDeviceMessenger.SharedInstance.AsyncDataReceived += ReceiveAsyncMessage;
            //// Get the currently connected Sphero
            Sphero[] spheros =
                SpheroProvider.GetSharedProvider().GetConnectedSpheros();
            m_Sphero = spheros[0];
            //// Enable data streaming for controller app. This method turns off stabilization (disables the wheel motors),
            //// turn on the back LED (negative x axis reference), and sets data streaming at 20 samples/sec (400/20),
            //// a single sample per packet sent, and turns on accelerometer, quaternion, and IMU (attitude) sampling.
            m_Sphero.EnableControllerStreaming(20, 1,
                                               SpheroDataStreamingMask.AccelerometerFilteredAll |
                                               SpheroDataStreamingMask.QuaternionAll |
                                               SpheroDataStreamingMask.IMUAnglesFilteredAll);

            streaming = true;
        }
    }
Exemplo n.º 23
0
	/*
	 * Called if the OS is Android to show the Connection Scene
	 */
	void SetupAndroid() {
		
		// initialize the Sphero Provider (Cannot call in the initialization of member variables or you will get a crash!)
		m_SpheroProvider = SpheroProvider.GetSharedProvider();
		
		// Search for paired robots
		if( !m_SpheroProvider.IsAdapterEnabled() ) {
			m_Title = "Bluetooth Not Enabled";
			m_RobotNames = new string[0];
		}
		else {
			m_Title = "Connect to a Sphero";
			// Refreshes the list of robots
			m_SpheroProvider.FindRobots();
			
			// Initialize the device messenger which sets up the callback
			SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage;
	
			// Make the spinner smaller to appear next to the clickable list
			if( m_MultipleSpheros ) {
				m_SpinnerSize = new Vector2(m_SpheroLabelHeight-10, m_SpheroLabelHeight-10);	
			}	
			m_RobotNames = m_SpheroProvider.GetRobotNames();
			// Sphero Provider will try and connect to the first robot, so show that progress
			if( m_RobotNames.Length == 1 ) {
				m_SpheroProvider.PairedSpheros[0].ConnectionState = Sphero.Connection_State.Connecting;
				m_SpheroLabelSelected = 0;
				m_ConnectingRobotName = m_SpheroProvider.PairedSpheros[0].DeviceInfo.Name;
			}
		}
	}