Пример #1
0
        // Handle press events
        private void pressedHandler(object sender, EventArgs e)
        {
            // get the gesture that was sent to us, which will tell us which object was pressed
            PressGesture gesture = sender as PressGesture;

            // get info about where the hit object was located when the gesture was recognized
            ITouchHit hit;

            if (gesture.GetTargetHitResult(out hit))
            {
                // want the info as a 2D point
                ITouchHit2D hit2d = (ITouchHit2D)hit;
                Debug.Log("PRESS on " + gesture.gameObject.name + " at " + hit2d.Point);
            }

            // play audio clip attached to object when pressed
            PlaySound(gesture.gameObject);

            // If the loaded scene is Spelling Game, re-enable collisions
            // when a letter is first pressed after resetting incorrect letters
            if (Application.loadedLevelName == "5. Spelling Game")
            {
                CollisionManager.EnableCollisions(gesture.gameObject, "TargetBlank");
            }

            // if the loaded scene is the sound game, re-enable collisions
            // when a sound blank is first pressed after resetting incorrect blanks
            if (Application.loadedLevelName == "6. Sound Game")
            {
                CollisionManager.EnableCollisions(gesture.gameObject, "TargetLetter");
            }
        }
Пример #2
0
        // Handle pan start events
        private void panStartedHandler(object sender, EventArgs e)
        {
            // get the gesture that was sent to us, which will tell us which object was pressed
            PanGesture gesture = sender as PanGesture;

            // get info about where the hit object was located when the gesture was recognized
            ITouchHit hit;

            if (gesture.GetTargetHitResult(out hit))
            {
                // want the info as a 2D point
                ITouchHit2D hit2d = (ITouchHit2D)hit;
                Debug.Log("PAN STARTED on " + gesture.gameObject.name + " at " + hit2d.Point);
            }
        }
Пример #3
0
        // Handle pan / drag events
        private void pannedHandler(object sender, EventArgs e)
        {
            // get the gesture that was sent to us, which will tell us which object was pressed
            PanGesture gesture = sender as PanGesture;

            // get info about where the hit object was located when the gesture was recognized
            ITouchHit hit;

            if (gesture.GetTargetHitResult(out hit))
            {
                // want the info as a 2D point
                ITouchHit2D hit2d = (ITouchHit2D)hit;
                Debug.Log("PAN on " + gesture.gameObject.name + " at " + hit2d.Point);

                // move the object with the drag
                gesture.gameObject.transform.position = new Vector3(hit2d.Point.x, hit2d.Point.y, -2);

                // TODO make sure the object being dragged can't fly off the screen
            }
        }
