// ------ protected override void OnUpdate() { base.OnUpdate(); if (Camera.main == null) { return; } AgentHuman player = Owner.LocalPlayer.Owner; BlackBoard blackBoard = player.BlackBoard; if (player.LastHitTime + 0.15f > Time.timeSinceLevelLoad) { m_CrosshairHit.Widget.Show(true, true); } else { m_CrosshairHit.Widget.Show(false, true); } WeaponBase weapon = player.WeaponComponent.GetCurrentWeapon(); if (!weapon || weapon.PreparedForFireProgress < 0 || !player.IsAlive) { if (m_PrepareForFire.IsVisible()) { m_PrepareForFire.Show(false, true); } } else { if (!m_PrepareForFire.IsVisible()) { m_PrepareForFire.Show(true, true); } float progress = weapon.PreparedForFireProgress; Color color = Color.white * (1 - progress) + Color.green * progress; Vector3 offset = new Vector3(75 + 70 * (1 - progress), 0, 0); Vector3 basePos = m_PrepareForFire.transform.localPosition; m_PrepareForFireA.Color = color; m_PrepareForFireB.Color = color; m_PrepareForFireA.transform.localPosition = basePos - offset; m_PrepareForFireB.transform.localPosition = basePos + offset; m_PrepareForFire.SetModify(true); } const float crosshairDistance = 200.0f; //do jake vzdalenosti testujeme kolizi zda mirime na enemy (todo: mozna pouzit konstantu z UpdateIdealFireDir) bool aimingHit = false; bool showEnemyLabel = false; //test collision in aiming sight Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)); LayerMask mask = (ObjectLayerMask.Default | ObjectLayerMask.PhysicsMetal | ObjectLayerMask.Ragdoll); Vector3 hitPoint; GameObject go = CollisionUtils.FirstCollisionOnRay(ray, crosshairDistance, player.GameObject, out hitPoint, mask); Agent agent = null; if (go) { agent = GameObjectUtils.GetFirstComponentUpward <Agent>(go); if (!agent || (agent == Player.LocalInstance.Owner) || !agent.IsAlive || agent.IsFriend(player)) { agent = null; } } if (!agent) { mask = ObjectLayerMask.Ragdoll; go = CollisionUtils.FirstSphereCollisionOnRay(ray, 0.6f, crosshairDistance, player.GameObject, out hitPoint, mask); if (go) { mask = ObjectLayerMask.Default | ObjectLayerMask.PhysicsMetal | ObjectLayerMask.Ragdoll; ray.direction = hitPoint - ray.origin; GameObject go2 = CollisionUtils.FirstCollisionOnRay(ray, crosshairDistance, player.GameObject, out hitPoint, mask); // to be accurate if (go2) { agent = GameObjectUtils.GetFirstComponentUpward <Agent>(go2); if (!agent || (agent == Player.LocalInstance.Owner) || !agent.IsAlive || agent.IsFriend(player)) { agent = null; } } } } if (agent) { //is it enemy? //Sem pridavat dalsi typy enemacu co nejsou podedene z agenta Agent a = GameObjectUtils.GetFirstComponentUpward <Agent>(go); if (a && (a != Player.LocalInstance.Owner) && a.IsAlive && !a.IsFriend(player)) { aimingHit = true; PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(a.networkView.owner); if (ppi != null) { SetTextAndAdjustBackground(ppi.NameForGui, m_EnemyLabelName, m_EnemyLabel, m_EnemyLabelOrigWidth, m_EnemyLabelNameOrigScale); showEnemyLabel = true; } E_Team enemyTeam = (ppi != null) ? ppi.Team : E_Team.None; if (Client.Instance.GameState.GameType == E_MPGameType.DeathMatch) { enemyTeam = E_Team.Bad; } m_EnemyLabel.Color = ZoneControlFlag.Colors[enemyTeam]; m_CrosshairHit.Widget.Color = ZoneControlFlag.Colors[E_Team.Bad]; //m_Crosshair[(int)E_CrosshairType.Target].Widget.Color = ZoneControlFlag.Colors[E_Team.Bad]; //foreach (GUIBase_Widget widget in m_CrosshairTargetChilds) // widget.Color = ZoneControlFlag.Colors[E_Team.Bad]; } } m_EnemyLabel.Show(showEnemyLabel, true); if (aimingHit || blackBoard.Desires.MeleeTarget && player.CanMelee()) { ShowCrosshair(E_CrosshairType.Target); } else { ShowCrosshair(E_CrosshairType.Normal); } }