Esempio n. 1
0
 public override void OnChildLetterConfirmed(ILetterSelectionResponse childObjectConfirmed, Vector3 inputPosition, List <GameObject> wasSelectedObjects)
 {
     if (!_audioSource.isPlaying)
     {
         _audioSource.Play();
     }
 }
 public virtual void OnChildLetterSelected(ILetterSelectionResponse childObjectSelected, Vector3 inputPosition)
 {
     if (childObjectSelected != null)
     {
         if (!_lettersGameObjectSelected.Contains(childObjectSelected))
         {
             _lettersGameObjectSelected.Add(childObjectSelected);
         }
     }
 }
    public virtual void OnChildLetterConfirmed(ILetterSelectionResponse childObjectConfirmed, Vector3 inputPosition, List <GameObject> wasSelectedObjects)
    {
        if (childObjectConfirmed != null)
        {
            if (!_lettersGameObjectSelected.Contains(childObjectConfirmed))
            {
                _lettersGameObjectSelected.Add(childObjectConfirmed);
            }
        }

        OnSelectionConfirm(this.gameObject, inputPosition, wasSelectedObjects);
    }
    protected override void AssembleLetters(string word) // create overload for offset and margins?
    {
        Debug.Log("assembling letters");

        var letterBlockSpriteRenderer = LetterBlockPrefab.GetComponent <RectTransform>();
        int length = word.Length;

        _letterChildren = new ILetterSelectionResponse[length];
        float scale = CalculateScale(word);

        letterChildrenObjects = new GameObject[length];



        //float letterWidth = letterBlockSpriteRenderer.rect.width * scale; // for starting position
        float letterWidth = ((letterBlockSpriteRenderer.rect.width / Screen.width) * WorldUnitSize) * scale;
        float initialAllowanceToCenterPosition = ((letterWidth * length) + (PerLetterMargin * length - 1)) / 2 - (letterWidth / 2); //less half since pivot point is at the center.

        //assemble the word using the letters
        int lettersInstantiated = 0;

        for (int i = 0; i < length; i++)
        {
            Vector3 objectPosition = new Vector3(transform.position.x + (letterWidth * lettersInstantiated) - initialAllowanceToCenterPosition, transform.position.y, transform.position.z);
            objectPosition.x += PerLetterMargin * lettersInstantiated;
            GameObject letterGameObject = Instantiate(LetterBlockPrefab, transform);
            letterChildrenObjects[i]              = letterGameObject;
            letterGameObject.transform.position   = objectPosition;
            letterGameObject.transform.localScale = new Vector2(scale, scale);
            ILetterSelectionResponse letterComponent = letterGameObject.GetComponent <ILetterSelectionResponse>();
            if (letterComponent != null)
            {
                Debug.Log("there is letter component " + _letterChildren.Length);
                letterComponent.Initialize(word[i]);
                _letterChildren[i] = letterComponent;
            }


            lettersInstantiated++;
        }

        //deactivate missing letter
        DeactivateRandomLetter(word);
        SwapToDragableLetter(word);
        AddVelocityToLetter();
        AddContainer(word);
        generateWalkingLetters(DistractionLetters, scale);
        //AssignContainerName(_deactivatedChar.ToString());

        OptionChanged();
    }
    private void SwapToDragableLetter(string word)
    {
        float scale = CalculateScale(word);

        System.Random random = new System.Random();

        GameObject letterGameObject = Instantiate(MissingLetterBlockPrefab, transform);

        _replacementLetter = letterGameObject;
        letterGameObject.transform.localScale = new Vector2(scale, scale);
        //letterGameObject.transform.position = Camera.main.ViewportToWorldPoint(new Vector2(0.5f, 0.25f));
        letterGameObject.transform.position = Camera.main.ViewportToWorldPoint(randomPosition());

        ILetterSelectionResponse letterComponent = letterGameObject.GetComponent <ILetterSelectionResponse>();

        if (letterComponent != null)
        {
            letterComponent.Initialize(_deactivatedChar);
        }
    }
    private void generateWalkingLetters(int numberOfLetters, float scale)
    {
        _distractionLetterObjects = new GameObject[numberOfLetters];
        if (_distractionChars == null)
        {
            _distractionChars = new List <char>();
        }

        for (int i = 0; i < numberOfLetters; i++)
        {
            char letter = generateRandomLetter();
            if (_distractionChars.Contains(letter) || letter == _deactivatedChar)
            {
                while (_distractionChars.Contains(letter) || letter == _deactivatedChar)
                {
                    letter = generateRandomLetter();
                }
            }

            _distractionChars.Add(letter);
            GameObject letterGameObject = Instantiate(MissingLetterBlockPrefab, transform);
            _distractionLetterObjects[i] = letterGameObject;

            letterGameObject.transform.position   = Camera.main.ViewportToWorldPoint(randomPosition());
            letterGameObject.transform.localScale = new Vector2(scale, scale);
            ILetterSelectionResponse letterComponent = letterGameObject.GetComponent <ILetterSelectionResponse>();
            if (letterComponent != null)
            {
                letterComponent.Initialize(letter);
            }

            var walker = letterGameObject.GetComponent <RandomWalker>();
            if (walker)
            {
                walker.EnableRandomWalk(true);
            }
        }
    }
    protected virtual void AssembleLetters(string word) // create overload for offset and margins?
    {
        Debug.Log("assembling letters");

        var letterBlockSpriteRenderer = LetterBlockPrefab.GetComponent <RectTransform>();
        int length = word.Length;

        _letterChildren = new ILetterSelectionResponse[length];
        float scale = CalculateScale(word);

        //float letterWidth = letterBlockSpriteRenderer.rect.width * scale; // for starting position
        float letterWidth = ((letterBlockSpriteRenderer.rect.width / Screen.width) * WorldUnitSize) * scale;
        float initialAllowanceToCenterPosition = ((letterWidth * length) + (PerLetterMargin * length - 1)) / 2 - (letterWidth / 2); //less half since pivot point is at the center.

        //assemble the word using the letters
        int lettersInstantiated = 0;

        for (int i = 0; i < length; i++)
        {
            Vector3 objectPosition = new Vector3(transform.position.x + (letterWidth * lettersInstantiated) - initialAllowanceToCenterPosition, transform.position.y, transform.position.z);
            objectPosition.x += PerLetterMargin * lettersInstantiated;
            GameObject letterGameObject = Instantiate(LetterBlockPrefab, transform);
            letterGameObject.transform.position   = objectPosition;
            letterGameObject.transform.localScale = new Vector2(scale, scale);
            ILetterSelectionResponse letterComponent = letterGameObject.GetComponent <ILetterSelectionResponse>();
            if (letterComponent != null)
            {
                letterComponent.Initialize(word[i]);
                Debug.Log("there is letter component " + _letterChildren.Length);
                _letterChildren[i] = letterComponent;
            }
            lettersInstantiated++;
        }

        OptionChanged();
    }
Esempio n. 8
0
    public override void OnChildLetterSelected(ILetterSelectionResponse childObjectSelected, Vector3 inputPosition)
    {
        ChildIsSelected();

        base.OnChildLetterSelected(childObjectSelected, inputPosition);
    }