// Start is called before the first frame update void Start() { character = Instantiate(Resources.Load <GameObject>("Prefabs/Character/" + eCharacter[UnityEngine.Random.Range(0, eCharacter.Length)])); ChessCharacter script = character.GetComponent <Skeleton>() ? (ChessCharacter)character.GetComponent <Skeleton>() : character.GetComponent <Knight>(); script.enabled = false; character.transform.position = tilemap.CellToWorld(new Vector3Int(4, 4, 0)); mainCamera.transform.SetParent(character.transform); recordText.text = Repository.GetRecord(); nicknameText.text = Repository.sData["Nickname"]; animator = character.GetComponent <Animator>(); pos = character.transform.position; cellpos = tilemap.WorldToCell(character.transform.position); if (PlayerPrefs.GetInt("BGM", 1) == 0) { bgmOn.SetActive(false); bgmOff.SetActive(true); } if (PlayerPrefs.GetInt("SE", 1) == 0) { seOn.SetActive(false); seOff.SetActive(true); } }
private bool BuyWaitCharacter(string path, string name, eCharacter characterType) { int waitPositionX = 0; while (waitPositionX < 8) { ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(waitPositionX, -1, 0)); if (chessTile != null) { if (chessTile.gameObject == null) { GameObject character = Instantiate(Resources.Load(path)) as GameObject; character.name = name; ChessCharacter cCharacter = character.GetComponent <ChessWaitCharacter>(); character.transform.SetParent(tilemap.transform); cCharacter.SetTilePosition(new Vector3Int(waitPositionX, -1, 0)); cCharacter.SetCharacterType(ChessCharacter.eCharacterType.WAIT); cCharacter.SetChessCharacterType(characterType); chessTile.gameObject = character; return(true); } } waitPositionX++; } return(false); }
public void SpawnCharacter(string path, string name, int tileX, int tileY, eCharacter chessCharacterType, ChessCharacter.eCharacterType characterType) { GameObject character = Instantiate(Resources.Load(path)) as GameObject; character.name = name; ChessCharacter cCharacter = character.GetComponent <ChessCharacter>(); cCharacter.SetTilePosition(new Vector3Int(tileX, tileY, 0)); cCharacter.SetCharacterType(characterType); cCharacter.SetChessCharacterType(chessCharacterType); Debug.Log("Spawn in GameManager"); character.transform.SetParent(tilemap.transform); ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(tileX, tileY, 0)); if (chessTile != null) { chessTile.gameObject = character; } GameObject canvas = GameObject.Find("Canvas"); RectTransform canvasRect = canvas.GetComponent <RectTransform>(); //slider transform 세팅 GameObject sliderObject = Instantiate(Resources.Load("Prefabs/UI/HpBar"), hpbarPanel.transform) as GameObject; //sliderObject.transform.SetParent(canvas.transform, false); Slider slider = sliderObject.GetComponent <Slider>(); cCharacter.SetHpBar(slider); }
public void AnimateEvent(string message) { if (message.Equals("AttackDamage")) // AttackDamage 함수와 헷깔리므로 이름 변경해야 합니다. { Debug.Log("AnimateEvent : AttackDamage!!!!!!"); if (_attackTarget != null) { GameObject gameObject = GameManager.gameInstance.GetTileObject(_attackTarget.GetTilePosition()); if (gameObject != null) { ChessCharacter character = gameObject.GetComponent <ChessCharacter>(); Debug.Log("character : " + character); character.SendMessage("AttackDamage", GetAttackPower()); } } } if (message.Equals("AttackEnd")) { Debug.Log("AnimateEvent : AttackEnd!!!!!!"); animator.SetBool("isAttack", false); SetState(eState.IDLE); } if (message.Equals("DeadEnd")) { Debug.Log("AnimateEvent : DeadEnd!!!!!!"); gameObject.SetActive(false); _hpBar.gameObject.SetActive(false); Destroy(gameObject); Destroy(_hpBar); } }
public void DestroyPlayerList() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(j, i, 0)); if (chessTile) { if (chessTile.gameObject) { //if (chessTile.gameObject.name.Contains("Player")) { ChessCharacter character = chessTile.gameObject.GetComponent <ChessCharacter>(); if (character) { DestroyImmediate(character.GetHpBar().gameObject); } DestroyImmediate(chessTile.gameObject); } } } } } }
private ChessCharacter FindAdjacentTarget(int findRange) { _cCharacter.ClearPathFindQueue(); GameManager.gameInstance.ResetTilePath(_cCharacter.name); ChessTile startTile; startTile = GameManager.gameInstance.tilemap.GetTile <ChessTile>(_cCharacter.GetTilePosition()); startTile.SetPrevPathTileNodeMap(_cCharacter.name, startTile); _cCharacter.PushPathFindTile(startTile); ChessTile nextQueueTile = _cCharacter.PopPathFindTile(); while (nextQueueTile != null) //###남은 갯수 체크가 아닌 PopPathFindTile 반환 값으로 판별하도록 개선 가능 { ChessTile currentTile = nextQueueTile; //가장 인근의 캐릭터 반환 if (currentTile.gameObject != null && currentTile.GetDistanceWeight() != 0) { ChessCharacter targetCharacter = currentTile.gameObject.GetComponent <ChessCharacter>(); if (_cCharacter.GetCharacterType() != targetCharacter.GetCharacterType() && targetCharacter.GetCharacterType() != ChessCharacter.eCharacterType.WAIT) // 적일 때만 탐색 성공 시킨다. { return(targetCharacter); } } else if (currentTile.GetDistanceWeight() == findRange + 1) { return(null); } else { for (int i = 0; i < (int)ChessCharacter.Direction.MAXSIZE; i++) { ChessCharacter.Direction direction = (ChessCharacter.Direction)i; Vector3Int nextTilePos = currentTile.GetTilePosition() + _cCharacter.GetDirectionTileNext(direction); ChessTile nextTile = GameManager.gameInstance.tilemap.GetTile <ChessTile>(nextTilePos); if (_cCharacter.IsInWall(nextTilePos) && //맵 안에 있을 때 분기 nextTile.GetPrevPathTileNodeMap(_cCharacter.name) == null) // 이미 이전 타일 세팅 안되있을 때 분기 { nextTile.SetPrevPathTileNodeMap(_cCharacter.name, currentTile); nextTile.SetDistanceWeight(currentTile.GetDistanceWeight() + 1); _cCharacter.PushPathFindTile(nextTile); } } } nextQueueTile = _cCharacter.PopPathFindTile(); } return(null); }
public void ChangeInfo(GameObject target) { UnitGuides information = target.GetComponent <UnitGuides>(); ChessCharacter stats = target.GetComponentInChildren <Skeleton>(true) ? (ChessCharacter)target.GetComponentInChildren <Skeleton>(true) : target.GetComponentInChildren <Knight>(true); Debug.Log(stats._findRange); introduce.text = information.introduce; maxHp.text = "최대체력 : " + stats.maxHp; moveSpeed.text = "이동속도 : " + stats.moveSpeed; atkPower.text = "공격력 : " + stats._attackPower; findRange.text = "탐색범위 : " + stats._findRange; atkRange.text = "공격범위 : " + stats._attackRange; }
void Start() { Object[] units = Resources.LoadAll("Prefabs"); foreach (string character in eCharacter) { Debug.Log(character + "를 생성합니다"); GameObject parent = Instantiate(unitsPanel, unitsContent.transform); GameObject unit = Instantiate(Resources.Load <GameObject>("Prefabs/Character/" + character), parent.transform); ChessCharacter script = unit.GetComponent <Skeleton>() ? (ChessCharacter)unit.GetComponent <Skeleton>() : unit.GetComponent <Knight>(); script.enabled = false; unit.transform.localScale = new Vector3(200, 200); parent.GetComponentInChildren <Text>().text = character; } }
private bool ChangeState(int range, ChessCharacter.eState state) { ChessCharacter targetCharacter = FindAdjacentTarget(range); if (targetCharacter != null) { if (range <= _cCharacter._attackRange) { _cCharacter.SetAttackTarget(targetCharacter); } else { _cCharacter.SetMoveTarget(targetCharacter); } _cCharacter.SetState(state); return(true); } return(false); }
public void SavePlayerList() { lastPlayerNameList.Clear(); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { ChessTile chessTile = tilemap.GetTile <ChessTile>(new Vector3Int(j, i, 0)); if (chessTile) { if (chessTile.gameObject) { if (chessTile.gameObject.name.Contains("Player")) { ChessCharacter character = chessTile.gameObject.GetComponent <ChessCharacter>(); lastPlayerNameList.Add(GetSpawnCharacterInfo(character.GetChessCharacterType(), chessTile.GetTilePosition().x, chessTile.GetTilePosition().y)); } } } } } }
protected virtual void InitData() { // 데이터들 초기 세팅 _battleState = eCharacterBattleState.BATTLE; Debug.Log("InitData in ChessCharacter"); _direction = Direction.RIGHT; transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); transform.position = tilemap.layoutGrid.CellToWorld(tilePosition); _pathFindQueue = new Queue <ChessTile>(); _pathStack = new Stack <ChessTile>(); _attackTarget = null; Debug.Log(this.name + " : Start Position tileX : " + tilePosition.x + " | tileY : " + tilePosition.y); tilemap.SetColliderType(tilePosition, Tile.ColliderType.Grid); _hp = maxHp; animator = GetComponent <Animator>(); animator.SetBool("isMoving", false); animator.SetBool("isDead", false); }
public override void InitState(ChessCharacter cCharacter) { base.InitState(cCharacter); }
public override void UpdateState() { base.UpdateState(); if (pathState == ePathState.PATH_FIND) { Debug.Log("[" + _cCharacter.name + "]ePathState.PATH_FIND"); // 경로대로 이동 종료 if (_cCharacter.GetTilePosition() == _cCharacter.GetMoveTarget().GetTilePosition()) //목표 == 현재 내 위치일 때 { Debug.Log("[" + _cCharacter.name + "] 목표 도착"); _cCharacter.SetState(ChessCharacter.eState.IDLE); return; } if (targetTile.GetTilePosition() != _cCharacter.GetTilePosition()) { Debug.Log("적 위치 변경으로 재탐색"); _cCharacter.SetState(ChessCharacter.eState.IDLE); return; } //경로 상의 다음 타일 세팅 aimTile = _cCharacter.PopPathStackTile(); if (aimTile != null && _cCharacter.CanMoveTile(aimTile.GetTilePosition())) { //Debug.Log("ePathState.PATH_FIND canMove"); //이동 방향 설정 Vector3Int dirctionVector = aimTile.GetTilePosition() - _cCharacter.GetTilePosition(); ChessCharacter.Direction direction = ChessCharacter.Direction.RIGHT; if (dirctionVector == Vector3Int.up) { direction = ChessCharacter.Direction.UP; } else if (dirctionVector == Vector3Int.down) { direction = ChessCharacter.Direction.DOWN; } else if (dirctionVector == Vector3Int.left) { direction = ChessCharacter.Direction.LEFT; } else if (dirctionVector == Vector3Int.right) { direction = ChessCharacter.Direction.RIGHT; } _cCharacter.SetDirection(direction); //이동하는 타일로 캐릭 정보 이동 GameManager.gameInstance.tilemap.SetColliderType(_cCharacter.GetTilePosition(), Tile.ColliderType.None); GameManager.gameInstance.SetTileObject(_cCharacter.GetTilePosition(), null); _cCharacter.SetTilePosition(aimTile.GetTilePosition()); pathState = ePathState.PATH_MOVE; } else { Debug.Log("ePathState.PATH_FIND can't Move"); // 다음 이동 타일에 배치된 오브젝트 있으면 그 대상 공격하기 if (aimTile != null && aimTile.gameObject != null) { ChessCharacter attackTargetCharacter = aimTile.gameObject.GetComponent <ChessCharacter>(); if (attackTargetCharacter != null) { if (_cCharacter.GetCharacterType() != attackTargetCharacter.GetCharacterType() && attackTargetCharacter.GetCharacterType() != ChessCharacter.eCharacterType.WAIT) // 적일 때만 공격 시킨다. { _cCharacter.SetAttackTarget(attackTargetCharacter); _cCharacter.SetState(ChessCharacter.eState.ATTACK); } } } else { _cCharacter.SetState(ChessCharacter.eState.IDLE); } } } else if (pathState == ePathState.PATH_MOVE) { //Debug.Log("ePathState.PATH_MOVE"); //현재 타일 > 다음 타일로의 이동 Vector3 aimPosition = GameManager.gameInstance.tilemap.layoutGrid.CellToWorld(aimTile.GetTilePosition()); _cCharacter.transform.position = Vector3.MoveTowards(_cCharacter.transform.position, aimPosition, _cCharacter.moveSpeed * Time.deltaTime); if (Vector3.Distance(_cCharacter.transform.position, aimPosition) == 0.0f) { pathState = ePathState.PATH_FIND; } } }
public void SetAttackTarget(ChessCharacter tileCharacter) { _attackTarget = tileCharacter; }
public void SetMoveTarget(ChessCharacter moveTarget) { _moveTarget = moveTarget; }
public virtual void InitState(ChessCharacter cCharacter) { _cCharacter = cCharacter; }