Пример #4
0
        // Handle all tap events. Trigger actions in response.
        private void tappedHandler(object sender, EventArgs e)
        {
            // get the gesture that was sent to us
            // this gesture will tell us what object was touched
            TapGesture gesture = sender as TapGesture;
            ITouchHit  hit;
            GameObject go = gesture.gameObject;

            // get info about where the hit object was located when the gesture was
            // recognized - i.e., where on the object (in screen dimensions) did
            // the tap occur?
            if (gesture.GetTargetHitResult(out hit))
            {
                // want the info as a 2D point
                ITouchHit2D hit2d = (ITouchHit2D)hit;
                Debug.Log("TAP on " + gesture.gameObject.name + " at " + hit2d.Point);
            }

            // if kid is tapped - stop pulsing kid, make kid bounce up and down, make kid speak
            if (go.tag == "Kid")
            {
                go.GetComponent <PulseBehavior>().StopPulsing(go);
                BounceKid(go);
                go.AddComponent <AudioSource>().clip = Resources.Load("Audio/KidSpeaking/Intro") as AudioClip;
                if (go.audio.clip != null)
                {
                    go.audio.Play();
                }

                // keep track of which kid was tapped on (boy or girl)
                ProgressManager.chosenKid = go.name;

                // go to next scene with the word tree
                StartCoroutine(LoadLevel("2. Word Tree", 2.5f));
            }

            // if a levelIcon is tapped on - make kid "shrink into" the levelIcon
            if (go.tag == "LevelIcon")
            {
                ShrinkKid(new Vector3(go.transform.position.x, go.transform.position.y, -2));

                // keep track of what level Icon was tapped: stores the name of the current level
                ProgressManager.currentLevel = go.name.Substring(0, go.name.Length - 1);

                // go to next scene
                StartCoroutine(LoadLevel("3. Choose Object", 1f));
            }

            // For each level (category of words, i.e. Animals or Transportation), there are three different modes (games for the user to play):
            // 1. Learn Spelling
            // 2. Spelling Game
            // 3. Sound Game
            // The name of each level icon has either the number 1, 2, or 3 appended to it. The number corresponds to the mode.
            // If level icon is tapped - keep track of what mode it is
            if (go.name.Substring(go.name.Length - 1).Equals("1"))
            {
                ProgressManager.currentMode = 1;
            }
            if (go.name.Substring(go.name.Length - 1).Equals("2"))
            {
                ProgressManager.currentMode = 2;
            }
            if (go.name.Substring(go.name.Length - 1).Equals("3"))
            {
                ProgressManager.currentMode = 3;
            }

            // if a word object is tapped on in the Choose Object scene, load the appropriate scene
            if (go.tag == "WordObject" && Application.loadedLevelName == "3. Choose Object")
            {
                // if the mode is 1, go to Learn Spelling scene
                if (ProgressManager.currentMode == 1)
                {
                    Application.LoadLevel("4. Learn Spelling");
                }
                // if the mode is 2, go to Spelling Game scene
                if (ProgressManager.currentMode == 2)
                {
                    Application.LoadLevel("5. Spelling Game");
                }
                // if the mode is 3, go to Sound Game scene
                if (ProgressManager.currentMode == 3)
                {
                    Application.LoadLevel("6. Sound Game");
                }
                // keep track of the name of the word object that was tapped on (the current word)
                ProgressManager.currentWord = gesture.gameObject.name;
            }

            // play word's sound when tapped
            if (go.tag == "WordObject" && Application.loadedLevelName != "3. Choose Object")
            {
                go.audio.Play();
            }

            // if home button is tapped, go back to the intro scene
            if (go.name == "HomeButton")
            {
                Application.LoadLevel("1. Intro");
            }

            // if tree button is tapped, shrink kid into tree icon and go back to Word Tree scene
            if (go.name == "TreeButton")
            {
                ShrinkKid(go.transform.position);

                StartCoroutine(LoadLevel("2. Word Tree", 1f));
            }

            // if back button is tapped, go to Choose Object scene
            if (go.name == "BackButton")
            {
                Application.LoadLevel("3. Choose Object");
            }

            // if sound button is tapped, play word's sound
            if (go.name == "SoundButton")
            {
                GameObject.FindGameObjectWithTag("WordObject").audio.Play();
            }

            // if hint button is tapped, show a hint
            if (go.name == "HintButton")
            {
                // if scene is Spelling Game, show a letter hint
                if (Application.loadedLevelName == "5. Spelling Game")
                {
                    CollisionManager.ShowLetterHint();
                }
                // if scene is Sound Game, show a sound hint
                if (Application.loadedLevelName == "6. Sound Game")
                {
                    CollisionManager.ShowSoundHint();
                }
            }

            // if the closed lock icon is tapped, unlock all levels of the word tree
            if (go.name == "LockClosed")
            {
                ProgressManager.UnlockAllLevels();
                ProgressManager.lockStatus = "LockOpen";                 // change status of lock to open

                // move closed lock icon to behind the background and disable touch gestures
                LeanTween.moveZ(go, 3f, .01f);
                go.GetComponent <GestureManager>().DisableGestures(go);

                // move open lock icon in front of background and subscribe to touch gestures
                GameObject lockOpen = GameObject.Find("LockOpen");
                LeanTween.moveZ(lockOpen, -2f, .01f);
                lockOpen.AddComponent <GestureManager>().AddAndSubscribeToGestures(lockOpen);
            }

            // if the open lock icon is tapped, remove all levels not yet completed from word tree
            if (go.name == "LockOpen")
            {
                ProgressManager.RelockLevels();
                ProgressManager.lockStatus = "LockClosed";                 // change status of lock to closed

                // move open lock icon to behind background and disable touch gestures
                LeanTween.moveZ(go, 3f, .01f);
                go.GetComponent <GestureManager>().DisableGestures(go);

                // move closed lock icon in front of background and subscribe to touch gestures
                GameObject lockClosed = GameObject.Find("LockClosed");
                LeanTween.moveZ(lockClosed, -2f, .01f);
                lockClosed.AddComponent <GestureManager>().AddAndSubscribeToGestures(lockClosed);
            }

            // if any button is tapped, darken the button briefly to indicate to user that
            // tap gesture has been registered
            if (go.tag == "Button")
            {
                LeanTween.color(go, Color.grey, .01f);
                LeanTween.color(go, Color.white, .01f).setDelay(.2f);
            }
        }