public void PopulateTile(List <Activity> activities)
        {
            for (int i = 0; i < activities.Count; i++)
            {
                GameObject instatiatedIcon = Instantiate(actIconPrefab);

                Vector3 iconPos = new Vector3(pivotCenter.transform.position.x, pivotCenter.transform.position.y, pivotCenter.transform.position.z);

                ActivityButton activityButton = instatiatedIcon.GetComponent <ActivityButton>();

                activityButton.SetActivity(activities[i]);
                instatiatedIcon.transform.SetParent(pivotCenter.transform);

                iconPos.x = iconPos.x - posXRange + (posXRange * (i + 1)) / activities.Count;
                instatiatedIcon.transform.position = iconPos;
            }
        }
Exemple #2
0
        public void PopulateWordNew(List <Activity> activities)
        {
            //Calcula a qtd de tiles de meio necessários
            int midTilesCount = (activities.Count - iconsStart - iconsEnd) / iconsPerTile;

            Vector3 initialPosIcon;
            Vector3 finalPosIcon;

            GameObject instantiatedTile;
            Vector3    tilePos = Vector3.zero;

            Vector3 intObjPos = Vector3.zero;

            //Instanciando o Tile inicial
            instantiatedTile = Instantiate(tileStart, tilePos, Quaternion.identity, this.transform);

            //Qguarda a posição onde deve ser instanciado o primeiro icone
            initialPosIcon = instantiatedTile.GetComponent <TileProperties>().GetPivotPos();

            //Instancia a qtd de mid tiles calculada anteriormente
            for (int i = 0; i < midTilesCount; i++)
            {
                tilePos.x       += tilesDistance;
                instantiatedTile = Instantiate(tileMidle, tilePos, Quaternion.identity, this.transform);

                instantiatedTile.GetComponent <TileProperties>().SortTileConfiguration();
            }

            //Instancia o Tile final
            tilePos.x       += tilesDistance;
            instantiatedTile = Instantiate(tileEnd, tilePos, Quaternion.identity, this.transform);

            //Guarda a posiçao onde deve ser instanciado o ultimo icone
            finalPosIcon = instantiatedTile.GetComponent <TileProperties>().GetPivotPos();

            //Atualiza a posição máxima da câmera
            tilePos.x += tilesDistance * (endTileRatio);
            camMaxPos  = tilePos;
            if (fixedCamLimit != null)
            {
                Camera.main.GetComponent <NewCameraMovement>().SetMaxPos(camMaxPos - fixedCamLimit);
            }
            else
            {
                Camera.main.GetComponent <NewCameraMovement>().SetMaxPos(camMaxPos);
            }

            //Configuração do chão, para englobar todos os tiles instanciados (menos o ultimo)
            if (midTilesCount > 1)
            {
                float midConvert = midTilesCount;
                groundSprite.size = new Vector2((midTilesCount * (groundTileMultiplier * 0.8f)) + (groundTileMultiplier), groundSprite.size.y);
                groundSprite.transform.position = new Vector3((midConvert / 2 + 0.5f) * tilesDistance, groundSprite.transform.position.y, groundSprite.transform.position.z);
            }
            else
            {
                groundSprite.size = new Vector2((midTilesCount + 1) * (groundTileMultiplier), groundSprite.size.y);
                groundSprite.transform.position = new Vector3((midTilesCount / 2 + 1) * tilesDistance, groundSprite.transform.position.y, groundSprite.transform.position.z);
            }

            //Configuração do céu, para englobar todos os tiles
            skySprite.size = new Vector2((midTilesCount + 2) * skyTileMultiplier, skySprite.size.y);
            skySprite.transform.position = new Vector3(((midTilesCount + 2) / 2) * tilesDistance, skySprite.transform.position.y, skySprite.transform.position.z);


            //Instanciando os icones
            //Calcula a distância de um para o outro
            posXRange = (finalPosIcon.x - initialPosIcon.x) / activities.Count;

            Vector3 iconPos = new Vector3(initialPosIcon.x, initialPosIcon.y, initialPosIcon.z);

            int notSpawnedInteractble = 0;

            int lastInstantiated = 0;

            List <GameObject> interactbleObjectsAux = new List <GameObject>();


            if (skipFirstInteractble)
            {
                interactbleObjectsAux.AddRange(interactbleObjects.GetRange(1, interactbleObjects.Count - 1));
            }

            for (int i = 0; i < activities.Count; i++)
            {
                GameObject instatiatedIcon = Instantiate(actIconPrefab);

                ActivityButton activityButton = instatiatedIcon.GetComponent <ActivityButton>();

                activityButton.SetActivity(activities[i]);
                instatiatedIcon.transform.SetParent(pivotCenter.transform);

                iconPos.y = initialPosIcon.y + Random.Range(-posYRange, posYRange);
                instatiatedIcon.transform.position = iconPos;
                iconPos.x += posXRange;

                if (i >= skipIcons)
                {
                    activityButton.midItem = true;
                }

                //Sorteia 50% a chance de instanciar um Interactble object
                int randomChance = Random.Range(0, 2);

                if ((randomChance == 0 || notSpawnedInteractble >= 2) && (interactbleObjects.Count > 0) && i >= skipIcons && (iconPos.x < finalPosIcon.x))
                {
                    if (onlySpawnAbove && (iconPos.y > initialPosIcon.y))
                    {
                        continue;
                    }

                    if (interactbleObjectsAux.Count == 0)
                    {
                        interactbleObjectsAux.AddRange(interactbleObjects.GetRange(0, interactbleObjects.Count));
                    }


                    int randomIndex;

                    //Sorteia um objeto da lista para instanciar

                    /*do
                     * {
                     *
                     *
                     * } while (randomIndex == lastInstantiated);
                     */
                    randomIndex      = Random.Range(0, interactbleObjectsAux.Count);
                    lastInstantiated = randomIndex;

                    GameObject interactbleObject = Instantiate(interactbleObjectsAux[randomIndex]);

                    interactbleObjectsAux.RemoveAt(randomIndex);

                    intObjPos.z = iconPos.z;
                    //Verifica se o ultimo item está a cima ou abaixo e define o range Y do item a partir disso
                    if (iconPos.y > initialPosIcon.y)
                    {
                        //O Icone foi instanciado a cima do meio
                        intObjPos.y = Random.Range(initialPosIcon.y - posYRange, iconPos.y - interactbleObject.GetComponent <ClickCollider>().securityMargin);
                    }
                    else
                    {
                        //O Icone foi instanciado abaixo do meio
                        intObjPos.y = Random.Range(iconPos.y + intObjMarginY, initialPosIcon.y + interactbleObject.GetComponent <ClickCollider>().securityMargin);
                    }

                    intObjPos.x = Random.Range(iconPos.x, (iconPos.x - 2 * intObjMarginX + posXRange));

                    interactbleObject.transform.position = intObjPos;
                    interactbleObject.transform.SetParent(pivotCenter.transform);

                    notSpawnedInteractble = 0;
                }
                else
                {
                    notSpawnedInteractble++;
                }
            }
        }