//<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)
            {
                //Create objects and background
                LoadLevel(ProgressManager.currentLevel);
                //Set up kid
                GameObject kid = GameObject.FindGameObjectWithTag(Constants.Tags.TAG_KID);
                //check if kid is attached
                if (kid != null)
                {
                    kid.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("Graphics/"
                                                                                         + ProgressManager.chosenKid);
                }
                else
                {
                    Debug.LogWarning("Cannot find kid in scene");
                }
                //check if sprite is attached
                if (kid.GetComponent <SpriteRenderer>().sprite != null)
                {
                    //Play Grow Animation for kid
                    GrowKid();
                    //Load audio for kid
                    kid.AddComponent <AudioSource>().clip = Resources.Load("Audio/KidSpeaking/"
                                                                           + ProgressManager.currentLevel) as AudioClip;
                    //Check if audio clip is attached
                    if (kid.GetComponent <AudioSource>().clip != null)
                    {
                        kid.GetComponent <AudioSource>().priority = 0;
                        kid.GetComponent <AudioSource>().volume   = 1.0f;
                        //Play audio clip attached to kid if there is one
                        kid.GetComponent <AudioSource>().Play();
                    }
                    else
                    {
                        Debug.LogWarning("No audio found");
                    }
                }
                else
                {
                    Debug.LogWarning("Cannot load sprite");
                }
                //Find ChooseObjectDirector gameObject
                GameObject dir = GameObject.Find("ChooseObjectDirector");
                if (dir != null)
                {
                    //Load background music for scene onto ChooseObjectDirector
                    dir.AddComponent <AudioSource>().clip = Resources.Load("Audio/BackgroundMusic/"
                                                                           + ProgressManager.currentLevel) as AudioClip;
                    //Check if audio clip is attached
                    if (dir.GetComponent <AudioSource>().clip != null)
                    {
                        dir.GetComponent <AudioSource>().priority = 0;
                        dir.GetComponent <AudioSource>().volume   = .25f;
                        //Start playing background music if attached
                        dir.GetComponent <AudioSource>().Play();
                    }
                    else
                    {
                        Debug.LogWarning("No audio file found");
                    }
                }
                else
                {
                    Debug.LogWarning("Cannot find ChooseObjectDirector");
                }
                //Subscribe buttons to touch gestures
                GameObject button = GameObject.FindGameObjectWithTag(Constants.Tags.TAG_BUTTON);
                if (button != null)
                {
                    button.AddComponent <GestureManager>().AddAndSubscribeToGestures(button);
                }
                else
                {
                    Debug.LogWarning("Cannot find button");
                }
                //Find word objects
                GameObject[] gos = GameObject.FindGameObjectsWithTag(Constants.Tags.TAG_WORD_OBJECT);
                foreach (GameObject go in gos)
                {
                    //Start pulsing for each object
                    Debug.Log("Started pulsing for " + go.name);
                    go.GetComponent <PulseBehavior>().StartPulsing(go);
                    //Check if word has been completed by user
                    //If word not completed, darken and fade out object
                    if (!ProgressManager.IsWordCompleted(go.name))
                    {
                        SetColorAndTransparency(go, Color.grey, .9f);
                    }
                    //If word completed, brighten and fill in object
                    else
                    {
                        Debug.Log("Word Completed: " + go.name);
                        SetColorAndTransparency(go, Color.white, 1f);
                    }
                }
                //Check if this level has been completed, i.e. if all words in the level have been completed
                if (CheckCompletedLevel())
                {
                    //If level completed, add to completedLevels list and unlock the next level
                    ProgressManager.AddCompletedLevel(ProgressManager.currentLevel);
                    ProgressManager.UnlockNextLevel(ProgressManager.currentLevel);
                }
            }
            else
            {
                Debug.LogError("Cannot find gesture manager component");
            }
        }
Пример #2
0
        //Called on start, used to initialize stuff
        void Start()
        {
            //Create objects and background
            LoadLevel(ProgressManager.currentLevel);

            //Set up kid
            GameObject kid = GameObject.FindGameObjectWithTag("Kid");

            kid.GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> ("Graphics/" + ProgressManager.chosenKid);

            //Play Grow Animation for kid
            GrowKid();

            //Load audio for kid
            kid.AddComponent <AudioSource> ().clip = Resources.Load("Audio/KidSpeaking/" + ProgressManager.currentLevel) as AudioClip;
            //Check if audio clip is attached
            if (kid.audio.clip != null)
            {
                kid.audio.priority = 255;
                //Play audio clip attached to kid if there is one
                kid.audio.Play();
            }

            //Find ChooseObjectDirector gameObject
            GameObject dir = GameObject.Find("ChooseObjectDirector");

            //Load background music for scene onto ChooseObjectDirector
            dir.AddComponent <AudioSource> ().clip = Resources.Load("Audio/BackgroundMusic/" + ProgressManager.currentLevel) as AudioClip;
            //Check if audio clip is attached
            if (dir.audio.clip != null)
            {
                dir.audio.volume = .7f;
                //Start playing background music if attached
                dir.audio.Play();
            }

            //Subscribe buttons to touch gestures
            GameObject button = GameObject.FindGameObjectWithTag("Button");

            button.AddComponent <GestureManager> ().AddAndSubscribeToGestures(button);

            //Find word objects
            GameObject[] gos = GameObject.FindGameObjectsWithTag("WordObject");
            foreach (GameObject go in gos)
            {
                //Start pulsing for each object
                Debug.Log("Started pulsing for " + go.name);
                go.GetComponent <PulseBehavior> ().StartPulsing(go);

                //Check if word has been completed by user

                //If word not completed, darken and fade out object
                if (!ProgressManager.IsWordCompleted(go.name))
                {
                    SetColorAndTransparency(go, Color.grey, .9f);
                }
                //If word completed, brighten and fill in object
                if (ProgressManager.IsWordCompleted(go.name))
                {
                    Debug.Log("Word Completed: " + go.name);
                    SetColorAndTransparency(go, Color.white, 1f);
                }
            }

            //Check if this level has been completed, i.e. if all words in the level have been completed
            if (CheckCompletedLevel())
            {
                //If level completed, add to completedLevels list and unlock the next level
                ProgressManager.AddCompletedLevel(ProgressManager.currentLevel);
                ProgressManager.UnlockNextLevel(ProgressManager.currentLevel);
            }
        }