private void TileSort(MaterialInitData initData, GameObject[] selectedTheme) { int index = 0; List <int> tileSponeIndex = new List <int>() { 0, 1, 2, 4, 9, 14, 22, 23, 24, 10, 15, 20 }; // 타일 인스턴스 for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { int ran = Random.Range(0, selectedTheme.Length); Vector3 pos = new Vector3(i + transform.position.x, 0.35f, j); Tile tile = TileLoad(pos); GroundInstance(selectedTheme[ran], tile); TileData tileData; if (tileSponeIndex.Contains(index)) { // 남은 자원 숫자 tileData = RandomMaterial(index, tileSponeIndex.Count, initData); tileSponeIndex.Remove(index); } else { tileData = new TileData(isPlayerGround, index, 100, TileState.NORMAL); } tile.TileInit(tileData); tileList.Add(tile); index++; } } }
public void UnitControllerInit(bool isPlayer, GameObject[] selectedTheme, MaterialInitData materialInitData, UnitInitData unitInitData) { //플레이어 진영인지 this.isPlayer = isPlayer; // 그라운드 타일 및 자원 생성 ground.GroundInit(isPlayer, selectedTheme, materialInitData); // 유닛 데이터 생성 unitData = new UnitData() { unitLevel = unitInitData.unitLevel, unitIndex = unitInitData.unitIndex, unitHp = unitInitData.unitHp, unitMaxHp = unitInitData.unitHp, unitDemage = unitInitData.unitDemage, maxStamina = unitInitData.maxStamina, stamina = unitInitData.stamina, staminaCoolTime = unitInitData.staminaCoolTime, tableCount = 0, unitMaterial = new UnitMaterialData() }; // 유닛 위치 초기화 unitControl.transform.position = ReturnMovePos(unitData.unitIndex); // 유닛 HUD 초기화 unitUI.SetDelegate(UnitStaminaUp); unitUI.UnitUIUpdate(unitData); // 델리게이트 설정 unitControl.SetDelegate(Move, Collect, Build, BuildTap, isPlayer, EnemyAction, EnemyBuildAction, EnemyLevelUp); // 이벤트 리스너 등록 if (isPlayer) { EventManager.Instance.on(EVENT_TYPE.TOWER_WILL_BUILD, TowerButtonTap); EventManager.Instance.on(EVENT_TYPE.TABLE_WILL_BUILD, TableButtonTap); EventManager.Instance.on(EVENT_TYPE.BUNKER_WILL_BUILD, BunkerButtonTap); EventManager.Instance.on(EVENT_TYPE.WILL_BUILD_OFF, BuildOff); } EventManager.Instance.on(EVENT_TYPE.TILE_HIT, IsPlayerHit); EventManager.Instance.on(EVENT_TYPE.TABLE_BROKEN, TableBroken); }
public void GameInit() { MaterialInitData playerMaterialInitData = new MaterialInitData() { wood = new MaterialData() { state = MaterialState.WOOD, count = materialInitCount.woodCount, amount = materialInitAmount.woodCount }, stone = new MaterialData() { state = MaterialState.STONE, count = materialInitCount.stoneCount, amount = materialInitAmount.stoneCount }, iron = new MaterialData() { state = MaterialState.IRON, count = materialInitCount.ironCount, amount = materialInitAmount.ironCount }, adam = new MaterialData() { state = MaterialState.ADAM, count = materialInitCount.adamCount, amount = materialInitAmount.adamCount }, }; MaterialInitData EnemyMaterialInitData = new MaterialInitData() { wood = new MaterialData() { state = MaterialState.WOOD, count = materialInitCount.woodCount, amount = materialInitAmount.woodCount }, stone = new MaterialData() { state = MaterialState.STONE, count = materialInitCount.stoneCount, amount = materialInitAmount.stoneCount }, iron = new MaterialData() { state = MaterialState.IRON, count = materialInitCount.ironCount, amount = materialInitAmount.ironCount }, adam = new MaterialData() { state = MaterialState.ADAM, count = materialInitCount.adamCount, amount = materialInitAmount.adamCount }, }; playerController.UnitControllerInit(true, selecetedTheme, playerMaterialInitData, unitInitData); enemyController.UnitControllerInit(false, selecetedTheme, EnemyMaterialInitData, unitInitData); // FireTimeCount(); StartCoroutine("OneSecTimer"); }
public void GroundInit(bool isPlayerGround, GameObject[] selectedTheme, MaterialInitData materialInitData) { this.isPlayerGround = isPlayerGround; TileSort(materialInitData, selectedTheme); EventManager.Instance.on(EVENT_TYPE.TOWER_FIRE, TileTargeting); }
private TileData RandomMaterial(int index, int tileSponeIndexCount, MaterialInitData initData) { TileData tileData; int currentRemainingMaterial = initData.wood.count + initData.stone.count + initData.iron.count + initData.adam.count; // 남은 자원의 숫자가 들어갈 자원의 숫자와 같으면 if (currentRemainingMaterial == tileSponeIndexCount) // 12 보다 클 수 없음 { if (initData.wood.count > 0) { tileData = new TileData(isPlayerGround, index, initData.wood.amount, TileState.MATERIAL, MaterialState.WOOD); initData.wood.count--; } else if (initData.stone.count > 0) { tileData = new TileData(isPlayerGround, index, initData.stone.amount, TileState.MATERIAL, MaterialState.STONE); initData.stone.count--; } else if (initData.iron.count > 0) { tileData = new TileData(isPlayerGround, index, initData.iron.amount, TileState.MATERIAL, MaterialState.IRON); initData.iron.count--; } else if (initData.adam.count > 0) { tileData = new TileData(isPlayerGround, index, initData.adam.amount, TileState.MATERIAL, MaterialState.ADAM); initData.adam.count--; } else { tileData = new TileData(isPlayerGround, index, 100, TileState.NORMAL); } } else { int ran = Random.Range(0, 2); // Normal 인지 Material 인지 if (ran == 1) { // material 이면 int materialRan = Random.Range(0, 4); if (materialRan == 0 && initData.wood.count > 0) { tileData = new TileData(isPlayerGround, index, initData.wood.amount, TileState.MATERIAL, MaterialState.WOOD); initData.wood.count--; } else if (materialRan == 1 && initData.stone.count > 0) { tileData = new TileData(isPlayerGround, index, initData.wood.amount, TileState.MATERIAL, MaterialState.STONE); initData.stone.count--; } else if (materialRan == 2 && initData.iron.count > 0) { tileData = new TileData(isPlayerGround, index, initData.wood.amount, TileState.MATERIAL, MaterialState.IRON); initData.iron.count--; } else if (materialRan == 3 && initData.adam.count > 0) { tileData = new TileData(isPlayerGround, index, initData.wood.amount, TileState.MATERIAL, MaterialState.ADAM); initData.adam.count--; } else { tileData = new TileData(isPlayerGround, index, 100, TileState.NORMAL); } } else { tileData = new TileData(isPlayerGround, index, 100, TileState.NORMAL); } } return(tileData); }