Ejemplo n.º 1
0
    private void Start()
    {
        audioCon = GameObject.Find("AudioMixer").GetComponent<AudioController>();

        closeTimer = MAX_CLOSE_TIMER;
        showNameA();

        activePrefabs = new GameObject[maxSelectedA - firstUnavailableA];

        //Fill up actionbar
        for(int i = 0; i < activePrefabs.Length; i++)
        {
            int tileId = i + 1; //from 1-10 (exclude air)
            bool useAirPuzzle = puzzleUseAir(tileId);

            bool banned = tileHub.actionbarBanned.Contains(tileId);
            if (!banned)
            {
                //print("Actionbar: Adding tileId: " + tileId);
                //print("b: " + b + ", Length: " + activePrefabs.Length);
                if(useAirPuzzle)
                {
                    activePrefabs[i] = tileHub.getPrefab(0);
                    actionbars[i + firstUnavailableA].GetComponent<Image>().color = Color.black;
                    actionbars[i + firstUnavailableA].GetComponent<ActionBarItem>().tileId = 0;
                }
                else
                {
                    activePrefabs[i] = tileHub.getPrefab(tileId);
                    actionbars[i + firstUnavailableA].GetComponent<Image>().sprite = activePrefabs[i].GetComponent<SpriteRenderer>().sprite;
                    actionbars[i + firstUnavailableA].GetComponent<ActionBarItem>().tileId = tileId;
                }
            }
        }

        //Create and fill selectionbar for each tile there is (except banned ones)
        int index = 0;
        int row = 0;
        Instantiate(selectionbarRowPrefab, selectbar.transform);
        for(int id = 0; id < tileHub.tilePrefabs.Length; id++)
        {
            GameObject tile = tileHub.getPrefab(id);

            bool useAirPuzzle = puzzleUseAir(id);

            bool banned = tileHub.actionbarBanned.Contains(id);
            if (!banned)
            {
                //position
                if (index >= selectbarMaxItemsPerRow)
                {
                    index = 0;
                    row++;
                    GameObject rowPrefab = Instantiate(selectionbarRowPrefab, selectbar.transform);
                    rowPrefab.transform.localPosition += new Vector3(0, actionTileSize * row, 0);
                }

                GameObject prefab = Instantiate(selectionbarPrefab, selectbar.transform);
                prefab.transform.localPosition += new Vector3(actionTileSize * index, actionTileSize * row, 0);
                index++;

                prefab.GetComponent<SelectbarController>().AC = this;
                if (useAirPuzzle)
                {
                    prefab.GetComponent<SelectbarController>().tileId = 0;
                    prefab.GetComponent<Image>().color = Color.black;
                }
                else
                {
                    prefab.GetComponent<SelectbarController>().tileId = id;
                    prefab.GetComponent<Image>().sprite = tile.GetComponent<SpriteRenderer>().sprite;
                }
            }
        }
        selectbar.SetActive(false);
        selectedTileS.SetActive(false);
    }