public void ChangeState(PCState newState) { m_currentState.Exit(); m_currentState = m_statesDictionary[newState]; m_currentState.Enter(); m_currentEnumState = newState; }
private void Awake() { pcInput = GetComponent <PCInput>(); pcState = GetComponent <PCState>(); pcMove = GetComponent <PCMove>(); colliderRadius = (bodyCollider.bounds.size.x / 2f) + 0.2f; }
// ----------------------------------------------------------------------------- // Unity Events private void Awake() { pcState = GetComponent <PCState>(); pcInput = GetComponent <PCInput>(); pcMove = GetComponent <PCMove>(); pcAnim = GetComponent <PCAnim>(); currScene = SceneManager.GetActiveScene().name; defaultCamPos = camFollowPoint.localPosition; }
private void Awake() { anim = GetComponent <Animator>(); pcState = GetComponent <PCState>(); pcInput = GetComponent <PCInput>(); pcMove = GetComponent <PCMove>(); mJump = GetComponent <Move_Jump>(); mRun = GetComponent <Move_Run>(); mWallslide = GetComponent <Move_WallSlide>(); // mDash = GetComponent<Move_Dash>(); mDuck = GetComponent <Move_Duck>(); mWalk = GetComponent <Move_Walk>(); aState = State.BoxIdle; transition = true; }
void Awake() { // does the pool exist yet if (s_playerChildFSMPool == null) { // lazy initialize it s_playerChildFSMPool = new PlayerChildFSM[Constants.s_nPlayerMaxChildCount]; s_playerChildStatus = new pcStatus[Constants.s_nPlayerMaxChildCount]; s_nPoolPointerIndex = 0; s_nActiveChildCount = 0; s_childrenInRightNode = new int[] { -1 }; s_childrenInLeftNode = new int[] { -1 }; s_childrenInAttack = new int[] { -1 }; } // add myself s_playerChildFSMPool[s_nPoolPointerIndex] = this; s_playerChildStatus[s_nPoolPointerIndex] = pcStatus.DeadState; m_nPoolIndex = s_nPoolPointerIndex; s_nPoolPointerIndex++; // Cache components rigidbody2D = GetComponent <Rigidbody2D>(); collider2D = GetComponent <CircleCollider2D>(); spriteRen = GetComponent <SpriteRenderer>(); m_AudioSource = GetComponent <AudioSource>(); // Set up the m_statesDictionary. m_statesDictionary = new Dictionary <PCState, IPCState>(); m_statesDictionary.Add(PCState.Avoid, new PC_AvoidState(this)); m_statesDictionary.Add(PCState.ChargeChild, new PC_ChargeChildState(this)); m_statesDictionary.Add(PCState.ChargeMain, new PC_ChargeMainState(this)); m_statesDictionary.Add(PCState.Dead, new PC_DeadState(this)); m_statesDictionary.Add(PCState.Defend, new PC_DefendState(this)); m_statesDictionary.Add(PCState.Idle, new PC_IdleState(this)); PlayerChildFSM.IncrementActiveChildCount(); // Change to dead state. m_currentState = m_statesDictionary[PCState.Dead]; m_currentState.Enter(); m_currentEnumState = PCState.Dead; }
//Check whether the enemy main cell is being attacked by a chargeChild/chargeMain player child cell, toggle the boolean "bIsMainBeingAttacked" accordingly void IsMainBeingAttacked() { Collider2D[] IncomingObjects = Physics2D.OverlapCircleAll(transform.position, 100f * GetComponent <SpriteRenderer>().bounds.size.x, Constants.s_onlyPlayerChildLayer); PCState PCCurrentState = PCState.Dead; if (IncomingObjects.Length <= 0) { bIsMainBeingAttacked = false; return; } for (int i = 0; i < IncomingObjects.Length; i++) { PCCurrentState = IncomingObjects[i].GetComponent <PlayerChildFSM>().GetCurrentState(); if (PCCurrentState == PCState.ChargeChild || PCCurrentState == PCState.ChargeMain) { bIsMainBeingAttacked = true; return; } } bIsMainBeingAttacked = false; }
//A function that return a GameObject variable on the closest attacking player child cell private GameObject GetClosestAttacker() { GameObject ClosestAttacker = null; float Distance = Mathf.Infinity; if (IsthereBurstShot()) { for (int i = 0; i < PlayerChildFSM.playerChildPool.Length; i++) { if (PlayerChildFSM.playerChildPool[i].attackMode == PlayerAttackMode.BurstShot && Utility.Distance(PlayerChildFSM.playerChildPool[i].transform.position, m_ecFSM.m_EMain.transform.position) < Distance) { ClosestAttacker = PlayerChildFSM.playerChildPool[i].gameObject; Distance = Utility.Distance(PlayerChildFSM.playerChildPool[i].transform.position, m_ecFSM.m_EMain.transform.position); } } } else { GameObject[] PlayerChilds = GameObject.FindGameObjectsWithTag(Constants.s_strPlayerChildTag); float ECtoPCDistance = 0f; PCState PCCurrentState = PCState.Idle; for (int i = 0; i < PlayerChilds.Length; i++) { ECtoPCDistance = Utility.Distance(PlayerChilds[i].transform.position, m_Child.transform.position); PCCurrentState = PlayerChilds[i].GetComponent <PlayerChildFSM>().GetCurrentState(); if ((PCCurrentState == PCState.ChargeChild || PCCurrentState == PCState.ChargeMain) && ECtoPCDistance < Distance) { ClosestAttacker = PlayerChilds[i]; Distance = ECtoPCDistance; } } } return(ClosestAttacker); }
// [[ ----- AWAKE ----- ]] private void Awake() { pcInput = GetComponent <PCInput>(); pcState = GetComponent <PCState>(); }
private void Awake() { pcState = GetComponent <PCState>(); }
void Awake() { // does the pool exist yet if (s_playerChildFSMPool == null) { // lazy initialize it s_playerChildFSMPool = new PlayerChildFSM[Constants.s_nPlayerMaxChildCount]; s_playerChildStatus = new pcStatus[Constants.s_nPlayerMaxChildCount]; s_nPoolPointerIndex = 0; s_nActiveChildCount = 0; s_childrenInRightNode = new int[] {-1}; s_childrenInLeftNode = new int[] {-1}; s_childrenInAttack = new int[] {-1}; } // add myself s_playerChildFSMPool[s_nPoolPointerIndex] = this; s_playerChildStatus[s_nPoolPointerIndex] = pcStatus.DeadState; m_nPoolIndex = s_nPoolPointerIndex; s_nPoolPointerIndex++; // Cache components rigidbody2D = GetComponent<Rigidbody2D>(); collider2D = GetComponent<CircleCollider2D>(); spriteRen = GetComponent<SpriteRenderer>(); m_AudioSource = GetComponent<AudioSource>(); // Set up the m_statesDictionary. m_statesDictionary = new Dictionary<PCState, IPCState>(); m_statesDictionary.Add(PCState.Avoid, new PC_AvoidState(this)); m_statesDictionary.Add(PCState.ChargeChild, new PC_ChargeChildState(this)); m_statesDictionary.Add(PCState.ChargeMain, new PC_ChargeMainState(this)); m_statesDictionary.Add(PCState.Dead, new PC_DeadState(this)); m_statesDictionary.Add(PCState.Defend, new PC_DefendState(this)); m_statesDictionary.Add(PCState.Idle, new PC_IdleState(this)); PlayerChildFSM.IncrementActiveChildCount(); // Change to dead state. m_currentState = m_statesDictionary[PCState.Dead]; m_currentState.Enter(); m_currentEnumState = PCState.Dead; }
public void DeferredChangeState(PCState newState) { m_deferredState = newState; m_bHasAwaitingDeferredStateChange = true; }
/// <param name="state"></param> /// <remarks>Unity still doesn't support enums on UnityEvents.</remarks> public void ToggleState(int state) { this.state = (PCState)state; }
private void InvertState() { state = (state == PCState.BROKEN) ? PCState.FIXED : PCState.BROKEN; }
private GameObject FindTargetChild() { //Find the node to obtain a target child by evaluating which node is the most threatening if (m_TargetSource == null) { GameObject Source = m_ecFSM.m_AttackTarget; if (Source == null) { return(null); } m_TargetSource = Source; } m_TargetEndPos = m_TargetSource.transform.position; //If the target to obtain a child cell to attack is any of the two nodes, loop through the cells within that specific node to get the closest child cell to the enemy child cell if (m_TargetSource.name.Contains("Node")) { List <PlayerChildFSM> m_PotentialTargets = new List <PlayerChildFSM>(); if (m_TargetSource.name.Contains("Left")) { for (int i = 0; i < PlayerChildFSM.childrenInLeftNode.Length - 1; i++) { if (PlayerChildFSM.childrenInLeftNode[i] == -1) { break; } m_PotentialTargets.Add(PlayerChildFSM.playerChildPool[PlayerChildFSM.childrenInLeftNode[i]]); } } else if (m_TargetSource.name.Contains("Right")) { for (int i = 0; i < PlayerChildFSM.childrenInRightNode.Length - 1; i++) { if (PlayerChildFSM.childrenInRightNode[i] == -1) { break; } m_PotentialTargets.Add(PlayerChildFSM.playerChildPool[PlayerChildFSM.childrenInRightNode[i]]); } } float fDistanceBetween = Mathf.Infinity; GameObject m_TargetCell = null; float ChildToPotentialTarget = 0f; PCState TargetCurrentState = PCState.Idle; for (int i = 0; i < m_PotentialTargets.Count; i++) { ChildToPotentialTarget = Utility.Distance(m_Child.transform.position, m_PotentialTargets[i].transform.position); TargetCurrentState = m_PotentialTargets[i].GetCurrentState(); if (CheckIfTargetIsAvailable(m_PotentialTargets[i].gameObject) && ChildToPotentialTarget < fDistanceBetween && TargetCurrentState != PCState.Dead && TargetCurrentState != PCState.Avoid) { fDistanceBetween = ChildToPotentialTarget; m_TargetCell = m_PotentialTargets[i].gameObject; break; } } if (m_TargetCell != null) { return(m_TargetCell); } } //Else If the target to obtain a child cell to attack is the squad captain cell, loop through the cells within that squad to get the closest child cell to the enemy child cell else if (m_TargetSource.name.Contains("Squad")) { List <SquadChildFSM> m_PotentialTargets = SquadChildFSM.GetAliveChildList(); if (m_PotentialTargets.Count <= 0) { return(null); } SquadChildFSM ClosestSquadChild = m_PotentialTargets[0]; float ChildToSquadChild = 0f; float ClosestDistance = Mathf.Infinity; for (int i = 0; i < m_PotentialTargets.Count; i++) { ChildToSquadChild = Utility.Distance(m_Child.transform.position, m_PotentialTargets[i].transform.position); if (ChildToSquadChild < ClosestDistance) { ClosestSquadChild = m_PotentialTargets[i]; ClosestDistance = ChildToSquadChild; } } m_ecFSM.Target = ClosestSquadChild.gameObject; return(m_ecFSM.Target); } //If there is no target for the child cell, transition it back to idle state return(null); }