// Token: 0x06003FDC RID: 16348 RVA: 0x00140F9C File Offset: 0x0013F39C private void _setSlideTargetVolumes(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit) { PhysSoundMaterial physSoundMaterial = null; PhysSoundBase physSoundBase = (!(otherObject == null)) ? otherObject.GetComponent <PhysSoundBase>() : null; if (physSoundBase) { if (!(physSoundBase is PhysSoundTerrain)) { physSoundMaterial = physSoundBase.GetPhysSoundMaterial(contactPoint); } } PhysSoundAudioContainer physSoundAudioContainer2; if (physSoundMaterial) { PhysSoundAudioContainer physSoundAudioContainer; if (this.audioContainersDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioContainer)) { physSoundAudioContainer.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f); } else if (this.SoundMaterial.FallbackTypeKey != -1 && this.audioContainersDic.TryGetValue(this.SoundMaterial.FallbackTypeKey, out physSoundAudioContainer)) { physSoundAudioContainer.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f); } } else if (this.SoundMaterial.FallbackTypeKey != -1 && this.audioContainersDic.TryGetValue(this.SoundMaterial.FallbackTypeKey, out physSoundAudioContainer2)) { physSoundAudioContainer2.SetTargetVolumeAndPitch(base.gameObject, otherObject, relativeVelocity, normal, exit, 1f); } }
private void setSlideTargetVolumes(PhysSoundBase otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit) { PhysSoundMaterial m = null; if (otherObject) { //Special case for sliding against a terrain if (otherObject is PhysSoundTerrain) { PhysSoundTerrain terr = otherObject as PhysSoundTerrain; Dictionary <int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint); foreach (PhysSoundAudioContainer c in audioContainersDic.Values) { PhysSoundComposition comp; float mod = 0; if (compDic.TryGetValue(c.KeyIndex, out comp)) { mod = comp.GetAverage(); } c.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit, mod); } return; } else { m = otherObject.GetPhysSoundMaterial(contactPoint); } } //General cases //If the other object has a PhysSound material if (m) { PhysSoundAudioContainer aud; if (audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit); } else if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit); } } //If it doesnt we set vols based on the fallback setting of our material else { PhysSoundAudioContainer aud; if (SoundMaterial.FallbackTypeKey != -1 && audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(SoundMaterial, relativeVelocity, normal, exit); } } }
public static void Create() { PhysSoundMaterial asset = ScriptableObject.CreateInstance <PhysSoundMaterial>(); AssetDatabase.CreateAsset(asset, GetActiveFolderName() + "/PhysSoundMaterial.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
// Token: 0x06003FE8 RID: 16360 RVA: 0x00141680 File Offset: 0x0013FA80 public void Initialize(PhysSoundMaterial m) { if (this.SlideAudio == null) { return; } this.mat = m; this.SlideAudio.clip = this.mat.GetAudioSet(this.KeyIndex).Slide; this.baseVol = this.SlideAudio.volume; this.basePitch = this.SlideAudio.pitch; this.basePitchRand = this.basePitch; this.SlideAudio.loop = true; this.SlideAudio.volume = 0f; }
/// <summary> /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal. /// </summary> public void SetTargetVolumeAndPitch(PhysSoundMaterial mat, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1) { if (SlideAudio == null) { return; } if (!SlideAudio.isPlaying) { basePitchRand = basePitch + Random.Range(-mat.PitchRandomness, mat.PitchRandomness); SlideAudio.Play(); } SlideAudio.pitch = basePitchRand + relativeVelocity.magnitude * mat.SlidePitchMod; targetVolume = exit ? 0 : mat.GetSlideVolume(relativeVelocity, normal) * baseVol * mod; }
/// <summary> /// Initializes this Audio Container with the given AudioClip. Will do nothing if SlideAudio is not assigned. /// </summary> /// <param name="clip"></param> public void Initialize(PhysSoundMaterial m) { if (SlideAudio == null) { return; } _mat = m; SlideAudio.clip = _mat.GetAudioSet(KeyIndex).Slide; _baseVol = SlideAudio.volume; _basePitch = SlideAudio.pitch; _basePitchRand = _basePitch; SlideAudio.loop = true; SlideAudio.volume = 0; }
private void setSlideTargetVolumes(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit) { //log("Sliding! " + gameObject.name + " against " + otherObject.name + " - Relative Velocity: " + relativeVelocity + ", Normal: " + normal + ", Contact Point: " + contactPoint + ", Exit: " + exit); if (SoundMaterial == null || !this.enabled || SoundMaterial.AudioSets.Count == 0) { return; } PhysSoundMaterial m = null; PhysSoundBase b = otherObject == null ? null : otherObject.GetComponent <PhysSoundBase>(); if (b) { //Special case for sliding against a terrain if (b is PhysSoundTerrain) { PhysSoundTerrain terr = b as PhysSoundTerrain; Dictionary <int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint); foreach (PhysSoundAudioContainer c in _audioContainersDic.Values) { PhysSoundComposition comp; float mod = 0; if (compDic.TryGetValue(c.KeyIndex, out comp)) { mod = comp.GetAverage(); } c.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit, mod); } return; } else { m = b.GetPhysSoundMaterial(contactPoint); } } //General cases //If the other object has a PhysSound material if (m) { PhysSoundAudioContainer aud; if (_audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit); } else if (!SoundMaterial.HasAudioSet(m.MaterialTypeKey) && SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit); } } //If it doesnt we set volumes based on the fallback setting of our material else { PhysSoundAudioContainer aud; if (SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud)) { aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit); } } }
public override void OnInspectorGUI() { mat = target as PhysSoundMaterial; bool dupeFound = false; bool nullFound = false; pitchRand = serializedObject.FindProperty("PitchRandomness"); scaleMod = serializedObject.FindProperty("ScaleMod"); slidePitchMod = serializedObject.FindProperty("SlidePitchMod"); slideVolMult = serializedObject.FindProperty("SlideVolMultiplier"); useColVel = serializedObject.FindProperty("UseCollisionVelocity"); scImpVol = serializedObject.FindProperty("ScaleImpactVolume"); relVelThr = serializedObject.FindProperty("RelativeVelocityThreshold"); impNormBias = serializedObject.FindProperty("ImpactNormalBias"); collMask = serializedObject.FindProperty("CollisionMask"); serializedObject.Update(); EditorGUILayout.LabelField("General Properties:", EditorStyles.boldLabel); mat.MaterialTypeKey = EditorGUILayout.Popup("Material Type", mat.MaterialTypeKey, PhysSoundTypeList.PhysSoundTypes); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(relVelThr, true); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(pitchRand); EditorGUILayout.Slider(scaleMod, 0, 1, "Object Scale Mod"); EditorGUILayout.Slider(impNormBias, 0, 1, "Impact Normal Bias"); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(slidePitchMod); EditorGUILayout.PropertyField(slideVolMult); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(collMask); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(useColVel); EditorGUILayout.PropertyField(scImpVol); EditorGUILayout.Separator(); GUILayout.Box("", GUILayout.MaxWidth(Screen.width - 25f), GUILayout.Height(dividerHeight)); EditorGUILayout.LabelField("Audio Sets:", EditorStyles.boldLabel); if (mat.AudioSets.Count == 0) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("The Audio Set List is Empty.", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { mat.FallbackTypeIndex = EditorGUILayout.Popup("Fallback Audio Set", mat.FallbackTypeIndex, mat.GetFallbackAudioSets()); if (mat.UseCollisionVelocity) { EditorGUILayout.HelpBox("You are using Collision Velocity. Remember that Impact clips must be ordered from least forceful to most forceful.", MessageType.Info); } EditorGUILayout.Separator(); audioSetFoldout.Update(mat.AudioSets.Count, false); impactsFoldout.Update(mat.AudioSets.Count, false); for (int i = 0; i < mat.AudioSets.Count; i++) { PhysSoundAudioSet aud = mat.AudioSets[i]; Color c = GUI.color; if (hasDuplicate(aud)) { dupeFound = true; GUI.color = new Color(1, 0.5f, 0.5f); } if (!PhysSoundTypeList.HasKey(aud.Key)) { nullFound = true; GUI.color = new Color(1, 0.5f, 0.5f); } EditorGUILayout.BeginHorizontal(); audioSetFoldout[i] = EditorGUILayout.Foldout(audioSetFoldout[i], "Material Type:"); GUILayout.Space(35); aud.Key = EditorGUILayout.Popup(aud.Key, PhysSoundTypeList.PhysSoundTypes); GUILayout.FlexibleSpace(); GUI.color = c * new Color(1, 1, 0.5f); if (GUILayout.Button("Remove", GUILayout.MaxWidth(75), GUILayout.MaxHeight(17))) { mat.AudioSets.RemoveAt(i); i--; continue; } GUI.color = c; EditorGUILayout.EndHorizontal(); if (audioSetFoldout[i]) { GUILayout.BeginVertical(EditorStyles.textField); GUILayout.Space(3); EditorGUI.indentLevel++; impactsFoldout[i] = EditorGUILayout.Foldout(impactsFoldout[i], "Impact Clips"); if (impactsFoldout[i]) { AudioClip newClip = null; newClip = EditorGUILayout.ObjectField("Add Clip", newClip, typeof(AudioClip), true) as AudioClip; if (newClip != null) { aud.Impacts.Add(newClip); } for (int j = 0; j < aud.Impacts.Count; j++) { GUILayout.BeginHorizontal(); aud.Impacts[j] = EditorGUILayout.ObjectField(aud.Impacts[j], typeof(AudioClip), true) as AudioClip; if (GUILayout.Button("X", GUILayout.MaxWidth(18), GUILayout.MaxHeight(15))) { aud.Impacts.RemoveAt(j); i--; } GUILayout.EndHorizontal(); } EditorGUILayout.Separator(); } EditorGUI.indentLevel--; aud.Slide = EditorGUILayout.ObjectField("Slide Clip", aud.Slide, typeof(AudioClip), true) as AudioClip; GUILayout.Space(3); GUILayout.EndVertical(); } GUILayout.Space(2); } } GUILayout.Space(2); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add New Audio Set", GUILayout.MaxWidth(150), GUILayout.Height(25))) { mat.AudioSets.Add(new PhysSoundAudioSet()); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (dupeFound) { EditorGUILayout.HelpBox("You have multiple Audio Sets with for the same Material Type! Any duplicate sets will not be used during runtime.", MessageType.Error); } if (nullFound) { EditorGUILayout.HelpBox("You have Audio Sets with invalid material types!", MessageType.Error); } EditorUtility.SetDirty(mat); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Gets the impact audio clip based on the given object that was hit, the velocity of the collision, the normal, and the contact point. /// </summary> public AudioClip GetImpactAudio(GameObject otherObject, Vector3 relativeVel, Vector3 norm, Vector3 contact, int layer = -1) { if (audioSetDic == null) { return(null); } if (!CollideWith(otherObject)) { return(null); } PhysSoundMaterial m = null; PhysSoundBase b = otherObject.GetComponent <PhysSoundBase>(); if (b) { m = b.GetPhysSoundMaterial(contact); } //Get sounds using collision velocity if (UseCollisionVelocity) { float velNorm = GetImpactVolume(relativeVel, norm); if (velNorm < 0) { return(null); } if (m) { PhysSoundAudioSet audSet; if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet)) { return(audSet.GetImpact(velNorm, false)); } else if (FallbackTypeKey != -1) { return(audioSetDic[FallbackTypeKey].GetImpact(velNorm, false)); } } else if (FallbackTypeKey != -1) { return(audioSetDic[FallbackTypeKey].GetImpact(velNorm, false)); } } //Get sound randomly else { if (m) { PhysSoundAudioSet audSet; if (audioSetDic.TryGetValue(m.MaterialTypeKey, out audSet)) { return(audSet.GetImpact(0, true)); } else if (FallbackTypeKey != -1) { return(audioSetDic[FallbackTypeKey].GetImpact(0, true)); } } else if (FallbackTypeKey != -1) { return(audioSetDic[FallbackTypeKey].GetImpact(0, true)); } } return(null); }
public override void OnInspectorGUI() { mat = target as PhysSoundMaterial; bool dupeFound = false; bool nullFound = false; pitchRand = serializedObject.FindProperty("PitchRandomness"); slidePitchMod = serializedObject.FindProperty("SlidePitchMod"); useColVel = serializedObject.FindProperty("UseCollisionVelocity"); scImpVol = serializedObject.FindProperty("ScaleImpactVolume"); relVelThr = serializedObject.FindProperty("RelativeVelocityThreshold"); impNormBias = serializedObject.FindProperty("ImpactNormalBias"); serializedObject.Update(); EditorGUILayout.LabelField("General Properties:", EditorStyles.boldLabel); mat.MaterialTypeKey = EditorGUILayout.Popup("Material Type", mat.MaterialTypeKey, PhysSoundTypeList.PhysSoundTypes); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(pitchRand); EditorGUILayout.PropertyField(slidePitchMod); EditorGUILayout.PropertyField(relVelThr, true); EditorGUILayout.Slider(impNormBias, 0, 1, "Impact Normal Bias"); EditorGUILayout.Separator(); EditorGUILayout.PropertyField(useColVel); EditorGUILayout.PropertyField(scImpVol); EditorGUILayout.Separator(); GUILayout.Box("", GUILayout.MaxWidth(Screen.width - 25f), GUILayout.Height(dividerHeight)); EditorGUILayout.LabelField("Audio Sets:", EditorStyles.boldLabel); if (mat.AudioSets.Count == 0) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("The Audio Set List is Empty.", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { mat.FallbackTypeIndex = EditorGUILayout.Popup("Fallback Audio Set", mat.FallbackTypeIndex, mat.GetFallbackAudioSets()); if (mat.UseCollisionVelocity) EditorGUILayout.HelpBox("You are using Collision Velocity. Remember that Impact clips must be ordered from least forceful to most forceful.", MessageType.Info); EditorGUILayout.Separator(); audioSetFoldout.Update(mat.AudioSets.Count, false); impactsFoldout.Update(mat.AudioSets.Count, false); for (int i = 0; i < mat.AudioSets.Count; i++) { PhysSoundAudioSet aud = mat.AudioSets[i]; if (hasDuplicate(aud)) { dupeFound = true; GUI.color = new Color(1, 0.5f, 0.5f); } if (!PhysSoundTypeList.HasKey(aud.Key)) { nullFound = true; GUI.color = new Color(1, 0.5f, 0.5f); } EditorGUILayout.BeginHorizontal(); audioSetFoldout[i] = EditorGUILayout.Foldout(audioSetFoldout[i], "Material Type:"); GUILayout.Space(35); aud.Key = EditorGUILayout.Popup(aud.Key, PhysSoundTypeList.PhysSoundTypes); GUILayout.FlexibleSpace(); Color c = GUI.color; GUI.color = new Color(1, 1, 0.5f); if (GUILayout.Button("Remove", GUILayout.MaxWidth(75), GUILayout.MaxHeight(17))) { mat.AudioSets.RemoveAt(i); i--; continue; } GUI.color = c; EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (audioSetFoldout[i]) { GUILayout.BeginVertical(EditorStyles.textField); GUILayout.Space(3); GUILayout.BeginHorizontal(); GUILayout.Space(5); GUILayout.BeginVertical(); impactsFoldout[i] = EditorGUILayout.Foldout(impactsFoldout[i], "Impact Clips"); if (impactsFoldout[i]) { AudioClip newClip = null; newClip = EditorGUILayout.ObjectField("Add Clip", newClip, typeof(AudioClip), true) as AudioClip; if (newClip != null) { aud.Impacts.Add(newClip); } for (int j = 0; j < aud.Impacts.Count; j++) { GUILayout.BeginHorizontal(); aud.Impacts[j] = EditorGUILayout.ObjectField(aud.Impacts[j], typeof(AudioClip), true) as AudioClip; if (GUILayout.Button("X", GUILayout.MaxWidth(18), GUILayout.MaxHeight(18))) { aud.Impacts.RemoveAt(j); i--; } GUILayout.EndHorizontal(); } EditorGUILayout.Separator(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); aud.Slide = EditorGUILayout.ObjectField("Slide Clip", aud.Slide, typeof(AudioClip), true) as AudioClip; GUILayout.Space(3); GUILayout.EndVertical(); } GUILayout.Space(2); } } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add New Audio Set", GUILayout.MaxWidth(150), GUILayout.Height(25))) { mat.AudioSets.Add(new PhysSoundAudioSet()); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (dupeFound) EditorGUILayout.HelpBox("You have multiple Audio Sets with for the same Material Type! Any duplicate sets will not be used during runtime.", MessageType.Error); if (nullFound) EditorGUILayout.HelpBox("You have Audio Sets with invalid material types!", MessageType.Error); EditorUtility.SetDirty(mat); serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Sets the target volume and pitch of the sliding sound effect based on the given object that was hit, velocity, and normal. /// </summary> public void SetTargetVolumeAndPitch(PhysSoundMaterial mat, Vector3 relativeVelocity, Vector3 normal, bool exit, float mod = 1) { if (SlideAudio == null) return; if (!SlideAudio.isPlaying) { basePitchRand = basePitch + Random.Range(-mat.PitchRandomness, mat.PitchRandomness); SlideAudio.Play(); } SlideAudio.pitch = basePitchRand + relativeVelocity.magnitude * mat.SlidePitchMod; targetVolume = exit ? 0 : mat.GetSlideVolume(relativeVelocity, normal) * baseVol * mod; }
// Token: 0x06003FCA RID: 16330 RVA: 0x00140500 File Offset: 0x0013E900 public KeyValuePair <int, int>?GetImpactAudio(GameObject otherObject, Vector3 relativeVel, Vector3 norm, Vector3 contact, int layer = -1) { if (this.audioSetDic == null) { return(null); } if (!this.CollideWith(otherObject)) { return(null); } PhysSoundMaterial physSoundMaterial = null; PhysSoundBase component = otherObject.GetComponent <PhysSoundBase>(); if (component) { physSoundMaterial = component.GetPhysSoundMaterial(contact); } int key = 0; int?num = null; if (this.UseCollisionVelocity) { float impactVolume = this.GetImpactVolume(relativeVel, norm); if (impactVolume < 0f) { return(null); } if (physSoundMaterial) { PhysSoundAudioSet physSoundAudioSet; if (this.audioSetDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioSet)) { key = physSoundMaterial.MaterialTypeKey; num = physSoundAudioSet.GetImpact(impactVolume, false); } else if (this.FallbackTypeKey != -1) { key = this.FallbackTypeKey; num = physSoundAudioSet.GetImpact(impactVolume, false); } } else if (this.FallbackTypeKey != -1) { key = this.FallbackTypeKey; num = this.audioSetDic[this.FallbackTypeKey].GetImpact(impactVolume, false); } } else if (physSoundMaterial) { PhysSoundAudioSet physSoundAudioSet2; if (this.audioSetDic.TryGetValue(physSoundMaterial.MaterialTypeKey, out physSoundAudioSet2)) { key = physSoundMaterial.MaterialTypeKey; num = physSoundAudioSet2.GetImpact(0f, true); } else if (this.FallbackTypeKey != -1) { key = this.FallbackTypeKey; num = physSoundAudioSet2.GetImpact(0f, true); } } else if (this.FallbackTypeKey != -1) { key = this.FallbackTypeKey; num = this.audioSetDic[this.FallbackTypeKey].GetImpact(0f, true); } if (num != null) { return(new KeyValuePair <int, int>?(new KeyValuePair <int, int>(key, num.Value))); } return(null); }