164 lines
5.1 KiB
C#
164 lines
5.1 KiB
C#
using DamageNumbersPro;
|
|
using Photon.Pun;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using Unity.Burst.CompilerServices;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using static Org.BouncyCastle.Bcpg.Attr.ImageAttrib;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class PlayerFX : MonoBehaviourPunCallbacks
|
|
{
|
|
[Header("Reload")]
|
|
public GameObject RifleMag;
|
|
public GameObject HandMag;
|
|
public AudioClip magEjectClip, magNewClip, hammerClip;
|
|
[Header("Shooting")]
|
|
public Animator anim;
|
|
public GameObject MuzzleFlash;
|
|
public AudioClip fireSFX, emptyFireSFX;
|
|
public AudioSource audioSoruce;
|
|
public GameObject bulletHole;
|
|
public GameObject bloodSplash;
|
|
public LineRenderer bulletTrail;
|
|
public DamageNumber damageNumber;
|
|
LineRenderer m_bulletTrail;
|
|
|
|
[Header("Footsteps")]
|
|
public AudioClip[] NormalFootsteps;
|
|
public AudioClip whooshClip;
|
|
|
|
PlayerNetwork playerNetwork;
|
|
private void Awake()
|
|
{
|
|
m_bulletTrail = Instantiate(bulletTrail, null);
|
|
m_bulletTrail.gameObject.SetActive(false);
|
|
playerNetwork = GetComponent<PlayerNetwork>();
|
|
}
|
|
|
|
public void EjectMag()
|
|
{
|
|
RifleMag.SetActive(false);
|
|
HandMag.SetActive(true);
|
|
audioSoruce.PlayOneShot(magEjectClip);
|
|
}
|
|
|
|
public void NewMag()
|
|
{
|
|
RifleMag.SetActive(true);
|
|
HandMag.SetActive(false);
|
|
audioSoruce.PlayOneShot(magNewClip);
|
|
}
|
|
|
|
public void OnFootStep(){
|
|
audioSoruce.PlayOneShot(NormalFootsteps[UnityEngine.Random.Range(0, NormalFootsteps.Length)]);
|
|
}
|
|
|
|
public void Hammer()
|
|
{
|
|
audioSoruce.PlayOneShot(hammerClip);
|
|
}
|
|
|
|
public void PunchInit(){
|
|
audioSoruce.PlayOneShot(whooshClip);
|
|
}
|
|
|
|
public void FireFX(RaycastHit? impact)
|
|
{
|
|
// RpcFireFX(impact.point, impact.normal, impact.collider != null);
|
|
Debug.Log("Fire FX");
|
|
if(impact == null)
|
|
{
|
|
photonView.RPC("RpcFireFX", RpcTarget.All, Camera.main.transform.position + (Camera.main.transform.forward * 200f), Vector3.zero, "");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
photonView.RPC("RpcFireFX", RpcTarget.All, impact?.point, impact?.normal, impact?.collider.tag);
|
|
}
|
|
|
|
if (impact?.collider.tag == "Player" && photonView.IsMine)
|
|
{
|
|
HitBox hitbox = impact?.collider.GetComponent<HitBox>();
|
|
if(hitbox == null){
|
|
// playerNetwork.OnHit(photonView.ViewID, PlayerControllerHelper.GetDamageForHitboxType(HitBoxType.Body), transform.position, 1); //PHANTOM SHOTS
|
|
}else{
|
|
hitbox.OnHit(photonView.ViewID, impact?.point ?? transform.position, transform);
|
|
}
|
|
}
|
|
|
|
if(impact?.collider.tag == "BulletImpactReceiver"&& photonView.IsMine){
|
|
|
|
impact?.transform.GetComponent<BulletImpactReceiver>().OnHit(impact?.point, impact?.normal, transform.position);
|
|
}
|
|
}
|
|
public bool aiming => anim.GetCurrentAnimatorClipInfo(1)[0].clip.name.Contains("Aim");
|
|
|
|
[PunRPC]
|
|
void RpcFireFX(Vector3 point, Vector3 normal, string tag)
|
|
{
|
|
StartCoroutine(shotFx(point, normal, tag));
|
|
}
|
|
public AudioClip[] FireSFXs;
|
|
IEnumerator shotFx(Vector3 point, Vector3 normal, string tag){
|
|
if (!aiming)
|
|
{
|
|
anim.CrossFadeInFixedTime("Aiming", 0f);
|
|
yield return new WaitForSeconds(0.05f);
|
|
}
|
|
AudioClip clip = FireSFXs[Random.Range(0, FireSFXs.Length)];
|
|
Debug.Log(clip.name);
|
|
audioSoruce.PlayOneShot(clip);
|
|
MuzzleFlash.SetActive(false);
|
|
MuzzleFlash.SetActive(true);
|
|
|
|
m_bulletTrail.gameObject.SetActive(true);
|
|
if (tag == "")
|
|
{
|
|
m_bulletTrail.SetPositions(new Vector3[] { MuzzleFlash.transform.position, point });
|
|
}else{
|
|
m_bulletTrail.SetPositions(new Vector3[] { MuzzleFlash.transform.position, point });
|
|
|
|
ImpactFX(tag, point,normal);
|
|
}
|
|
}
|
|
void ImpactFX(string tag, Vector3 point, Vector3 normal)
|
|
{
|
|
if(tag == "Player")
|
|
{
|
|
Transform blood = ObjectsPool.instance.Spawn(bloodSplash, point, Quaternion.FromToRotation(Vector3.up, normal), destructionTimer: 3).transform;
|
|
blood.position += blood.up * 0.01f;
|
|
return;
|
|
}
|
|
|
|
if(tag == "BulletImpactReceiver"){
|
|
return;
|
|
}
|
|
|
|
//Bullet hole FX
|
|
Transform hole = ObjectsPool.instance.Spawn(bulletHole, point, Quaternion.FromToRotation(Vector3.up, normal), destructionTimer: 10).transform;
|
|
hole.position += hole.up * 0.01f;
|
|
|
|
//ShowDamageNumber(point, 5); //Test
|
|
}
|
|
public float dmgFXScale = 0.25f;
|
|
public void ShowDamageNumber(Vector3 position, float damage)
|
|
{
|
|
DamageNumber dmgFx = damageNumber.Spawn(position, damage);
|
|
dmgFx.spamGroup = position.ToString();
|
|
|
|
float dist = Vector3.Distance(Camera.main.transform.position, position);
|
|
dmgFx.SetScale(Mathf.Sqrt(dist) * dmgFXScale);
|
|
//dmgFx.SetToMousePosition(UIManager.instance.rectParent, Camera.main);
|
|
}
|
|
|
|
|
|
public void EmptyFire()
|
|
{
|
|
audioSoruce.PlayOneShot(emptyFireSFX);
|
|
}
|
|
}
|