//<summary>
        //called on start, initialize stuff
        //</summary>
        void Start()
        {
            //Scale graphics to screen size
            Utilities.setCameraViewForScreen();
            //create instance of grestureManager
            GestureManager gestureManager = GameObject.FindGameObjectWithTag
                                                (Constants.Tags.TAG_GESTURE_MANAGER).GetComponent <GestureManager>();

            if (gestureManager != null)
            {
                // create two sets of words - movable and target
                LoadSpellingLesson(ProgressManager.currentWord);
                // subscribe buttons to gestures
                GameObject[] buttons = GameObject.FindGameObjectsWithTag(Constants.Tags.TAG_BUTTON);
                foreach (GameObject button in buttons)
                {
                    gestureManager.AddAndSubscribeToGestures(button);
                }
                // play word's sound
                //find the word
                GameObject word = GameObject.FindGameObjectWithTag(Constants.Tags.TAG_WORD_OBJECT);
                if (word != null)
                {
                    //create new audio source for the sound
                    AudioSource audioSource = gameObject.AddComponent <AudioSource>();
                    //load the audio file with word's name in it
                    string file = "Audio" + "/Words/" + word.transform.name;
                    audioSource.clip = Resources.Load(file) as AudioClip;
                    if (audioSource.clip != null)
                    {
                        audioSource.Play();
                    }
                    else
                    {
                        Debug.LogWarning("Cannot find audio file");
                    }
                    StartCoroutine(StartPulsing(.5f));
                    // then explode the letters
                    StartCoroutine(ExplodeWord(1));
                    // then enable collisions to occur
                    StartCoroutine(EnableCollisions(2));
                    //Possible regions where letters can move
                    //TODO make sure these locations are on the screen
                    points.Add(new Vector3(-5.5f, 3.5f, 0f));
                    points.Add(new Vector3(-6f, -3.9f, 0f));
                    points.Add(new Vector3(-6f, 0f, 0f));
                    points.Add(new Vector3(4f, 3f, 0f));
                    points.Add(new Vector3(6f, 0f, 0f));
                }
                else
                {
                    Debug.LogWarning("Cannot find word");
                }
            }
            else
            {
                Debug.LogError("Cannot find gesture manager");
            }
        }
Exemple #2
0
        //<summary>
        // Called on start, used to initialize stuff
        //</summary>
        void Start()
        {
            //Scale graphics to screen size
            Utilities.setCameraViewForScreen();
            //create instance of grestureManager
            GestureManager gestureManager = GameObject.FindGameObjectWithTag
                                                (Constants.Tags.TAG_GESTURE_MANAGER).GetComponent <GestureManager>();

            if (gestureManager != null)
            {
                GameObject dir = GameObject.Find("IntroDirector");
                // load Background music onto IntroDirector
                dir.AddComponent <AudioSource>().clip = Resources.Load
                                                            ("Audio/BackgroundMusic/WordTree") as AudioClip;
                // play background music if attached
                if (dir.GetComponent <AudioSource>().clip != null)
                {
                    dir.GetComponent <AudioSource>().Play();
                }
                //For keeping background music playing in a loop
                dir.GetComponent <AudioSource>().loop = true;
                // find kid
                GameObject[] kids = GameObject.FindGameObjectsWithTag(Constants.Tags.TAG_KID);
                foreach (GameObject kid in kids)
                {
                    // start pulsing kid
                    kid.AddComponent <PulseBehavior>().StartPulsing(kid);
                    // subscribe kid to touch gestures
                    gestureManager.AddAndSubscribeToGestures(kid);
                }
                ProgressManager.lockStatus = "";
            }
            else
            {
                Debug.LogError("Cannot find gesture manager");
            }
        }
        // instantiate new game object with specified properties
        public static void InstantiateObject(ObjectProperties prop)
        {
            // create new game object
            GameObject go = new GameObject();

            // set name
            go.name = prop.Name();

            Debug.Log("Created new object " + go.name);

            // set tag
            go.tag = prop.Tag();

            // set initial position
            go.transform.position = prop.InitPosn();

            // set scale of sprite image
            go.transform.localScale = prop.Scale();

            // load sprite image
            SpriteRenderer spriteRenderer = go.AddComponent <SpriteRenderer>();
            // image file needs to be in an existing Assets/Resources folder or subfolder
            Sprite sprite = Resources.Load <Sprite>("Graphics/" + prop.Sprite());

            if (sprite == null)
            {
                Debug.Log("ERROR: could not load sprite " + prop.Name());
            }
            spriteRenderer.sprite = sprite;

            // load audio clip
            if (prop.AudioFile() != null)
            {
                AudioSource audioSource = go.AddComponent <AudioSource>();
                // audio file needs to be in an existing Assets/Resources folder or subfolder
                AudioClip clip = Resources.Load("Audio/" + prop.AudioFile()) as AudioClip;
                if (clip == null)
                {
                    Debug.Log("ERROR: could not load audioclip " + prop.AudioFile());
                }
                audioSource.clip        = clip;
                audioSource.playOnAwake = false;
            }

            if (go.tag != "TargetLetter" && go.tag != "TargetBlank" && go.tag != "Jar")
            {
                // add polygon collider that matches shape of object
                // used to detect touches and collisions
                go.AddComponent <PolygonCollider2D> ();
            }

            if (go.tag == "TargetLetter" || go.tag == "TargetBlank")
            {
                // add circle collider
                // used to detect touches and collisions
                CircleCollider2D cc2d = go.AddComponent <CircleCollider2D>();

                // set as trigger so OnTriggerEnter2D function is called when collider is hit
                cc2d.isTrigger = true;

                // set radius for circle collider
                // want radius to be small, to make it easier for users to drag letters or sound blanks to where they want
                // without accidentally colliding with another object
                if (go.tag == "TargetLetter")
                {
                    if (ProgressManager.currentMode == 1)
                    {
                        cc2d.radius = .1f;
                    }
                    if (ProgressManager.currentMode == 3)
                    {
                        cc2d.radius = 3f;
                    }
                }
                if (go.tag == "TargetBlank")
                {
                    cc2d.radius = .3f;
                }
            }

            if (go.tag == "Jar")
            {
                // add circle collider
                // used to detect collisions
                CircleCollider2D cc2d = go.AddComponent <CircleCollider2D> ();

                // set radius for circle collider
                // want to set radius exactly so that it extends to the rim/opening of the jar
                // so collisions will be detected when the user dragging a sound blank hits the rim
                cc2d.radius = .5f;
            }

            if (go.tag == "MovableLetter" || go.tag == "MovableBlank")
            {
                // add rigidbody if object is draggable
                Rigidbody2D rb2d = go.AddComponent <Rigidbody2D>();

                // remove object from physics engine's control, because we don't want
                // the object to move with gravity, forces, etc. - we do the moving
                rb2d.isKinematic = true;

                // don't want gravity, otherwise object will fall
                rb2d.gravityScale = 0;
            }

            // subscribe to gestures
            GestureManager gm = go.AddComponent <GestureManager> ();

            gm.AddAndSubscribeToGestures(go);

            // add pulse behavior - draws attention to interactive objects
            go.AddComponent <PulseBehavior> ();


            if (go.tag == "Hint")
            {
                // set hint letter color to black
                go.GetComponent <SpriteRenderer>().color = Color.black;

                // create hint letter behind the background
                go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, 3);
            }
        }