SetObjectObstructionAndOcclusion() public static method

public static SetObjectObstructionAndOcclusion ( UnityEngine in_ObjectID, uint in_uListener, float in_fObstructionLevel, float in_fOcclusionLevel ) : AKRESULT
in_ObjectID UnityEngine
in_uListener uint
in_fObstructionLevel float
in_fOcclusionLevel float
return AKRESULT
    private void Update()
    {
        bool useSpatialAudio = AkRoom.IsSpatialAudioEnabled;

        // Update Listeners
        if (useSpatialAudio)
        {
            UpdateObstructionOcclusionValues(AkSpatialAudioListener.TheSpatialAudioListener);
        }
        else
        {
            UpdateObstructionOcclusionValues(m_gameObj.ListenerList);
        }

        CastRays();

        // Set Obstruction/Occlusion
        foreach (var ObsOccPair in ObstructionOcclusionValues)
        {
            var ObsOccValue = ObsOccPair.Value;

            if (ObsOccValue.Update(fadeRate))
            {
                if (useSpatialAudio)
                {
                    AkSoundEngine.SetEmitterObstruction(gameObject, ObsOccValue.currentValue);
                }
                else
                {
                    AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, 0.0f, ObsOccValue.currentValue);
                }
            }
        }
    }
 protected override void SetObstructionOcclusion(
     System.Collections.Generic.KeyValuePair <AkAudioListener, ObstructionOcclusionValue> ObsOccPair)
 {
     if (AkSpatialAudioListener.TheSpatialAudioListener != null && AkRoom.RoomCount > 0)
     {
         AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, ObsOccPair.Value.currentValue, 0.0f);
     }
     else
     {
         AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, 0.0f, ObsOccPair.Value.currentValue);
     }
 }
 protected override void SetObstructionOcclusion(
     System.Collections.Generic.KeyValuePair <AkAudioListener, ObstructionOcclusionValue> ObsOccPair)
 {
     if (AkRoom.IsSpatialAudioEnabled)
     {
         AkSoundEngine.SetEmitterObstruction(gameObject, ObsOccPair.Value.currentValue);
     }
     else
     {
         AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, 0.0f,
                                                        ObsOccPair.Value.currentValue);
     }
 }
Ejemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.A))
     {
         Debug.Log("OCCLUDE");
         AudioManager.Instance.SetOcclusion(100, .25f, gameObject);
     }
     if (Input.GetKeyDown(KeyCode.B))
     {
         Debug.Log("OCCLUDE");
         AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, GameObject.Find("Camera (eye)"), 100, 100);
     }
 }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        // Init
        RaycastHit hitInfo;
        float      playerDistance;
        Vector3    originPosition = origin.gameObject.transform.position;

        originPosition.y += 1.5f;

        // Calc
        Vector3 current_position = transform.position;

        current_position.y += 1f;
        Vector3 raycastDir = originPosition - current_position;

        playerDistance = Vector3.Distance(current_position, originPosition);
        if (playerDistance > 50)
        {
            return;
        }
        // Check if something occlude
        if (Physics.Raycast(new Ray(current_position, raycastDir), out hitInfo, playerDistance, layerMaskOcclusion))
        {
            // Hit wall
            //print("hit:"+hitInfo.collider.gameObject.name);
            Debug.DrawRay(current_position, raycastDir, Color.red);
            if (current_occlusion < 100.0f)
            {
                current_occlusion += max_occlusion / (time_end / Time.deltaTime);
            }
        }
        else
        {
            // Don't hit wall
            Debug.DrawRay(current_position, raycastDir, Color.blue);
            if (current_occlusion > 0.0f)
            {
                current_occlusion -= max_occlusion / (time_start / Time.deltaTime);
            }
        }

        // Occlusion
        current_occlusion = Mathf.Clamp(current_occlusion, 0, max_occlusion);
        //print(current_occlusion);

        // Wwise
        AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, listener, 0.0f, current_occlusion / 100f);
    }
Ejemplo n.º 6
0
 public void SetOcclusion(float obstrLvl, float occlusionLevel, GameObject objectToOcc)
 {
     AkSoundEngine.SetObjectObstructionAndOcclusion(objectToOcc, _player, obstrLvl, occlusionLevel);
     //AkSoundEngine.SetObjectObstructionAndOcclusion(objectToOcc, _player, 0, 0);
 }
Ejemplo n.º 7
0
    void OcclusionCalc()
    {
        maxAtt      = AkSoundEngine.GetMaxRadius(gameObject); //getting attenuation data from sound source
        originPoint = transform.position;                     //coordinates of soundsource
        playerPoint = gameObjectPlayer.transform.position;    //coordinates of Player


        //we are gonna control occlusion only based on the wall thickness (distance between point of raycast hitting 1st wall and point of raycast goes out of the wall to hit the Player)

        if (distToPlayer <= maxAtt) //raycasting starts once Player is within the attenuation radius
        {
            targetDirection1 = playerPoint - originPoint;
            distToPlayer     = Vector3.Distance(playerPoint, originPoint);
            if (Physics.Raycast(originPoint, targetDirection1, out hitInfo1, distToPlayer, layerMask))
            {
                wallPointIn = hitInfo1.point;

                targetDirection2 = Vector3.zero - targetDirection1;
                if (Physics.Raycast(playerPoint, targetDirection2, out hitInfo2, distToPlayer, layerMask))
                {
                    wallPointOut = hitInfo2.point;
                    if (Physics.Raycast(playerPoint, Vector3.down, 2.0f, layerMask))
                    {
                        insideRoom = true;
                    }
                    else
                    {
                        insideRoom = false;
                    }
                }
                else
                {
                    wallPointOut = Vector3.zero;
                }
            }

            else
            {
                wallPointIn = Vector3.zero;
            }

            if (wallPointIn == Vector3.zero)
            {
                wwiseOcclusion = 0.0f;
            }

            else
            {
                wallThickness  = Vector3.Distance(wallPointOut, wallPointIn);
                wwiseOcclusion = wallThickness / maxWallThickness;
                if (insideRoom == true)
                {
                    wwiseOcclusion += 1.0f;
                }

                if (wwiseOcclusion > 1.0f)
                {
                    wwiseOcclusion = 1.0f;
                }
            }

            AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, gameObjectListener, 0.0f, wwiseOcclusion);
        }
    }