// Define basic components public void SetComponentsBasic() { // Set shatter component meshDemolition.scrShatter = meshDemolition.useShatter == true ? GetComponent <RayfireShatter>() : null; // Other transForm = GetComponent <Transform>(); meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); skinnedMeshRend = GetComponent <SkinnedMeshRenderer>(); restriction = GetComponent <RayfireRestriction>(); // Set sound sound = GetComponent <RayfireSound>(); if (sound != null) { sound.rigid = this; sound.Initialize(); } // Add missing mesh renderer if (meshFilter != null && meshRenderer == null) { meshRenderer = gameObject.AddComponent <MeshRenderer>(); } // Init reset lists if (reset.action == RFReset.PostDemolitionType.DeactivateToReset) { limitations.descendants = new List <RayfireRigid>(); } }
public override void OnInspectorGUI() { // Get target sound = target as RayfireSound; if (sound == null) { return; } // Initialize if (Application.isPlaying == true) { GUILayout.Space(8); if (GUILayout.Button("Initialization Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.InitializationSound(targ as RayfireSound, 0f); } } } if (GUILayout.Button("Activation Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.ActivationSound(targ as RayfireSound, 0f); } } } if (GUILayout.Button("Demolition Sound", GUILayout.Height(25))) { foreach (var targ in targets) { if (targ as RayfireSound != null) { RFSound.DemolitionSound(targ as RayfireSound, 0f); } } } // Info GUILayout.Label("Info", EditorStyles.boldLabel); // Get volume GUILayout.Label(" Volume: " + RFSound.GeVolume(sound, 0f)); GUILayout.Space(5); } // Draw script UI DrawDefaultInspector(); }
// Copy from public void CopyFrom(RayfireSound source) { baseVolume = source.baseVolume; sizeVolume = source.sizeVolume; initialization = new RFSound(source.initialization); activation = new RFSound(source.activation); demolition = new RFSound(source.demolition); minimumSize = source.minimumSize; cameraDistance = source.cameraDistance; }
// Demolition sound public static void DemolitionSound(RayfireSound scr, float size) { // Null if (scr == null) { return; } // Turned off if (scr.demolition.enable == false) { return; } // No Rigid if (scr.rigid == null) { Debug.Log("RayFire Sound: " + scr.name + " Demolition sound warning. Rigid component required", scr.gameObject); return; } // Get size if not defined if (size <= 0) { size = scr.rigid.limitations.bboxSize; } // Filtering if (FilterCheck(scr, size) == false) { return; } // Get play clip if (scr.demolition.HasClips == true) { scr.demolition.clip = scr.demolition.clips[Random.Range(0, scr.demolition.clips.Count)]; } // Has no clip if (scr.demolition.clip == null) { return; } // Get volume float volume = GeVolume(scr, size) * scr.demolition.multiplier; // Play Play(scr, scr.demolition.clip, scr.demolition.outputGroup, volume); }
/// ///////////////////////////////////////////////////////// /// Play on events /// ///////////////////////////////////////////////////////// // Initialization sound public static void InitializationSound(RayfireSound scr, float size) { // Null if (scr == null) { return; } // Turned off if (scr.initialization.enable == false) { return; } // No Rigid if (scr.rigid == null) { Debug.Log("RayFire Sound: " + scr.name + " Initialization sound warning. Rigid component required", scr.gameObject); return; } // Get size if not defined if (size <= 0) { size = scr.rigid.limitations.bboxSize; } // Filtering if (FilterCheck(scr, size) == false) { return; } // Get play clip if (scr.initialization.HasClips == true) { scr.initialization.clip = scr.initialization.clips[Random.Range(0, scr.activation.clips.Count - 1)]; } // Has no clip if (scr.initialization.clip == null) { return; } // Get volume float volume = GeVolume(scr, size); // Play AudioSource.PlayClipAtPoint(scr.initialization.clip, scr.gameObject.transform.position, volume); }
/// ///////////////////////////////////////////////////////// /// Static /// ///////////////////////////////////////////////////////// // Get volume public static float GeVolume(RayfireSound scr, float size) { // Get size if not defined if (size <= 0) { if (scr.rigid != null) { size = scr.rigid.limitations.bboxSize; } } // Get volume float volume = scr.baseVolume; if (scr.sizeVolume > 0) { volume += size * scr.sizeVolume; } return(volume); }
/// ///////////////////////////////////////////////////////// /// Play on events /// ///////////////////////////////////////////////////////// // Play public static void Play(RayfireSound scr, AudioClip clip, AudioMixerGroup group, float volume) { // Has output group if (group != null) { // Get audio source GameObject audioObject = new GameObject("RFSoundSource"); audioObject.transform.parent = RayfireMan.inst.transform; Object.Destroy(audioObject, clip.length + 1f); audioObject.transform.position = scr.gameObject.transform.position; AudioSource audioSource = audioObject.AddComponent <AudioSource>(); // Setup audioSource.clip = clip; audioSource.playOnAwake = false; audioSource.outputAudioMixerGroup = group; audioSource.Play(); } else { AudioSource.PlayClipAtPoint(clip, scr.gameObject.transform.position, volume); } }
// Filters check static bool FilterCheck(RayfireSound scr, float size) { // Small size if (scr.minimumSize > 0) { if (size < scr.minimumSize) { return(false); } } // Far from camera if (scr.cameraDistance > 0) { if (Camera.main != null) { if (Vector3.Distance(Camera.main.transform.position, scr.transform.position) > scr.cameraDistance) { return(false); } } } return(true); }