Esempio n. 1
0
        // create word object
        void CreateWordImage(string word, float scale)
        {
            float y = 2;             // y-position of object

            // instantiate word object from properties given
            ObjectProperties Obj = ObjectProperties.CreateInstance(word, "WordObject", new Vector3(0, y, 0), new Vector3(scale, scale, 1), ProgressManager.currentLevel + "/" + word, "Words/" + word);

            ObjectProperties.InstantiateObject(Obj);
        }
 //<summary>
 // create jars
 //</summary>
 void CreateJars()
 {
     // find letters
     GameObject[] gos = GameObject.FindGameObjectsWithTag(Constants.Tags.TAG_TARGET_LETTER);
     foreach (GameObject go in gos)
     {
         // get position of letter
         Vector3 letterPosn = new Vector3(go.transform.position.x, go.transform.position.y, 1.5f);
         // instantiate jar behind letter
         ObjectProperties jar = ObjectProperties.CreateInstance("Jar", "Jar", letterPosn,
                                                                new Vector3(.45f, .45f, 1), "Jar", null);
         ObjectProperties.InstantiateObject(jar);
     }
 }
Esempio n. 3
0
 //<summary>
 // give user hint about what letter a particular sound is pronouncing
 //</summary>
 public static void ShowSoundHint()
 {
     // find movable sound blanks
     GameObject[] mov = GameObject.FindGameObjectsWithTag(Constants.Tags.TAG_MOVABLE_BLANK);
     // loop through sound blanks
     foreach (GameObject go in mov)
     {
         // choose first sound blank that is still draggable
         // i.e. hasn't been dragged onto a jar/letter yet
         if (go.GetComponent <TransformGesture>().enabled == true)
         {
             // get position of sound blank
             Vector3 posn = go.transform.position;
             // sound blank rotates halfway around and fades out
             LeanTween.rotateAround(go, Vector3.right, 180, 1f);
             LeanTween.alpha(go, 0f, .5f).setDelay(.5f);
             // create letter if one doesn't already exist
             if (GameObject.Find("Hint" + go.name) == null)
             {
                 ObjectProperties letter = ObjectProperties.CreateInstance
                                               ("Hint" + go.name, "Hint", posn, new Vector3(WordCreation.letterScale * .9f,
                                                                                            WordCreation.letterScale * .9f, 1), "Letters/" + go.name, null);
                 ObjectProperties.InstantiateObject(letter);
             }
             // find the letter just created / already created
             GameObject hint = GameObject.Find("Hint" + go.name);
             // move letter to center of corresponding sound blank
             hint.transform.position = new Vector3(go.transform.position.x,
                                                   go.transform.position.y, 3);
             // play phoneme sound of letter
             go.GetComponent <AudioSource>().PlayDelayed(1f);
             // letter fades in and moves in front of background to z = -3
             LeanTween.alpha(hint, 0f, .01f);
             LeanTween.moveZ(hint, -3, .01f).setDelay(1f);
             LeanTween.alpha(hint, 1f, .01f).setDelay(1f);
             // letter changes color to green and then back to black
             LeanTween.color(hint, Color.green, 1f).setDelay(1f);
             LeanTween.color(hint, Color.black, 1f).setDelay(2f);
             // letter fades out and moves behind background to z = 3
             LeanTween.alpha(hint, 0f, .01f).setDelay(3f);
             LeanTween.moveZ(hint, 3, .01f).setDelay(3f);
             // sound blank rotates back around and fades in
             LeanTween.alpha(go, 1f, .5f).setDelay(3f);
             LeanTween.rotateAround(go, Vector3.left, 180, 1f).setDelay(3f);
             // exit loop once a hint letter has been created
             break;
         }
     }
 }
