// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { m_aiSpawnUnit = animator.GetBehaviour <AISpawnUnit> (); m_listeUnits.Clear(); for (int i = 0; i < m_listeTypeUnits.Count; i++) { for (int j = 0; j < m_listeNbUnits[i]; j++) { m_listeUnits.Add(m_listeTypeUnits[i]); } } m_listeSpawnUnits[m_indexSpanwUnits].SetUnitsQueue(m_listeUnits); m_aiSpawnUnit.SetIndexSpawUnits(m_indexSpanwUnits); m_aiSpawnUnit.SetListeSpawnUnits(m_listeSpawnUnits); animator.SetTrigger(Constant.BotTransition.s_spawnUnit); m_aiSpawnUnit = animator.GetBehaviour <AISpawnUnit>(); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { for (int i = 0; i < m_botSpawnUnits.Count; i++) { if (m_playerSpawnUnits[i].IsSpawning()) // unitsQueue player pas vide { if (!m_botSpawnUnits[i].IsSpawning()) // unitsQueue bot vide { m_unitsQueue = m_playerSpawnUnits[i].GetUnitsQueue(); m_botSpawnUnits[i].SetUnitsQueue(m_unitsQueue); } m_aiSpawnUnit.SetIndexSpawUnits(i); m_aiSpawnUnit.SetListeSpawnUnits(m_botSpawnUnits); animator.SetTrigger(Constant.BotTransition.s_spawnUnit); } } }
public void MakeAction(Animator animator) { float ratio = Random.Range(0f, 1f); if (ratio < m_unitSpawnRatio) // SpawnUnits { int idSpawnUnit = Random.Range(0, m_botSpawnUnits.Count); Constant.SpawnTypeUnit unitType = m_listSpawnTypeUnit[Random.Range(0, m_listSpawnTypeUnit.Count)]; GameObject prefabTemp = GameManager.Instance.GetUnitForPlayer(unitType); if (GameManager.Instance.GetPlayer(PlayerEntity.Player.Bot).GetUnitGold() >= prefabTemp.GetComponent <UnitController>().GetUnitCost()) { m_unitsQueue.Clear(); m_unitsQueue.Add(unitType); m_botSpawnUnits[idSpawnUnit].SetUnitsQueue(m_unitsQueue); } m_aiSpawnUnit.SetIndexSpawUnits(idSpawnUnit); m_aiSpawnUnit.SetListeSpawnUnits(m_botSpawnUnits); animator.SetTrigger(Constant.BotTransition.s_spawnUnit); } else if (m_unitSpawnRatio <= ratio && ratio < m_unitSpawnRatio + m_obstaclesRatio) // Obstacles Build/Destroy { int index = Random.Range(0, m_listObstacles.Count); if (m_listObstacles[index].GetCurrentState() == ObstacleConstructor.EState.Buildable) { m_aiBuildObstacle.SetIndex(index); m_aiBuildObstacle.SetObstacleConstructorList(m_listObstacles); int typeBuildIndex = Random.Range(0, m_listSpawnTypeObstacle.Count); m_aiBuildObstacle.SetTypeBuild(m_listSpawnTypeObstacle[typeBuildIndex]); animator.SetTrigger(Constant.BotTransition.s_buildObstacle); } //if (m_listObstacles[index].GetCurrentState() == ObstacleConstructor.EState.Built) //{ // m_aiDestroyObstacle.SetIndex(index); // m_aiDestroyObstacle.SetObstacleConstructorList(m_listObstacles); // animator.SetTrigger(Constant.BotTransition.s_destroyObstacle); //} } else { m_indexCheckpoint = Random.Range(0, m_listCheckpoints.Count); if (m_unitSpawnRatio + m_obstaclesRatio <= ratio && ratio < m_unitSpawnRatio + m_obstaclesRatio + m_checkpointsReleaseAllRatio) // Checkpoints ReleaseAll { m_nbUnitsReleased = m_listCheckpoints[m_indexCheckpoint].GetNbUnitsStocked(); } else if (m_unitSpawnRatio + m_obstaclesRatio + m_checkpointsReleaseAllRatio <= ratio && ratio < m_unitSpawnRatio + m_obstaclesRatio + m_checkpointsReleaseAllRatio + m_checkpointsReleaseRatio) // Checkpoints Release { m_nbUnitsReleased = 1; } if (m_listCheckpoints[m_indexCheckpoint].GetNbUnitsStocked() >= m_nbUnitsReleased && m_nbUnitsReleased != 0) { m_aiReleaseUnits.SetListCheckpoints(m_listCheckpoints); m_aiReleaseUnits.SetIndexCheckpoint(m_indexCheckpoint); m_aiReleaseUnits.SetNbUnitsReleased(m_nbUnitsReleased); animator.SetTrigger(Constant.BotTransition.s_releaseUnits); } } }