protected bool CheckUnit(Unit aUnit) { Vector3 direction = (aUnit.transform.position - owner.transform.position).normalized; float cosAngle = Mathf.Cos(m_Arc * 0.5f); float angle = Vector3.Dot(direction, owner.transform.forward); if(angle > cosAngle && Vector3.Distance(aUnit.transform.position,owner.transform.position) < m_Distance) { return true; } return false; }
protected override void OnGameEvent(GameEventID aEventType) { if (aEventType == GameEventID.UNIT_KILLED) { Unit sender = eventData.sender as Unit; if (sender != null && sender.unitName == playerName) { unit = sender; StartCoroutine(Revive()); } } }
private void TeachAbilities(Unit unit) { IEnumerator ability = m_Abilities.GetEnumerator(); while (ability.MoveNext()) { Ability current = ability.Current as Ability; if (current == null) { continue; } DebugUtils.Log("Teaching " + unit.unitName + " ability " + current.abilityName); unit.AddAbility(current); } enabled = false; }
IEnumerator LateEnable() { yield return new WaitForEndOfFrame(); if (m_Unit == null) { m_Unit = UnitManager.GetUnit(m_UnitName); } UIImage resourceBar = UIManager.Find<UIImage>(m_BarName); if (resourceBar != null) { m_BarMaterial = resourceBar.renderer.material; if (m_BarMaterial != null && m_BarMaterial.shader.name == UIUtilities.SHADER_CUTOFF_TRANSPARENT) { m_BarMaterial.SetFloat(UIUtilities.SHADER_CUTOFF_Y, 1.0f); } } }
/// <summary> /// The conditions a unit must meet in order for the AI to chase it /// This condition does a raycast to check for vision and checks the unit type to be a player /// </summary> /// <param name="aUnit">The unit being tested.</param> /// <returns></returns> protected virtual bool SearchCondition(Unit aUnit) { Vector3 direction = (aUnit.transform.position - transform.position).normalized; Vector3 origin = transform.position; float distance = Vector3.Distance(aUnit.transform.position, transform.position); ///Check if the unit is beyond max distance if(distance > m_MaxDistance) { return false; } ///Verify in line of sight and not in minimum distance range float angle = Vector3.Dot(direction, transform.forward); float cosAngle = Mathf.Cos(m_VisionAngle * 0.5f); if(angle < cosAngle && distance > m_MinDistance) { return false; } ///Raycast RaycastHit hit; if (!Physics.Raycast(origin, direction, out hit, distance + m_DistanceCorrection, m_SearchLayerMask)) { //DebugUtils.LogWarning("Raycast search for unit Missed"); return false; //Missed?? } //DebugUtils.Log("Hit" + hit.collider.name + "\nLayer = " + (1 << hit.collider.gameObject.layer)); if((1 << hit.collider.gameObject.layer) == Game.LAYER_SURFACE) { return false; } ///Verify unit type return aUnit.unitType == UnitType.PLAYER; }
public void Start() { m_Unit = GetComponent<Unit>(); }
private void Start() { m_Motor = GetComponent<AIMotor>(); m_Unit = GetComponent<Unit>(); }
// Use this for initialization void Start() { m_GroundCheckMask = ~LayerMask.GetMask("Player"); m_CharacterController = GetComponent<CharacterController>(); m_CharacterAction = GetComponent<CharacterAction>(); m_Unit = GetComponent<Unit>(); m_Animator = GetComponentInChildren<Animator>(); if (m_Animator != null) { m_ForwardID = Animator.StringToHash(ANIMATION_FORWARD); m_SideID = Animator.StringToHash(ANIMATION_SIDE); m_IsAttackingID = Animator.StringToHash(ANIMATION_IS_ATTACKING); m_AttackSwordID = Animator.StringToHash(ANIMATION_ATTACK_SWORD); m_AttackWandID = Animator.StringToHash(ANIMATION_ATTACK_WAND); m_AttackMotionID = Animator.StringToHash(ANIMATION_ATTACK_MOTION); m_AttackGunID = Animator.StringToHash(ANIMATION_ATTACK_GUN); } Camera gameplayCamera = Game.gameplayCamera; m_CharacterCamera = gameplayCamera.GetComponent<CharacterCamera>(); if (m_CharacterCamera != null) { m_CharacterCamera.positionCam = m_Head; m_CharacterCamera.xRotCam = m_VerticalLook; m_CharacterCamera.yRotCam = transform; } }
/// <summary> /// Compare method to compare unit distance /// </summary> /// <param name="A">Unit A</param> /// <param name="B">Unit B</param> /// <returns></returns> protected int CompareUnitDistance(Unit A, Unit B) { float distanceA = Vector3.Distance(transform.position, A.transform.position); float distanceB = Vector3.Distance(transform.position, B.transform.position); if(distanceA < distanceB) { return -1; } else if(distanceA == distanceB) { return 0; } else { return 1; } }
public static void Register(Unit aUnit) { if(s_Instance != null && aUnit != null) { if(!s_Instance.m_Units.Contains(aUnit)) { s_Instance.m_Units.Add(aUnit); aUnit.unitID = s_Instance.m_IDGenerator.Get(); Debug.Log("Registering " + aUnit.unitName); } } }
public void Respawn(Unit aPlayer) { aPlayer.transform.position = m_SpawnPoint.position; m_PlayerToRespawn = aPlayer; StartCoroutine(RespawnDelay()); }
void Start() { m_State = AIState.AQUIRE_TARGET; m_Agent = GetComponent<NavMeshAgent>(); m_Unit = GetComponent<Unit>(); m_Animator = GetComponentInChildren<Animator>(); if(m_Animator != null) { m_ForwardID = Animator.StringToHash(ANIMATION_FORWARD); m_IsAttackingID = Animator.StringToHash(ANIMATION_IS_ATTACKING); m_AttackSwordID = Animator.StringToHash(ANIMATION_ATTACK_SWORD); m_AttackWandID = Animator.StringToHash(ANIMATION_ATTACK_WAND); m_AttackMotionID = Animator.StringToHash(ANIMATION_ATTACK_MOTION); } m_LastPosition = transform.position; }
public static void CantSee(Unit aUnit) { instance.m_UnitsCanSee.Remove(aUnit); }
public static void CanSee(Unit aUnit) { if(!instance.m_UnitsCanSee.Contains(aUnit)) { instance.m_UnitsCanSee.Add(aUnit); } }
protected virtual void Start() { m_AIMotor = GetComponent<AIMotor>(); m_Unit = GetComponent<Unit>(); }
/// <summary> /// Searches for all units /// </summary> private void SearchForUnits() { if(m_TargetAquiredBehaviour == null) { return; } //DebugUtils.Log("Searching for units"); IEnumerable<Unit> units = UnitManager.GetAllUnits(); if(units == null) { return; } IEnumerator<Unit> iter = units.GetEnumerator(); m_TargetList.Clear(); while(iter.MoveNext()) { if(iter.Current == null) { continue; } if(SearchCondition(iter.Current)) { m_TargetList.Add(iter.Current); } } int count = m_TargetList.Count; if(count > 0) { if(count > 1) { m_TargetList.Sort(CompareUnitDistance); } m_Target = m_TargetList[0]; } else { m_Target = null; } }
public static void Unregister(Unit aUnit) { if(s_Instance != null && aUnit != null) { if(s_Instance.m_Units.Remove(aUnit)) { s_Instance.m_IDGenerator.Free(aUnit.unitID); } } }
// Use this for initialization void Start() { m_Motor = GetComponent<CharacterMotor>(); m_Unit = GetComponent<Unit>(); }
IEnumerator LateStart() { yield return new WaitForEndOfFrame(); m_Unit = UnitManager.GetUnit(m_TargetName); }