Esempio n. 4
0
        // Create word with letters. Takes in desired word, list of phonemes in word, tag for each letter (MovableLetter or TargetLetter),
        // and game mode that word will be created in (Learn, SpellingGame, or SoundGame).
        public static void CreateWord(string word, string[] sounds, string tag, string mode)
        {
            Vector3[] position = new Vector3[word.Length];          // contains desired position of each letter
            string[]  letters  = new string[word.Length];           // contains letters in word

            // want each letter as an uppercase string
            for (int i = 0; i < word.Length; i++)
            {
                char letter = System.Char.ToUpper(word [i]);
                letters[i] = System.Char.ToString(letter);
            }

            // set y-position for letters
            if (mode == "Learn")
            {
                y = -2;
            }
            if (mode == "SpellingGame")
            {
                y = 0;
            }
            if (mode == "SoundGame")
            {
                y = -3.5f;
            }

            // set z-position for letters
            if (tag == "MovableLetter")
            {
                z = -2;
            }
            if (tag == "TargetLetter")
            {
                z = 0;
            }

            // set x-position for each letter
            // word centered at x = 0, letters evenly spread out according to letterWidth
            if (word.Length == 3)
            {
                position = new Vector3[3] {
                    new Vector3(-1f * letterWidth, y, z),
                    new Vector3(0, y, z),
                    new Vector3(1f * letterWidth, y, z)
                };
            }
            if (word.Length == 4)
            {
                position = new Vector3[4] {
                    new Vector3(-1.5f * letterWidth, y, z),
                    new Vector3(-.5f * letterWidth, y, z),
                    new Vector3(.5f * letterWidth, y, z),
                    new Vector3(1.5f * letterWidth, y, z),
                };
            }
            if (word.Length == 5)
            {
                position = new Vector3[5] {
                    new Vector3(-2f * letterWidth, y, z),
                    new Vector3(-1f * letterWidth, y, z),
                    new Vector3(0, y, z),
                    new Vector3(1f * letterWidth, y, z),
                    new Vector3(2f * letterWidth, y, z)
                };
            }


            for (int i = 0; i < word.Length; i++)
            {
                // create letter with desired properties according to input given
                ObjectProperties letter = ObjectProperties.CreateInstance(letters [i], tag, position [i], new Vector3(letterScale, letterScale, 1), "Letters/" + letters [i], "Phonemes/" + sounds [i]);
                ObjectProperties.InstantiateObject(letter);
            }
        }
Esempio n. 5
0
 //<summary>
 //Instantiate blanks. Takes in the desired word, phonemes in the word, shape of the blank (Rectangle or Circle),
 // tag of object (MovableBlank or TargetBlank), and type of game (SpellingGame or SoundGame).
 //</summary>
 public static void CreateBlanks(string word, string[] sounds, string shape, string tag, string mode)
 {
     //Set default scale, according to blank shape
     if (shape == "Rectangle")
     {
         xScale = .7f;
         yScale = 1.5f;
     }
     if (shape == "Circle")
     {
         xScale = .3f;
         yScale = .3f;
     }
     //Set y position, according to game mode
     if (mode == "SpellingGame")
     {
         y = -3;
     }
     if (mode == "SoundGame")
     {
         y = 0;
     }
     //Set z position
     if (tag == Constants.Tags.TAG_MOVABLE_BLANK)
     {
         // if draggable, set in front
         z = -2;
     }
     if (tag == Constants.Tags.TAG_TARGET_BLANK)
     {
         // if static, set in back
         z = 0;
     }
     //Want the word in the format of an array of uppercase letters instead of a string
     string[] letterArray = new string[word.Length];
     for (int i = 0; i < word.Length; i++)
     {
         char letter = System.Char.ToUpper(word[i]);
         letterArray[i] = System.Char.ToString(letter);
     }
     //Set x position of each blank, for each possible word length
     //Word is centered at x = 0, letters are evenly spaced out according to blankWidth
     Vector3[] position = new Vector3[word.Length];
     if (word.Length == 3)
     {
         position = new Vector3[3]
         {
             new Vector3(-1f * blankWidth, y, z),
             new Vector3(0, y, z),
             new Vector3(1f * blankWidth, y, z)
         };
     }
     if (word.Length == 4)
     {
         position = new Vector3[4]
         {
             new Vector3(-1.5f * blankWidth, y, z),
             new Vector3(-.5f * blankWidth, y, z),
             new Vector3(.5f * blankWidth, y, z),
             new Vector3(1.5f * blankWidth, y, z),
         };
     }
     if (word.Length == 5)
     {
         position = new Vector3[5]
         {
             new Vector3(-2f * blankWidth, y, z),
             new Vector3(-1f * blankWidth, y, z),
             new Vector3(0, y, z),
             new Vector3(1f * blankWidth, y, z),
             new Vector3(2f * blankWidth, y, z)
         };
     }
     //Assign properties for the blanks according to input given, then instantiate each blank
     for (int i = 0; i < word.Length; i++)
     {
         ObjectProperties blank = ObjectProperties.CreateInstance(letterArray[i], tag, position[i],
                                                                  new Vector3(xScale, yScale, 1), shape, "Phonemes/" + sounds[i]);
         ObjectProperties.InstantiateObject(blank);
     }
 }
Esempio n. 6
0
        // 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);
            }
        }