void Update() { DrawView(); M_State(); if (bosshaert == 0) { _ms = Monster_State.Die; } }
public void ChScript(Monster_State newState) { if (isinit) { _states[currentState].enabled = false; _states[currentState].EndState(); } currentState = newState; _states[currentState].BeginState(); _states[currentState].enabled = true; }
IEnumerator Check_Player() { while (isAlive) { Vector3 dirToTarget = (target.position - transform.position).normalized; //_transform.forward와 dirToTarget은 모두 단위벡터이므로 내적값은 두 벡터가 이루는 각의 Cos값과 같다. //내적값이 시야각/2의 Cos값보다 크면 시야에 들어온 것이다. if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((ViewAngle / 2) * Mathf.Deg2Rad)) //if (Vector3.Angle(_transform.forward, dirToTarget) < ViewAngle/2) { float distToTarget = Vector3.Distance(transform.position, target.position); // Debug.Log("거리 : " + distToTarget); tmpPos = target.position; if (Physics.Raycast(transform.position, dirToTarget, distToTarget, mask)) { Debug.DrawLine(transform.position, target.position, Color.red); // Player가 시야 내에 있는 경우 isParallel = Angle_IsNan(); if (isParallel) { _ms = Monster_State.Attack; isParallel = false; } // 마주 보고 있으면 공격 else { _ms = Monster_State.TargetTrace; } // 그렇지 않으면 추적 } yield return(new WaitForSeconds(check_delayTime)); } else { //Player가 시야 내에 없는 경우 Debug.DrawLine(transform.position, target.position, Color.red); _ms = Monster_State.TargetTrace; yield return(new WaitForSeconds(check_delayTime)); } } }
/// <summary> /// 删除状态 /// </summary> /// <param name="state">需要删除的状态</param> /// <returns></returns> public bool DeleteState(Monster_State state) { if (state == Monster_State.NullState) { return(false); } else if (states.ContainsKey(state) == false) { return(false); } else { states.Remove(state); return(true); } }
/// <summary> /// 添加转换条件 /// </summary> /// <param name="trans">转换条件</param> /// <param name="stateID">转换的目标状态</param> public void Addtransition(Transition trans, Monster_State monster_State) { if (trans == Transition.NullTrans) { return; } else if (monster_State == Monster_State.NullState) { return; } else if (transition.ContainsKey(trans)) { return; } transition.Add(trans, monster_State); }
public void PerformTransition(Transition trans) { if (trans == Transition.NullTrans) { return; } Monster_State targetstate = currentstate.GetMonster_State(trans); if (states.ContainsKey(targetstate) == false) { return; } FSM_MonsterS Targetstate = states[targetstate]; /*currentstate.DowhileStart(); * currentstate.DowhileEnd();*/ currentstate = Targetstate; }
IEnumerator Co_Die() { switch (PlayManager.instance.Stage_State) { case Stage_State.stage: PlayManager.instance.Change_State(Player_State.Run); Add_Stage_Data(); UiManager.instance.Check_Progress_Reward(Progress_Reward_Type.monster, 1); break; case Stage_State.underground: PlayManager.instance.Change_State(Player_State.Run); if (monster_Type.Equals(Monster_Type.underground_Boss)) { Underground_.underground_Info.int_Max_Boss += 1; } else { Underground_.underground_Info.int_Max_Monster += 1; } UiManager.instance.Set_Underground_Info(); Underground_.Get_Underground_Random_Item(); break; case Stage_State.upgrade: PlayManager.instance.Change_State(Player_State.Reward); UiManager.instance.Set_Upgrade_Reward(true); PlayManager.instance.End_Upgrade(); break; case Stage_State.hell: PlayManager.instance.Change_State(Player_State.Run); Hell_.int_Max_Monster += 1; UiManager.instance.Set_Hell_Info(); break; default: break; } monster_State = Monster_State.Die; anim_Monster.Play("die"); switch (monster_Type) { case Monster_Type.Basic: PlayManager.instance.Set_Monster(); Game_info_.Set_Game_Info(Game_Info_Type.monster, 1); Quest_.Check_Daily_Quest(Daily_Quest_Type.monster, 1); break; case Monster_Type.Boss: PlayManager.instance.Stop_Boss_Timer(false); Game_info_.Set_Game_Info(Game_Info_Type.boss, 1); break; case Monster_Type.underground_Boss: PlayManager.instance.Set_Monster(); break; case Monster_Type.upgrade_Boss: break; case Monster_Type.hell_Boss: PlayManager.instance.Set_Monster(); break; case Monster_Type.goblin: Item item = Item_s.Get_Random_Goblin_Item(); BackEndDataManager.instance.Set_Item((Item_Type)item.item_num, item.val, Calculate_Type.plus); PlayManager.instance.Set_Monster(); Game_info_.Set_Game_Info(Game_Info_Type.gold_goblin, 1); break; default: break; } yield return(new WaitForSeconds(1.0f)); Destroy(gameObject); }
IEnumerator Check_Player() { while (true) { Vector3 dirToTarget = (target.position - transform.position).normalized; //_transform.forward와 dirToTarget은 모두 단위벡터이므로 내적값은 두 벡터가 이루는 각의 Cos값과 같다. //내적값이 시야각/2의 Cos값보다 크면 시야에 들어온 것이다. if (Vector3.Dot(transform.forward, dirToTarget) > Mathf.Cos((ViewAngle / 2) * Mathf.Deg2Rad)) //if (Vector3.Angle(_transform.forward, dirToTarget) < ViewAngle/2) { float distToTarget = Vector3.Distance(transform.position, target.position); tmpPos = target.position; if (Physics.Raycast(transform.position, dirToTarget, distToTarget)) { Debug.DrawLine(transform.position, target.position, Color.red); //Debug.Log("시야 내에 존재"); // Player가 시야 내에 있는 경우 // 시야 내에 있지만 서로 마주보고 있지않는 경우 // - 범위 공격 isParallel = Angle_IsNan(); if (isParallel) { // Debug.Log("집중 공격"); n = 0; _ms = Monster_State.Attack; isParallel = false; } else { n = 1; _ms = Monster_State.Attack; //Debug.Log("범위 공격"); } // 시야 내에 서로 마주보고 있는 경우 // - 집중 공격 // _ms = Monster_State.Attack; // isPlayer = true; } yield return(new WaitForSeconds(5f)); } else { //Player가 시야 내에 없는 경우 // 1. 플레이어 추적하기 // 2. 전체 공격 target_pos = (target.position - transform.position); float dot2 = Vector3.Dot(transform.forward, target_pos); Debug.Log("시야 내에 존재 하지않음"); // Debug.Log(Mathf.Cos(dot2)); int ran = Random.Range(0, 1); if (Mathf.Cos(dot2) < 0) { if (ran == 0) { n = 2; _ms = Monster_State.Attack; } else { _ms = Monster_State.TargetTrace; } // Debug.Log(" 뒤 : 전체 공격 or Trace"); } else { if (ran == 0) { n = 1; _ms = Monster_State.Attack; } else { _ms = Monster_State.TargetTrace; } //Debug.Log("Trace or 범위 공격"); } yield return(new WaitForSeconds(5f)); } } }