Advertisement
Guest User

Untitled

a guest
Aug 8th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.63 KB | None | 0 0
  1. /// <summary>
  2. /// Fx manager.
  3. /// David Oneill
  4. /// 11/5/2014
  5. /// this is the effects managementclass, holding rpc functions to broadcast to other players,
  6. /// syncing sounds and effects over the network! These are called by weaponBehaviour.cs +Audio classes.
  7. /// </summary>
  8. using UnityEngine;
  9. using System.Collections;
  10.  
  11.  
  12. public class FxManager : MonoBehaviour {
  13.     //public AudioClip audioClipToPlay = null;
  14.  
  15.     public AudioClip AK47fireSnd;
  16.     public AudioClip AK47reloadSnd;
  17.     //public AudioClip AK47reloadLastSnd;//usually shell reload sound + shotgun pump or rifle chambering sound
  18.     //public AudioClip AK47noammoSnd;
  19.     public AudioClip AK47readySnd;
  20.  
  21.     public AudioClip ShotGunfireSnd;
  22.     public AudioClip ShotGunreloadSnd;
  23.     public AudioClip ShotGunreadySnd;
  24.  
  25.     public AudioClip M1911fireSnd;
  26.     public AudioClip M1911reloadSnd;
  27.     public AudioClip M1911readySnd;
  28.  
  29.    
  30.     public AudioClip Mp5fireSnd;
  31.     public AudioClip Mp5reloadSnd;
  32.     public AudioClip Mp5readySnd;
  33.  
  34.     public AudioClip SniperfireSnd;
  35.     public AudioClip SniperreloadSnd;
  36.     public AudioClip SniperreadySnd;
  37.  
  38.     public AudioClip KatanaSnd;
  39.     //public AudioClip SniperreloadSnd;
  40.     public AudioClip KatanareadySnd;
  41.  
  42.     public GameObject[] dirtMarks;
  43.     public GameObject[] metalMarks;
  44.     public GameObject[] woodMarks;
  45.     public GameObject[] glassMarks;
  46.     public GameObject[] fleshMarks;
  47.    
  48.     public GameObject[] dirtMarksMelee;
  49.     public GameObject[] metalMarksMelee;
  50.     public GameObject[] woodMarksMelee;
  51.  
  52.     private GameObject markObj;
  53.  
  54.     public GameObject bulletTrail;
  55.  
  56.     //FootSteps
  57.     public float dirtStepVol = 1.0f;
  58.     public AudioClip[] dirtSteps;
  59.     public float woodStepVol = 1.0f;
  60.     public AudioClip[] woodSteps;
  61.     public float metalStepVol = 1.0f;
  62.     public AudioClip[] metalSteps;
  63.     public float waterSoundVol = 1.0f;
  64.     public AudioClip[] waterSounds;
  65.     public float climbSoundVol = 1.0f;
  66.     public AudioClip[] climbSounds;
  67.     //landing
  68.     public AudioClip dirtLand;
  69.     public AudioClip metalLand;
  70.     public AudioClip woodLand;
  71.     public AudioClip waterLand;
  72.     //Privates for audio
  73.     private AudioClip footStepClip;//Footstep audio clip to be played
  74.     private float volumeAmt = 1.0f;//volume of audio clip to be played
  75.  
  76.  
  77.     [RPC]
  78.     void BulletTrailFX(Vector3 startPos, Vector3 endPos)
  79.     {
  80.         GameObject bulletTrailFx = (GameObject)Instantiate(bulletTrail, startPos,Quaternion.LookRotation(startPos - endPos));
  81.         LineRenderer lineR =  bulletTrailFx.transform.Find("LineFX").GetComponent<LineRenderer>();
  82.         lineR.SetPosition(0,startPos);
  83.         lineR.SetPosition(1,endPos);
  84.  
  85. //      Debug.Log ("FX Call!");
  86.     }
  87.  
  88.     [RPC]
  89.     void ReloadAudioFX(string name,Vector3 playPoint)
  90.     {
  91.         switch(name){
  92.         case "AK47":
  93.             AudioSource.PlayClipAtPoint(AK47reloadSnd,playPoint);
  94.             break;
  95.         case "Katana":
  96.             break;
  97.         case "M1911":
  98.             AudioSource.PlayClipAtPoint(M1911reloadSnd,playPoint);
  99.             break;
  100.         case "MP5":
  101.             AudioSource.PlayClipAtPoint(Mp5reloadSnd,playPoint);
  102.             break;
  103.         case "Shotgun":
  104.             AudioSource.PlayClipAtPoint(ShotGunreloadSnd,playPoint);
  105.             break;
  106.         case "Sniper":
  107.             AudioSource.PlayClipAtPoint(SniperreloadSnd,playPoint);
  108.             break;
  109.         default:
  110.             break; 
  111.         }
  112.     }
  113.  
  114.     [RPC]
  115.     void ReadyAudioFX(string name,Vector3 playPoint)
  116.     {
  117.         switch(name){
  118.         case "AK47":
  119.             AudioSource.PlayClipAtPoint(AK47readySnd,playPoint);
  120.             break;
  121.         case "Katana":
  122.             AudioSource.PlayClipAtPoint(KatanareadySnd,playPoint);
  123.             break;
  124.         case "M1911":
  125.             AudioSource.PlayClipAtPoint(M1911readySnd,playPoint);
  126.             break;
  127.         case "MP5":
  128.             AudioSource.PlayClipAtPoint(Mp5readySnd,playPoint);
  129.             break;
  130.         case "Shotgun":
  131.             AudioSource.PlayClipAtPoint(ShotGunreadySnd,playPoint);
  132.             break;
  133.         case "Sniper":
  134.             AudioSource.PlayClipAtPoint(SniperreadySnd,playPoint);
  135.             break;
  136.         default:
  137.             break;
  138.         }
  139.     }
  140.  
  141.     [RPC]
  142.     void FireAudioFX(string name,Vector3 playPoint)
  143.     {
  144.         switch(name){
  145.         case "AK47":
  146.             AudioSource.PlayClipAtPoint(AK47fireSnd,playPoint);
  147.             break;
  148.         case "Katana":
  149.             AudioSource.PlayClipAtPoint(KatanaSnd,playPoint);
  150.             break;
  151.         case "M1911":
  152.             AudioSource.PlayClipAtPoint(M1911fireSnd,playPoint);
  153.             break;
  154.         case "MP5":
  155.             AudioSource.PlayClipAtPoint(Mp5fireSnd,playPoint);
  156.             break;
  157.         case "Shotgun":
  158.             AudioSource.PlayClipAtPoint(ShotGunfireSnd,playPoint);
  159.             break;
  160.         case "Sniper":
  161.             AudioSource.PlayClipAtPoint(SniperfireSnd,playPoint);
  162.             break;
  163.         default:
  164.             break;
  165.         }
  166.     }
  167.  
  168.     [RPC]//Come back to this
  169.     void BulletMarkFX (bool ranged,string tag,Vector3 hitpoint, Quaternion hitNormal){
  170.  
  171.         if(ranged == true){//not a melee weapon
  172.             //find the tag name of the hit game object and select an impact mark for the surface type
  173.             switch(tag){
  174.             case "Dirt":
  175.                 markObj = dirtMarks[Random.Range(0, dirtMarks.Length)];
  176.         //  Debug.Log ("This is shit");
  177.                 break;
  178.             case "Metal":
  179.                 markObj = metalMarks[Random.Range(0, metalMarks.Length)];
  180.                 break;
  181.             case "Wood":
  182.                 markObj = woodMarks[Random.Range(0, woodMarks.Length)];
  183.                 break;
  184.             case "Glass":
  185.                 markObj = glassMarks[Random.Range(0, glassMarks.Length)];
  186.                 break;
  187.             case "Flesh":
  188.                 markObj = fleshMarks[Random.Range(0, fleshMarks.Length)];
  189.                 break;
  190.             default:
  191.                 markObj = dirtMarks[Random.Range(0, dirtMarks.Length)];
  192.                 break;
  193.                
  194.             }
  195.         }else{
  196.             switch(tag){//select a melee weapon impact mark
  197.             case "Dirt":
  198.                 markObj = dirtMarksMelee[Random.Range(0, dirtMarksMelee.Length)];
  199.                
  200.                 break;
  201.             case "Metal":
  202.                 markObj = metalMarksMelee[Random.Range(0, metalMarksMelee.Length)];
  203.                 break;
  204.             case "Wood":
  205.                 markObj = woodMarksMelee[Random.Range(0, woodMarksMelee.Length)];
  206.                 break;
  207.             case "Glass":
  208.                 markObj = glassMarks[Random.Range(0, glassMarks.Length)];
  209.                 break;
  210.             case "Flesh":
  211.                 markObj = fleshMarks[Random.Range(0, fleshMarks.Length)];
  212.                 break;
  213.             default:
  214.                 markObj = dirtMarksMelee[Random.Range(0, dirtMarksMelee.Length)];
  215.                 break;
  216.             }
  217.         }
  218.         //markObj = dirtMarks[Random.Range(0, dirtMarks.Length)];
  219.         Instantiate(markObj, hitpoint, hitNormal );// Quaternion.identity);
  220.         //AudioSource a = markObj.transform.GetComponentInChildren<AudioSource>();
  221.         //a.pitch =  Random.Range(0.96f * Time.timeScale, 1.0f * Time.timeScale);
  222.         //markObj.transform.parent = (GameObject)hitpoint;
  223.  
  224.         //Debug.Log (tag);
  225.  
  226. //Debug.Log (hitpoint);
  227.  
  228.  
  229.     }
  230.     //FootStep sounds!- look at changing the volume of the footsteps based on running/sneaking.
  231.     [RPC]
  232.     void FootStepAudio(string materialType,Vector3 playPoint)
  233.     {
  234.         switch(materialType){//determine which material the player is standing on and select random footstep effect for surface type
  235.         case "Wood":
  236.             footStepClip = woodSteps[Random.Range(0, woodSteps.Length)];
  237.             volumeAmt = woodStepVol;
  238.             AudioSource.PlayClipAtPoint(footStepClip,playPoint,volumeAmt);
  239.  
  240.             break;
  241.         case "Metal":
  242.             footStepClip = metalSteps[Random.Range(0, metalSteps.Length)];
  243.             volumeAmt = metalStepVol;
  244.             AudioSource.PlayClipAtPoint(footStepClip,playPoint,volumeAmt);
  245.  
  246.             break;
  247.         case "Dirt":
  248.             footStepClip = dirtSteps[Random.Range(0, dirtSteps.Length)];
  249.             volumeAmt = dirtStepVol;
  250.             AudioSource.PlayClipAtPoint(footStepClip,playPoint,volumeAmt);
  251.  
  252.             break;
  253.         default:
  254.             footStepClip = dirtSteps[Random.Range(0, dirtSteps.Length)];
  255.             volumeAmt = dirtStepVol;
  256.             AudioSource.PlayClipAtPoint(footStepClip,playPoint,volumeAmt);
  257.  
  258.             break; 
  259.         }
  260.  
  261.  
  262.     }//End of FootStep
  263.  
  264.     [RPC]
  265.     void WaterAudio(Vector3 playPoint)
  266.     {
  267.         footStepClip = waterSounds[Random.Range(0, waterSounds.Length)];//select random water step effect from waterSounds array
  268.         volumeAmt = waterSoundVol;//set volume of audio clip to customized amount
  269.         AudioSource.PlayClipAtPoint(footStepClip, playPoint, volumeAmt);
  270.     }
  271.  
  272.     [RPC]
  273.     void ClimbAudio(Vector3 playPoint)
  274.     {
  275.         footStepClip = climbSounds[Random.Range(0, climbSounds.Length)];
  276.         volumeAmt = climbSoundVol;
  277.         AudioSource.PlayClipAtPoint(footStepClip, playPoint, volumeAmt);
  278.     }
  279.  
  280.     [RPC]
  281.     void LandAudio(string tag,Vector3 playPoint)
  282.     {
  283.         //Debug.Log ("LandAudio");
  284.         switch(tag){
  285.         case "Water":
  286.             //volumeAmt = waterSoundVol * 2;
  287.             AudioSource.PlayClipAtPoint(waterLand,playPoint,volumeAmt);
  288.             break;
  289.         case "Dirt":
  290.             //volumeAmt = dirtStepVol * 2;
  291.             AudioSource.PlayClipAtPoint(dirtLand,playPoint,volumeAmt);         
  292.             break;
  293.         case "Wood":
  294.             //volumeAmt = woodStepVol * 2;
  295.             AudioSource.PlayClipAtPoint(woodLand,playPoint,volumeAmt); 
  296.             break;
  297.         case "Metal":
  298.             //volumeAmt = metalStepVol * 1.5f;
  299.             AudioSource.PlayClipAtPoint(metalLand,playPoint,volumeAmt);
  300.             break;
  301.         default:
  302.             //volumeAmt = dirtStepVol * 2;
  303.             AudioSource.PlayClipAtPoint(dirtLand,playPoint,volumeAmt); 
  304.             break; 
  305.         }
  306.     }
  307.  
  308. }//End#######################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement