Пример #1
0
    public void InitTiles()
    {
        // 모든 리스트 초기화
        _listMoveTiles.Clear();
        _listPangTiles.Clear();
        _listWaitingTiles.Clear();
        _listTopTiles.Clear();
        _listBombTiles.Clear();

        // 자식 타일들이 있으면 다 삭제
        Transform[] childList = GetComponentsInChildren <Transform>(true);
        if (childList != null)
        {
            for (int i = 0; i < childList.Length; i++)
            {
                if (childList[i] != transform)
                {
                    Destroy(childList[i].gameObject);
                }
            }
        }

        //ui 초기화
        _questCnt = 10;
        _moveCnt  = 20;

        _uiMng.SetMoveCnt(_moveCnt);
        _uiMng.SetQuestCnt(_questCnt);

        int totalTilesCnt = _iSize * _iSize;

        _tiles = new Tile[totalTilesCnt];

        _prefTile = Resources.Load("Tiles/TilePrefab") as GameObject;


        // 강제로 스테이지를 설정합니다.
        // 대부분 상수처리로 하고 나중에 툴 값을 적용
        // 화면 사이즈가 6이라고 정


        // 안쓰는 타일 숨기기
        int[] locked = { 4, 5, 6, 12, 13, 20, 21, 28, 29, 35, 36, 37, 42, 43, 44, 45, 46, 47, 48 };
        for (int i = 0; i < locked.Length; i++)
        {
            Tile t0 = Instantiate <Tile>(_prefTile.transform.GetComponent <Tile>());
            t0.transform.localScale = Vector3.one;
            t0.transform.parent     = this.transform;
            t0._isLock = true;
            t0.gameObject.SetActive(false);
            _tiles[locked[i]] = t0;
        }


        float fOneSize    = 0.8f;
        float fSideStartX = -fOneSize * (_iSize - 1) / 2.0f;

        //팽이 위치 잡기
        int[] tops = { 1, 2, 11, 19, 22, 24, 30, 38, 39, 40 };
        for (int k = 0; k < tops.Length; k++)
        {
            int cur = tops[k];
            if (_tiles[cur] == null)
            {
                int  i  = cur / _iSize;
                int  j  = cur % _iSize;
                int  r  = (int)Tile.TILE_IDX.TOP;
                Tile t0 = Instantiate <Tile>(_prefTile.transform.GetComponent <Tile>());
                t0.name = "Top : " + cur;
                t0.SetIdx(r);

                t0.transform.localScale = Vector3.one;

                t0.transform.parent = this.transform;
                float x = fSideStartX + fOneSize * j;
                float y = fSideStartX - fOneSize * i + 3.0f;
                y += fOneSize / 2 * j;
                Vector3 v = new Vector3(x, y, 0.0f);
                t0.transform.localPosition = Vector3.zero;
                t0.transform.DOLocalMove(v, 0.7f);

                _tiles[cur]        = t0;
                _tiles[cur]._pos   = v;
                _tiles[cur]._cur   = cur;
                _tiles[cur]._board = this;
            }
        }

        // 초기 스테이즈 설정

        int line = 0;

        for (int i = 0; i < _iSize; i++)
        {
            for (int j = 0; j < _iSize; j++)
            {
                int cur = line + j;
                if (_tiles[cur] == null)
                {
                    int  r  = GetSatrtTileIdx(i, j);
                    Tile t0 = Instantiate <Tile>(_prefTile.transform.GetComponent <Tile>());
                    t0.name = "tile : " + cur;
                    t0.SetIdx(r);

                    t0.transform.localScale = Vector3.one;

                    t0.transform.parent = this.transform;
                    float x = fSideStartX + fOneSize * j;
                    float y = fSideStartX - fOneSize * i + 3.0f;
                    y += fOneSize / 2 * j;
                    Vector3 v = new Vector3(x, y, 0.0f);
                    t0.transform.localPosition = Vector3.zero;
                    t0.transform.DOLocalMove(v, 0.5f);

                    _tiles[cur]        = t0;
                    _tiles[cur]._pos   = v;
                    _tiles[cur]._cur   = cur;
                    _tiles[cur]._board = this;
                }
                else
                {
                    //Debug.Log(" out " + cur);
                }
            }

            line += _iSize;
        }


        // 새로 타일이 생성 되는 곳 지정
        int[] maker = { 3 };
        for (int i = 0; i < maker.Length; i++)
        {
            Tile makerTile = _tiles[maker[i]];
            makerTile._isMaker = true;
        }
    }