/* 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; } } }
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; } }
IEnumerator DelaySpheroConnection() { yield return(new WaitForSeconds(1.0f)); Sphero[] spheros = SpheroProvider.GetSharedProvider().GetConnectedSpheros(); spheros[0].SetRGBLED(1, 1, 1); }
// 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(); }
/* Use this for initialization */ void ViewSetup() { SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; #if UNITY_IPHONE // Connect first Sphero available on iOS SpheroProvider.GetSharedProvider().Connect(0); #endif }
// 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); }
/* Use this for initialization */ void ViewSetup() { // Get Connected Sphero SpheroDeviceMessenger.SharedInstance.NotificationReceived += ReceiveNotificationMessage; if (SpheroProvider.GetSharedProvider().GetConnectedSpheros().Length == 0) { Application.LoadLevel("SpheroConnectionScene"); } }
/* 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 }
/* * 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"); } }
/* 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 }
/* 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(); } }
/* 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(); } }
/* 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; }
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; } } } }
/* 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); } }
/* * 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"); } }
/* 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); }
/* 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 }
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 }
// 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; } }
/* * 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; } } }