User Tools

Site Tools


tutorials:net_unity:unity_mini_tutorial_switching_scenes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
tutorials:net_unity:unity_mini_tutorial_switching_scenes [2015/09/10 13:27]
glass [Continuing Education]
tutorials:net_unity:unity_mini_tutorial_switching_scenes [2019/01/21 19:24] (current)
Line 1: Line 1:
 +[[tutorials/​net_unity|{{ :​unity_3d_logo.png }}]]
  
 +====== Unity Mini Tutorial: Switching Scenes ======
 +
 +===== Introduction =====
 +
 +Switching scenes is a common method to load a new level in a game or go to a different activity area. In order to do this properly with Unity and GestureWorks together, gestures need to be unloaded and reset to avoid problems. This tutorial discusses the proper way to switch scenes using GestureWorks Unity.
 +
 +For this tutorial you will need the [[http://​gestureworks.com/​coreGestureworks Core]] multitouch framework; a [[http://​files.gestureworks.com/​downloads/​Core/​Trial/​GestureworksCoreTrialSetup.exe|free trial]] is available.
 +
 +Download the code for all of the C# & Unity multitouch tutorials here: [[https://​github.com/​ideum/​gestureworks-unity/​|gestureworks-unity on GitHub]].
 +
 +----
 +
 +===== Requirements =====
 +
 +Estimated time to complete: **10 minutes**
 +
 +This tutorial assumes a basic understanding of GestureWorks setup in Unity as described in the HelloMultitouch tutorials and the Interactive Bitmap tutorial. The project <​html><​font face="​Courier New">​MiniTutorial_ChangingScenes</​font></​html>​ is also required.
 +
 +----
 +
 +===== Process Overview =====
 +
 +  - [[tutorials:​net_unity:​unity_mini_tutorial_switching_scenes#​example_of_changing_scenes|Example of changing scenes]]
 +  - [[tutorials:​net_unity:​unity_mini_tutorial_switching_scenes#​discussion_of_changing_scenes|Discussion of changing scenes]]
 +
 +----
 +
 +===== Process Detail =====
 +
 +==== 1. Example of changing scenes ====
 +
 +Copy your GestureWorks dlls to the <​html><​font face="​Courier New">​Assets/​GestureWorks/​Core</​font></​html>​ directory of MiniTutorial_ChangingScenes (more discussion of the process is in a previous tutorial.)
 +
 +The project contains two scene files, <​html><​font face="​Courier New">​MyScene.unity</​font></​html>​ and <​html><​font face="​Courier New">​MySceneB.unity</​font></​html>​. Open <​html><​font face="​Courier New">​MyScene.unity</​font></​html>​ and built and run. There will be two sprites with a button displayed:
 +
 +{{ :​tutorials:​net_unity:​777px-unity_mini_scenes.1_a.png?​direct |}}
 +
 +Tapping the button will switch scenes. This is shown by the bitmap objects being tinted red in the other scene:
 +
 +{{ :​tutorials:​net_unity:​777px-unity_mini_scenes.1_b.png?​direct |}}
 +
 +The button code that switches the scene is in Scripts/​SwitchScenes.cs and is as follows:
 +
 +<​code:​xml linenums:1 |Switching Screens // SwitchScenes.cs //>
 +using UnityEngine;​
 +using System.Collections;​
 +using GestureWorksCoreNET;​
 +using GestureWorksCoreNET.Unity;​
 +
 +public class SwitchScenes : TouchObject {
 +        ​
 +    public GestureWorksScript gestureWorks;​
 +        ​
 +    private bool switchedScenes = false;
 +        ​
 +    public void Tap(GestureEvent gEvent)
 +    {               
 +        Switch();
 +    }
 +                ​
 +    private void Switch()
 +    {
 +        if(switchedScenes || gestureWorks == null)
 +        {
 +            return; ​
 +        }
 +                ​
 +        switchedScenes = true;
 +                ​
 +        gestureWorks.SwitchScenes("​MySceneB"​);​
 +    }
 +}
 +</​code>​
 +
 +The object responds to touch or drag objects by calling the Switch method. The button object contains a reference to the scene’s GestureWorks GameObject and calls the SwitchScenes method on it to change scenes. This is different than the standard Unity way of switching scene files by calling:
 +
 +<​code:​xml linenums:1 |Standard Unity way of switching scene files //  //>
 +Application.loadedLevel(“sceneName”);​
 +</​code>​
 +
 +==== 2. Discussion of changing scenes ====
 +
 +
 +Changing scenes with GestureWorks should always be done through the SwitchScene methods in the GestureWorks GameObject. The process for switching scenes involves many steps of waiting for existing gestures to process and clearing out gestures and touch events. Calling SwitchScene handles all of these steps, not calling it and using Unity’s Application.LoadLevel directly may cause a crash (and maybe not on every game run but occasionally.) If more fine control of switching scenes is required the Coroutine UnloadScene,​ which SwitchScenes calls, in the GestureWorksScript can be used directly.
 +
 +----
 +
 +
 +===== Continuing Education =====
 +
 +It is the intention of this and the other GestureWorks Core tutorials to get the programmer started using the GestureWorks core framework, and is by no means an exhaustive explanation of all of the features of Gestureworks Core; in fact, we’ve only barely scratched the surface!
 +
 +Additional tutorials for learning more about GestureWorks Unity:
 +
 +  * [[tutorials:​net_unity:​unity_mini_tutorial_movement_related_to_camera|Unity Mini Tutorial: Movement Related to Camera]]
 +  * [[tutorials:​net_unity:​unity_mini_tutorial_registering_touch_objects|Unity Mini Tutorial: Registering Touch Objects]]
 +
 +There is also FAQ here:
 +
 +  * [[tutorials:​net_unity:​gestureworks_faq|Unity GestureWorks FAQ]]
 +
 +For more information on GestureWorks Core, GestureML, and CreativeML, please visit the following sites:
 +
 +  * [[http://​wiki.gestureworks.com]]
 +  * [[http://​gestureml.org]]
 +  * [[http://​creativeml.org]]