public void MoveEmber() { // 빈 영역 확인 EmberArea.Clear(); for (int y = -2; y <= 2; y++) { for (int x = -2; x <= 2; x++) { Vector3Int tempPos = tilePos + new Vector3Int(x, y, 0); if (!TileMgr.Instance.ExistObject(tempPos, floor) && !TileMgr.Instance.ExistEnvironment(tempPos, floor)) { EmberArea.Add(tempPos); } } } if (EmberArea.Count == 0) { Ember.SetActive(false); return; } int index = Random.Range(0, EmberArea.Count); Vector3Int nPos = EmberArea[index]; Ember.transform.position = TileMgr.Instance.CellToWorld(nPos, floor); Ember.GetComponent <SortingGroup>().sortingOrder = TileMgr.GetOrder(Ember.transform.position, nPos); Ember.SetActive(true); }
public static void CreateInstance(int stage) { if (m_instance != null) { Debug.Log("Destroy TileMgr"); m_instance = null; } m_instance = new TileMgr(stage); }
public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go) { if (go != null && TileMgr.Instance != null) { int order = TileMgr.GetOrder(go.transform.position, position); go.GetComponent <SortingGroup>().sortingOrder = order; } return(base.StartUp(position, tilemap, go)); }
protected virtual void Start() { _currento2 = _maxo2; _currentHp = _maxHp; rbody = GetComponent <Rigidbody2D>(); // Sorting Order 수정 int order = TileMgr.GetOrder(transform.position, _currentTilePos); GetComponent <SortingGroup>().sortingOrder = order; }
IEnumerator MoveTile() { yield return(null); _anim.SetBool("IsRunning", true); for (int i = 0; i < _panicMoveCount; i++) { Vector3Int pPos = TileMgr.Instance.WorldToCell(transform.position, floor); Vector3Int nPos; while (true) { int randx = Random.Range(-1, 2); int randy = Random.Range(-1, 2); nPos = pPos + new Vector3Int(randx, randy, 0); if (GameMgr.Instance.GetSurvivorAt(nPos, floor) != null) { continue; } break; } Vector3 arrivePos = TileMgr.Instance.CellToWorld(nPos, floor); float delta = _speed * Time.deltaTime; while (Vector3.Distance(arrivePos, transform.position) > delta) { transform.position = Vector3.MoveTowards(transform.position, arrivePos, delta); yield return(null); } transform.position = arrivePos; _currentTilePos = nPos; // Sorting Order 수정 int order = TileMgr.GetOrder(transform.position, _currentTilePos); GetComponent <SortingGroup>().sortingOrder = order; } _anim.SetBool("IsRunning", false); _moveDone = true; }
public World(int W = 20, int H = 20) { Tiles = new Tile[W, H]; this.W = W; this.H = H; Tile Bottom = new Tile(TileMgr.GetTileTex(1), false); Tile Wall = new Tile(TileMgr.GetTileTex(2), true); for (int x = 0; x < W; x++) { for (int y = 0; y < H; y++) { Tiles[x, y] = Bottom; } } Tiles[5, 3] = Tiles[5, 4] = Tiles[5, 5] = Tiles[5, 6] = Tiles[5, 7] = Wall; Tiles[6, 3] = Tiles[7, 3] = Tiles[8, 3] = Wall; Tiles[6, 7] = Tiles[7, 7] = Tiles[8, 7] = Wall; }
/// <summary> /// /// </summary> static Tile() { T = new Sprite(TileMgr.GetTileTex(0)); }
public override void Move() { base.Move(); float hor = Input.GetAxisRaw("Horizontal"); // 가속도 없는 Raw값 사용 float ver = Input.GetAxisRaw("Vertical"); if (CurrentHP <= 0 || CurrentO2 <= 0 || _currentMental <= 0 || playerAct == Action.Carry || playerAct == Action.MoveFloor || playerAct == Action.ActiveUlt || (hor == 0.0f && ver == 0.0f)) { // 이동 종료 rbody.velocity = Vector3.zero; // 애니메이션 종료 if (_anim != null) { if (_anim.GetBool("IsRunning")) { _anim.SetBool("IsRunning", false); SoundManager_Walk.instance.StopSound();//걷는 소리 정지 } } return; } // 캐릭터 이동 Vector3 dir = new Vector3(hor, ver, 0.0f); dir /= dir.magnitude; rbody.velocity = dir * _movespeed; _currentTilePos = TileMgr.Instance.WorldToCell(transform.position, floor); // Sorting Order 수정 int order = TileMgr.GetOrder(transform.position, _currentTilePos); GetComponent <SortingGroup>().sortingOrder = order; // 이동 방향에 따라 캐릭터 이미지 회전 bool isRight = hor > 0; if (isRight) { if (_body.rotation.y != 180) { _body.rotation = new Quaternion(0, 180.0f, 0, transform.rotation.w); } } else { if (_body.rotation.y != 0) { _body.rotation = Quaternion.identity; } } // 애니메이션 시작 if (_anim != null) { if (!_anim.GetBool("IsRunning")) { _anim.SetBool("IsRunning", true); SoundManager_Walk.instance.PlayWalkSound();//걷는소리 재생 } } // 산소 소비 float o2UseRate = 1.0f; if (isInGas) { o2UseRate *= 1.5f; } if (playerAct == Action.Rescue) { o2UseRate *= 1.5f; } AddO2(-UseO2 * o2UseRate * Time.deltaTime); // 트리거 실행 GameMgr.Instance.OnMovePlayer(currentTilePos, floor); }
private void StageSetup() { // Create TileMgr Instance TileMgr.CreateInstance(stage); TalkMgr.CreateInstance(stage); // Load XML XmlDocument doc = new XmlDocument(); TextAsset textAsset = (TextAsset)Resources.Load("Stage/Stage" + stage); doc.LoadXml(textAsset.text); XmlNode stageNode = doc.SelectSingleNode("Stage"); string startTimeStr = stageNode.SelectSingleNode("StartTime").InnerText; string[] startTimeTokens = startTimeStr.Split(':'); currTime = int.Parse(startTimeTokens[0]) * 60 + int.Parse(startTimeTokens[1]); // Stage Content string stageNamePreviewText = stageNode.SelectSingleNode("StageNamePreview").InnerText; string stageNameText = stageNode.SelectSingleNode("StageName").InnerText; string stageContentText = stageNode.SelectSingleNode("StageContent").InnerText; string[] stageContentLines = stageContentText.Split('\n'); for (int i = 1; i < stageContentLines.Length; i++) { stageContentLines[i] = stageContentLines[i].Trim(); } for (int i = 1; i <= 2 && i < stageContentLines.Length; i++) { stageContentLines[i] = " " + stageContentLines[i]; } stageContentText = ""; for (int i = 1; i < stageContentLines.Length; i++) { stageContentText += stageContentLines[i] + "\n"; } // Disaster & Goal & PlayState XmlNode disastersNode = stageNode.SelectSingleNode("Disasters"); XmlNode goalsNode = stageNode.SelectSingleNode("Goals"); disasterMgr = new DisasterMgr(disastersNode); goalMgr = new GoalMgr(goalsNode); gameInfo = new GameInfo(stage); gameInfo.CurrTime = currTime; gameInfo.Deadline = goalMgr.GetDeadline(); StartCoroutine(disasterMgr.UpdateWillActiveDisasterArea()); // 다음 턴 재난 지역 타일맵에 동기화 // Load Canvas GameObject canvas = GameObject.Find("UICanvas"); selectCanvas = canvas.transform.Find("SelectCanvas").GetComponent <Canvas>(); playCanvas = canvas.transform.Find("PlayCanvas").GetComponent <Canvas>(); reportCanvas = canvas.transform.Find("ReportCanvas").GetComponent <Canvas>(); selectCanvas.enabled = false; playCanvas.enabled = false; reportCanvas.enabled = false; // Load Select UI Transform operatorCard = selectCanvas.transform.Find("OperatorSelect/OperatorCard"); operatorCardNum = 0; for (int i = 0; i < operatorCard.childCount; i++) { GameObject go = operatorCard.GetChild(i).gameObject; if (go.activeSelf) { operatorCards[i] = go; operatorCardNum++; } } selectCanvas.transform.Find("StageGoal/StageNamePreview").GetComponentInChildren <Text>().text = stageNamePreviewText; Text stageName = selectCanvas.transform.Find("StageGoal/StageName").GetComponent <Text>(); stageName.text = stageNameText; stageName.rectTransform.sizeDelta = new Vector2(stageName.preferredWidth, stageName.preferredHeight); RectTransform stageBar = selectCanvas.transform.Find("StageGoal/StageBar").GetComponent <RectTransform>(); stageBar.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, stageName.rectTransform.rect.width + 20); GameObject goalPrefab = Resources.Load <GameObject>("Prefabs/UI/SelectUI_Goal"); Transform goals = selectCanvas.transform.Find("StageGoal/Goals"); List <Goal> mainGoals = goalMgr.GetMainGoals(); for (int i = 0; i < mainGoals.Count; i++) { string explanation = mainGoals[i].GetExplanationText(); string status = mainGoals[i].GetStatusText(); GameObject goal = Instantiate(goalPrefab, goals); goal.transform.Find("Explanation").GetComponent <Text>().text = explanation; goal.transform.Find("Status").GetComponent <Text>().text = status; goal.transform.localPosition = new Vector3(0, -20 + -30 * i); } RectTransform content = selectCanvas.transform.Find("StageGoal/Content").GetComponent <RectTransform>(); content.GetComponent <Text>().text = stageContentText; content.anchoredPosition += new Vector2(0, -20 + -30 * mainGoals.Count + -20); startBtnText = selectCanvas.transform.Find("StartBtn").GetComponentInChildren <Text>(); ChangeStartBtnText(); // Load Play UI _fadeImage = playCanvas.transform.Find("Fade").GetComponent <Image>(); _mentalText = playCanvas.transform.Find("PlayerCard/CurrentMental").GetComponent <Text>(); _stateText = playCanvas.transform.Find("PlayerCard/CurrentState").GetComponent <Text>(); _charNameText = playCanvas.transform.Find("PlayerCard/Player_KorName").GetComponent <Text>(); _CardProfile = playCanvas.transform.Find("PlayerCard/Player_Image").GetComponent <Image>(); disasterAlaram = playCanvas.transform.Find("MiddleUI/DisasterAlarm").gameObject; disasterAlaramText = disasterAlaram.transform.Find("Text").GetComponent <Text>(); stageEnd = playCanvas.transform.Find("MiddleUI/StageEnd").gameObject; stageEndText = stageEnd.transform.Find("Text").GetComponent <Text>(); timerText = GameObject.Find("UICanvas/PlayCanvas/TopUI/TurnEndBtn/TimerText").GetComponent <Text>(); ChangeTimerText(); pauseMgr = new PauseMgr(goalMgr, OnPause, OnResume, OnGameExit); // Load Resources operatorPrefabs[0] = Resources.Load <GameObject>("Prefabs/Operator/Captain"); operatorPrefabs[1] = Resources.Load <GameObject>("Prefabs/Operator/HammerMan"); operatorPrefabs[2] = Resources.Load <GameObject>("Prefabs/Operator/Rescuers"); operatorPrefabs[3] = Resources.Load <GameObject>("Prefabs/Operator/Nurse"); operatorProfileImage[0] = Resources.Load <Sprite>("Sprite/PlayScene/UI/PlayerCard/IDcard-leader"); operatorProfileImage[1] = Resources.Load <Sprite>("Sprite/PlayScene/UI/PlayerCard/IDcard-hammerman"); operatorDepoyedSprite = Resources.Load <Sprite>("Sprite/PlayScene/OperatorSelect_UI/Operator/Operater_card-Depolyed"); _currGameState = GameState.SELECT_OPERATOR; }