Exemple #1
0
        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);
                }
            }
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            physTerr = target as PhysSoundTerrain;

            serializedObject.Update();

            if (physTerr.Terrain == null)
            {
                EditorGUILayout.HelpBox("No Terrain was found!", MessageType.Error);
                serializedObject.ApplyModifiedProperties();
                return;
            }

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("PhysSound Terrain Materials:", EditorStyles.boldLabel);

            matFoldout = EditorGUILayout.Foldout(matFoldout, "PhysSound Materials List");

            TerrainLayer[] tLayers = physTerr.Terrain.terrainData.terrainLayers;

            while (physTerr.SoundMaterials.Count > tLayers.Length)
            {
                physTerr.SoundMaterials.RemoveAt(physTerr.SoundMaterials.Count - 1);
            }

            if (matFoldout)
            {
                matScroll = EditorGUILayout.BeginScrollView(matScroll, GUILayout.MaxHeight(200));

                for (int i = 0; i < tLayers.Length; i++)
                {
                    if (i >= physTerr.SoundMaterials.Count)
                    {
                        physTerr.SoundMaterials.Add(null);
                    }

                    TerrainLayer t = tLayers[i];
                    //SplatPrototype sp = tLayers[i];
                    GUILayout.BeginHorizontal();

                    GUILayout.Box(t.diffuseTexture, GUILayout.Width(50), GUILayout.Height(50));

                    GUILayout.BeginVertical();
                    EditorGUILayout.LabelField("Splat Texture: " + t.diffuseTexture.name);
                    physTerr.SoundMaterials[i] = (PhysSoundMaterial)EditorGUILayout.ObjectField(physTerr.SoundMaterials[i], typeof(PhysSoundMaterial), false);
                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                    GUILayout.Box("", GUILayout.MaxWidth(Screen.width - 25f), GUILayout.Height(1));
                }
                EditorGUILayout.EndScrollView();
            }

            EditorGUILayout.Separator();
            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            physTerr = target as PhysSoundTerrain;

            serializedObject.Update();

            if (physTerr.Terrain == null)
            {
                EditorGUILayout.HelpBox("No Terrain was found!", MessageType.Error);
                serializedObject.ApplyModifiedProperties();
                return;
            }

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("PhysSound Terrain Materials:", EditorStyles.boldLabel);

            matFoldout = EditorGUILayout.Foldout(matFoldout, "PhysSound Materials List");

            SplatPrototype[] textures = physTerr.Terrain.terrainData.splatPrototypes;

            while (physTerr.SoundMaterials.Count > textures.Length)
            {
                physTerr.SoundMaterials.RemoveAt(physTerr.SoundMaterials.Count - 1);
            }

            if (matFoldout)
            {
                matScroll = EditorGUILayout.BeginScrollView(matScroll, GUILayout.MaxHeight(200));

                for (int i = 0; i < textures.Length; i++)
                {
                    if (i >= physTerr.SoundMaterials.Count)
                    {
                        physTerr.SoundMaterials.Add(null);
                    }

                    SplatPrototype sp = textures[i];
                    GUILayout.BeginHorizontal();

                    GUILayout.Box(sp.texture, GUILayout.Width(50), GUILayout.Height(50));

                    GUILayout.BeginVertical();
                    EditorGUILayout.LabelField("Splat Texture: " + sp.texture.name);
                    physTerr.SoundMaterials[i] = (PhysSoundMaterial)EditorGUILayout.ObjectField(physTerr.SoundMaterials[i], typeof(PhysSoundMaterial), false);
                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                    GUILayout.Box("", GUILayout.MaxWidth(Screen.width - 25f), GUILayout.Height(1));
                }
                EditorGUILayout.EndScrollView();
            }

            EditorGUILayout.Separator();
            serializedObject.ApplyModifiedProperties();
        }
        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);
                }
            }
        }
Exemple #5
0
 void Awake()
 {
     physTerr         = target as PhysSoundTerrain;
     physTerr.Terrain = physTerr.GetComponent <Terrain>();
 }
 void Awake()
 {
     physTerr = target as PhysSoundTerrain;
     physTerr.Terrain = physTerr.GetComponent<Terrain>();
 }