/// <summary> /// 待機状態 /// </summary> void Idle() { float timeInterval = 2.0f; if (timer > timeInterval) { state = CustomerAIState.CHECK; } }
/// <summary> /// 移動 /// </summary> void Move() { agent.SetDestination(movePosObj.transform.position); if (Vector3.Distance(transform.position, movePosObj.transform.position) < 0.5f) { timer = 0; state = CustomerAIState.ACTION; } }
//State machine public void ChangeState(CustomerAIState newState) { switch (newState) { case CustomerAIState.Shopping: if (m_targetShop != null) { if (m_shoppingList.Contains(m_targetShop) && m_targetShop.ShoppingAmount < 0.0f) { m_shoppingList.Remove(m_targetShop); PickNextShop(); } else { RequestShopPath(m_targetShop.ShopObject); } } else { PickNextShop(); } Speed = 5.0f; break; case CustomerAIState.Hungry: m_targetShop = new ShopData(); m_targetShop.ShopObject = OverSeer.GetShop(Shop.ShopEnum.Cafe); m_targetShop.ShoppingAmount = Hunger; RequestShopPath(m_targetShop.ShopObject); Speed = 5.0f; break; case CustomerAIState.Pissed: m_targetShop = new ShopData(); m_targetShop.ShopObject = OverSeer.GetShop(Shop.ShopEnum.WC, Random.Range(1, 3)); m_targetShop.ShoppingAmount = Bladder; RequestShopPath(m_targetShop.ShopObject); Speed = 7.5f; break; case CustomerAIState.Running: RequestExitPath(); Speed = 10; break; case CustomerAIState.Satisfied: RequestExitPath(); Speed = 5.0f; break; default: break; } CustomerState = newState; }
// Use this for initialization void Start() { // 初期化 agent = GetComponent <NavMeshAgent>(); // シーン上にある棚オブジェクトを全取得 shelfObj = GameObject.FindGameObjectsWithTag("Shelf"); // シーン上にあるレジオブジェクトを全取得 registerObj = GameObject.FindGameObjectsWithTag("Register"); // 初期ステートの設定 state = CustomerAIState.CHECK; }
void RegisterAction() { actionObj.GetComponent <RegisterEvent>().IsCustomer = true; if (actionObj.GetComponent <RegisterEvent>().IsPlayerActionEnd) { actionObj.GetComponent <RegisterEvent>().IsCustomer = false; isMoveEnd = true; movePosObj = GameObject.Find("EntryPos"); state = CustomerAIState.REGISTERMOVE; } }
void RegisterIdle() { if (registerNum <= 0) { actionObj.GetComponent <RegisterEvent>().IsPlayerActionEnd = false; state = CustomerAIState.REGISTERACTION; } else if (actionObj.GetComponent <RegisterEvent>().IsAIMoveLine(registerNum)) { movePosObj = actionObj.GetComponent <RegisterEvent>().AIMoveLineObj(registerNum); registerNum--; state = CustomerAIState.REGISTERMOVE; } }
/// <summary> /// ギミックの発動 /// </summary> void Action() { float timeInterval = 2.0f; if (timer > timeInterval) { actionObj.GetComponent <ItemStockEvent>().StockDecrement(1); actionObj.GetComponent <ItemStockEvent>().IsAIMoveRelease(movePosObj); stockCount++; state = CustomerAIState.CHECK; } }
void RegisterMove() { agent.SetDestination(movePosObj.transform.position); if (Vector3.Distance(transform.position, movePosObj.transform.position) < 0.5f) { if (isMoveEnd) { AIGenerator.Instance.RemoveList(gameObject); Destroy(gameObject); } else { state = CustomerAIState.REGISTERIDLE; } } }
/// <summary> /// 移動先の検索とその後の行動を指定 /// </summary> void Check() { List <GameObject> canMovePosObjcts = new List <GameObject>(); for (int i = 0; i < shelfObj.Length; i++) { if (shelfObj[i].GetComponent <ItemStockEvent>().CheckPos() && shelfObj[i] != actionObj && stockCount < 4) { canMovePosObjcts.Add(shelfObj[i]); } } for (int i = 0; i < registerObj.Length; i++) { if (registerObj[i].GetComponent <RegisterEvent>().CheckPos() && stockCount > 0) { canMovePosObjcts.Add(registerObj[i]); } } if (canMovePosObjcts.Count > 0) { int rnd = Random.Range(0, canMovePosObjcts.Count); actionObj = canMovePosObjcts[rnd]; if (actionObj.GetComponent <ItemStockEvent>()) { movePosObj = actionObj.GetComponent <ItemStockEvent>().AIMovePosObj(); state = CustomerAIState.MOVE; } else { registerNum = actionObj.GetComponent <RegisterEvent>().AIMovePosObjNum(); movePosObj = actionObj.GetComponent <RegisterEvent>().AIMovePosObj(); state = CustomerAIState.REGISTERMOVE; } } else { timer = 0; state = CustomerAIState.IDLE; } }