예제 #1
0
        /// <summary>
        /// Step on Terrain
        /// </summary>
        /// <param name="footStepObject"></param>
        public void StepOnTerrain(FootStepObject footStepObject)
        {
            if (currentStep != null && currentStep == footStepObject.sender)
            {
                return;
            }
            currentStep = footStepObject.sender;

            if (terrainData)
            {
                surfaceIndex = GetMainTexture(footStepObject.sender.position);
            }

            //bool valid = (terrainData != null && terrainData.splatPrototypes != null && terrainData.splatPrototypes.Length > 0
            //&& terrainData.splatPrototypes.Length <= surfaceIndex && terrainData.splatPrototypes[surfaceIndex].texture != null);
            var name = (terrainData != null && terrainData.splatPrototypes.Length > 0)? (terrainData.splatPrototypes[surfaceIndex]).texture.name:"";

            footStepObject.name = name;
            PlayFootFallSound(footStepObject);

            if (debugTextureName)
            {
                Debug.Log(name);
            }
        }
예제 #2
0
 /// <summary>
 /// Step on Mesh
 /// </summary>
 /// <param name="footStepObject"></param>
 public void StepOnMesh(FootStepObject footStepObject)
 {
     if (currentStep != null && currentStep == footStepObject.sender)
     {
         return;
     }
     currentStep = footStepObject.sender;
     PlayFootFallSound(footStepObject);
     if (debugTextureName)
     {
         Debug.Log(footStepObject.name);
     }
 }
예제 #3
0
        void StepMark(FootStepObject footStep)
        {
            RaycastHit hit;

            if (Physics.Raycast(footStep.sender.transform.position + new Vector3(0, 0.1f, 0), -footStep.sender.up, out hit, 1f, stepLayer))
            {
                if (stepMark)
                {
                    var angle = Quaternion.FromToRotation(footStep.sender.up, hit.normal);
                    var step  = Instantiate(stepMark, hit.point, angle * footStep.sender.rotation) as GameObject;
                    //step.transform.SetParent(footStep.ground.transform);
                    Destroy(step, timeToDestroy);
                }
            }
        }
예제 #4
0
 public void PlayFootFallSound(FootStepObject footStepObject)
 {
     for (int i = 0; i < customSurfaces.Count; i++)
     {
         if (customSurfaces[i] != null && ContainsTexture(footStepObject.name, customSurfaces[i]))
         {
             customSurfaces[i].PlayRandomClip(footStepObject);
             return;
         }
     }
     if (defaultSurface != null)
     {
         defaultSurface.PlayRandomClip(footStepObject);
     }
 }
예제 #5
0
        public void PlayRandomClip(FootStepObject footStepObject)
        {
            // if there are no clips to play return.
            if (audioClips == null || audioClips.Count == 0)
            {
                return;
            }

            // initialize variable if not already started
            if (randomSource == null)
            {
                randomSource = new vFisherYatesRandom();
            }

            // find a random clip and play it.
            GameObject audioObject = null;

            if (audioSource != null)
            {
                audioObject = Instantiate(audioSource.gameObject, footStepObject.sender.position, Quaternion.identity) as GameObject;
            }
            else
            {
                audioObject = new GameObject("audioObject");
                audioObject.transform.position = footStepObject.sender.position;
            }

            var source = audioObject.AddComponent <vAudioSurfaceControl>();

            if (audioMixerGroup != null)
            {
                source.outputAudioMixerGroup = audioMixerGroup;
            }
            int index = randomSource.Next(audioClips.Count);

            if (particleObject && footStepObject.ground && stepLayer.ContainsLayer(footStepObject.ground.gameObject.layer))
            {
                Instantiate(particleObject, footStepObject.sender.position, footStepObject.sender.rotation);
            }
            if (useStepMark)
            {
                StepMark(footStepObject);
            }

            source.PlayOneShot(audioClips[index]);
        }