public void PerFrameUpdate() { //run delay timer for tooltip if (_isShowingToolTip) { if (!NGUITools.GetActive(ToolTip)) { NGUITools.SetActive(ToolTip.gameObject, true); } Vector3 pos = Input.mousePosition + new Vector3(0, 10, 0); pos.x = Mathf.Clamp01(pos.x / Screen.width); pos.y = Mathf.Clamp01(pos.y / Screen.height); ToolTip.transform.position = GameManager.Inst.UIManager.UICamera.ViewportToWorldPoint(pos);; //_toolTipTimer = 0; /* * if(_toolTipTimer < ToolTipDelay) * { * _toolTipTimer += Time.unscaledDeltaTime; * } * else * { * * } */ } if (InputEventHandler.Instance.State == UserInputState.PopupOpen || InputEventHandler.Instance.State == UserInputState.Dialogue) { SetCursorState(CursorState.Default); HideToolTip(); GameManager.Inst.UIManager.HUDPanel.HideTargetName(); } //Debug.Log(Input.mousePosition); if (GameManager.Inst.PlayerControl.IsGamePaused || InputEventHandler.Instance.State != UserInputState.Normal) { return; } //UnityEngine.Cursor.visible = false; if (CurrentState == CursorState.Aim) { UnityEngine.Cursor.visible = false; AimCursor aimCursor = ActiveCursor.GetComponent <AimCursor>(); if (aimCursor != null) { //float climb = GameManager.Inst.PlayerControl.SelectedPC.AimTarget.localPosition.y; float armFatigue = GameManager.Inst.PlayerControl.SelectedPC.MyStatus.ArmFatigue / GameManager.Inst.PlayerControl.SelectedPC.MyStatus.MaxArmFatigue; float amount = GameManager.Inst.Constants.ArmFatigueRecoil.Evaluate(Mathf.Clamp(armFatigue, 0, 1)); float baseAmount = 5; if (GameManager.Inst.PlayerControl.SelectedPC.IsHipAiming || GameManager.Inst.PlayerControl.SelectedPC.UpperBodyState != HumanUpperBodyStates.Aim) { baseAmount = 15; } amount = amount * 100 + baseAmount + 20 * GameManager.Inst.PlayerControl.SelectedPC.MyAI.WeaponSystem.GetTurnMoveScatter(); aimCursor.SetExpansion(amount); Weapon currentWeapon = GameManager.Inst.PlayerControl.SelectedPC.MyReference.CurrentWeapon.GetComponent <Weapon>(); if (currentWeapon.IsRanged) { Gun gun = (Gun)currentWeapon; if (gun.Barrel.Range < Vector3.Distance(GameManager.Inst.PlayerControl.SelectedPC.transform.position, GameManager.Inst.PlayerControl.SelectedPC.AimPoint)) { SetCrosshairState(aimCursor, true); } else { SetCrosshairState(aimCursor, false); } } else { SetCrosshairState(aimCursor, false); } } } else { UnityEngine.Cursor.visible = true; } float centerAlpha = CursorAim.GetComponent <AimCursor>().AimCursorCenter.alpha; CursorAim.GetComponent <AimCursor>().SetCenterCursorAlpha(Mathf.Lerp(centerAlpha, 0, Time.deltaTime * 3)); //update cursor state based on what player is doing GameObject aimedObject = GameManager.Inst.PlayerControl.GetAimedObject(); if (GameManager.Inst.PlayerControl.SelectedPC.MyAI.ControlType == AIControlType.Player) { //if(GameManager.Inst.PlayerControl.SelectedPC.GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && !GameManager.Inst.UIManager.IsCursorInHUDRegion()) if ((GameManager.Inst.PlayerControl.SelectedPC.UpperBodyState == HumanUpperBodyStates.Aim || GameManager.Inst.PlayerControl.SelectedPC.UpperBodyState == HumanUpperBodyStates.HalfAim) && !GameManager.Inst.UIManager.IsCursorInHUDRegion()) { SetCursorState(CursorState.Aim); /* * //now check if aimed object is enemy * Character aimedChar = GameManager.Inst.PlayerControl.GetAimedObject().GetComponent<Character>(); * if(aimedChar != null && aimedChar.Faction != GameManager.Inst.PlayerControl.SelectedPC.Faction) * { * //mark cursor as red * CursorAim.color = new Color(1, 0, 0); * } */ } else if (aimedObject != null && Vector3.Distance(GameManager.Inst.PlayerControl.SelectedPC.transform.position, aimedObject.transform.position) < 15) { if (aimedObject.GetComponent <PickupItem>() != null) { PickupItem pickup = aimedObject.GetComponent <PickupItem>(); string quantity = ""; if (pickup.Quantity > 1) { quantity = "(" + pickup.Quantity + ")"; } //ShowToolTip(pickup.Item.Name + quantity); GameManager.Inst.UIManager.HUDPanel.ShowTargetName(pickup.Item.Name + quantity, 1); SetCursorState(CursorState.Hand); } else if (aimedObject.GetComponent <StoryObject>() != null) { //ShowToolTip(aimedObject.GetComponent<StoryObject>().Name); GameManager.Inst.UIManager.HUDPanel.ShowTargetName(aimedObject.GetComponent <StoryObject>().Name, 1); SetCursorState(CursorState.Hand); } else if (aimedObject.GetComponent <Character>() != null) { Character aimedCharacter = aimedObject.GetComponent <Character>(); int relationship = aimedCharacter.MyAI.IsCharacterEnemy((Character)GameManager.Inst.PlayerControl.SelectedPC); if (aimedCharacter != null && aimedCharacter.MyStatus.Health > 0 && relationship >= 2 && aimedCharacter.MyAI.ControlType != AIControlType.Player && !aimedCharacter.IsHidden) { SetCursorState(CursorState.Talk); } else { SetCursorState(CursorState.Default); } string name = aimedCharacter.Name; if (relationship < 1) { name = aimedCharacter.Faction.ToString(); } if (!string.IsNullOrEmpty(aimedCharacter.Title)) { name = aimedCharacter.Title + " " + name; } if (!string.IsNullOrEmpty(name) && !aimedCharacter.IsHidden) { //ShowToolTip(name); GameManager.Inst.UIManager.HUDPanel.ShowTargetName(name, relationship); } } else if (aimedObject.tag == "SerumLab") { //ShowToolTip("Serum Lab"); GameManager.Inst.UIManager.HUDPanel.ShowTargetName("Serum Lab", 1); SetCursorState(CursorState.Hand); } else { DeathCollider deathCollider = aimedObject.GetComponent <DeathCollider>(); if (deathCollider != null) { Character aimedCharacter = deathCollider.ParentCharacter; if (aimedCharacter != null && aimedCharacter.MyStatus.Health <= 0) { SetCursorState(CursorState.Hand); } else { SetCursorState(CursorState.Default); } } else if (aimedObject.tag == "Chest" && aimedObject.GetComponent <Chest>() != null) { SetCursorState(CursorState.Hand); } else if (aimedObject.tag == "Door" || aimedObject.tag == "LightSwitch") { SetCursorState(CursorState.Hand); } else if (aimedObject.tag == "Portal") { SetCursorState(CursorState.Portal); } else { //Debug.Log("setting cursor to default"); SetCursorState(CursorState.Default); } HideToolTip(); GameManager.Inst.UIManager.HUDPanel.FadeTargetName(); } } else { //Debug.Log("setting cursor to default"); SetCursorState(CursorState.Default); HideToolTip(); GameManager.Inst.UIManager.HUDPanel.FadeTargetName(); } } else { //Debug.Log("setting cursor to default"); SetCursorState(CursorState.Default); HideToolTip(); GameManager.Inst.UIManager.HUDPanel.HideTargetName(); } }
void OnCollisionEnter(Collision collision) { Character hitCharacter = collision.collider.GetComponent <Character>(); DeathCollider deathCollider = collision.collider.GetComponent <DeathCollider>(); if (hitCharacter == ParentWeapon.Attacker) { return; } if (hitCharacter != null && ParentWeapon.Attacker.MyAI.IsCharacterFriendly(hitCharacter)) { return; } if (collision.collider.GetComponent <Bullet>() != null) { return; } Vector3 pos = collision.contacts[0].point; Vector3 normal = collision.contacts[0].normal; if (hitCharacter != null) { //calculate damage based on attack rating. higher the attack rating more likely the damage is near totalDamage float x = UnityEngine.Random.value; float yMax = EvaluateDamageCurve(Attack * 10, 1); float y = EvaluateDamageCurve(Attack * 10, x); float damage = TotalDamage * (y / yMax); float distPercent = _distTraveled / Range; float distDamageDrop = DamageDropCurve.Evaluate(distPercent) * damage; float randCritical = UnityEngine.Random.value; Damage deliveredDamage = new Damage(); deliveredDamage.Type = DamageType.Bullet; deliveredDamage.KineticDamage = TotalDamage; deliveredDamage.Bleeding = Bleeding; deliveredDamage.Penetration = Penetration; if (randCritical <= CriticalChance) { deliveredDamage.IsCritical = true; } hitCharacter.SendDamage(deliveredDamage, normal * -1, ParentWeapon.Attacker, ParentWeapon); GameObject impact = GameManager.Inst.FXManager.LoadFX("GunshotBlood" + UnityEngine.Random.Range(1, 4).ToString(), 1, FXType.BloodSpatter); Debug.DrawRay(pos, normal, new Color(0, 1, 0), 3); impact.transform.position = pos; impact.transform.rotation = Quaternion.LookRotation(normal); BloodSpatter blood = impact.GetComponent <BloodSpatter>(); blood.Source = hitCharacter; blood.Offset = pos - hitCharacter.transform.position; ParentWeapon.Attacker.OnSuccessfulHit(hitCharacter); } else { int upperBound = 5; PhysicMaterial material = collision.collider.sharedMaterial; GameObject impact = null; string clipName = ""; string holeName = ""; if (deathCollider != null) { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactSand", 0, FXType.BulletImpact); clipName = "bullet_sand"; } else if (material == null) { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactConcrete", 0, FXType.BulletImpact); clipName = "bullet_default"; upperBound = 10; holeName = "Bullet_Hole_Concrete"; } else if (material.name == "Metal") { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactMetal", 0, FXType.BulletImpact); clipName = "bullet_metal"; holeName = "Bullet_Hole_Metal"; } else if (material.name == "Terrain") { FloorType floorType = GameManager.Inst.WorldManager.CurrentTerrain.GetMainFloorType(this.transform.position); if (floorType == FloorType.rock) { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactConcrete", 0, FXType.BulletImpact); clipName = "bullet_default"; holeName = "Bullet_Hole_Concrete"; } else if (floorType == FloorType.sand) { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactSand", 0, FXType.BulletImpact); clipName = "bullet_sand"; } else { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactDirt", 0, FXType.BulletImpact); clipName = "bullet_dirt"; } } else if (material.name == "SoftWood" || material.name == "Wood") { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactWood", 0, FXType.BulletImpact); clipName = "bullet_wood"; holeName = "Bullet_Hole_Wood"; } else if (material.name == "Concrete") { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactConcrete", 0, FXType.BulletImpact); clipName = "bullet_default"; upperBound = 10; holeName = "Bullet_Hole_Concrete"; } else { impact = GameManager.Inst.FXManager.LoadFX("BulletImpactConcrete", 0, FXType.BulletImpact); clipName = "bullet_default"; upperBound = 10; holeName = "Bullet_Hole_Concrete"; } //bullet hole if (holeName != "") { GameObject hole = GameManager.Inst.FXManager.LoadFX(holeName, 30, FXType.BulletHole); hole.transform.position = pos + normal * 0.02f; hole.transform.rotation = Quaternion.LookRotation(normal * -1); } int clipChoice = UnityEngine.Random.Range(1, upperBound); clipName = clipName + clipChoice.ToString(); float volume = UnityEngine.Random.Range(0.12f, 0.2f); AudioSource audio = impact.GetComponent <AudioSource>(); if (audio != null && Vector3.Distance(this.transform.position, GameManager.Inst.PlayerControl.SelectedPC.transform.position) < 10) { audio.PlayOneShot(GameManager.Inst.SoundManager.GetClip(clipName), volume); } impact.transform.position = pos; impact.transform.rotation = Quaternion.LookRotation(normal); } Rigidbody otherRB = collision.collider.GetComponent <Rigidbody>(); if (otherRB) { Vector3 force = normal * Velocity.magnitude * 1; otherRB.AddForceAtPosition(force, pos); } //_rigidbody.velocity = _rigidbody.velocity * 0.4f; GameObject.Destroy(this.gameObject); }