void DisableGameObject(AkGameObj game_obj)
        {
            if (game_obj != null)
            {
                //
                // Disable the collider and GameObject to save processing the object
                // whilst it is not doing anything.
                //
                Collider collider = game_obj.GetComponent <Collider>();
                if (collider != null)
                {
                    collider.enabled = false;
                }

                MeshRenderer renderer = game_obj.GetComponent <MeshRenderer>();
                if (renderer != null)
                {
                    renderer.enabled = false;
                }
                game_obj.gameObject.SetActive(false);
            }
        }
        public override void Play(NVRCollisionSoundMaterials material, Vector3 position, float impactVolume)
        {
            if (!mWwiseAvailable)
            {
                return;
            }
            if (material == NVRCollisionSoundMaterials.none)
            {
                return;
            }

            string event_name = EventStrings[material];

            AkGameObj game_obj = AudioPool[CurrentPoolIndex];

            CurrentPoolIndex++;
            if (CurrentPoolIndex >= AudioPool.Length)
            {
                CurrentPoolIndex = 0;
            }

            game_obj.gameObject.SetActive(true);
            Collider collider = game_obj.GetComponent <Collider>();

            if (collider != null)
            {
                collider.enabled = true;
            }

            if (showCollisions)
            {
                MeshRenderer renderer = game_obj.GetComponent <MeshRenderer>();
                if (renderer != null)
                {
                    renderer.enabled = true;
                }
            }

            //
            // Position the object and post the event.
            //
            game_obj.transform.position = position;

            //
            // use the impactVolume to control the sound
            //
            float impact_value = impactVolume * 100.0f;

            //Debug.Log("impactVolume = " + impactVolume);
            AkSoundEngine.SetRTPCValue(mImpactVolumeControlId, impact_value, AudioPool[CurrentPoolIndex].gameObject);

            //Debug.Log("Position in Unity: " + AudioPool[CurrentPoolIndex].transform.position +
            //    " position in Wise: " + AudioPool[CurrentPoolIndex].GetPosition());
            uint res = AkSoundEngine.PostEvent(event_name, AudioPool[CurrentPoolIndex].gameObject,
                                               (uint)AkCallbackType.AK_EndOfEvent, DisableGameObjectCallback, game_obj);

            if (res == AkSoundEngine.AK_INVALID_PLAYING_ID)
            {
                //
                // Failed to play the sound
                //
                DisableGameObject(game_obj);
            }
        }
    public override void OnInspectorGUI()
    {
        GUILayout.BeginVertical("Box");

        // Unity tries to construct a AkGameObjPositionOffsetData all the time. Need this ugly workaround
        // to prevent it from doing this.
        if (m_AkGameObject.m_positionOffsetData != null)
        {
            if (!m_AkGameObject.m_positionOffsetData.KeepMe)
            {
                m_AkGameObject.m_positionOffsetData = null;
            }
        }

        bool applyPosOffset = m_AkGameObject.m_positionOffsetData != null;

        applyPosOffset = EditorGUILayout.Toggle("Apply Position Offset: ", applyPosOffset);
        if (m_AkGameObject.m_positionOffsetData == null && applyPosOffset)
        {
            m_AkGameObject.m_positionOffsetData = new AkGameObjPositionOffsetData(true);
        }
        else if (!applyPosOffset && m_AkGameObject.m_positionOffsetData != null)
        {
            m_AkGameObject.m_positionOffsetData = null;
        }

        if (m_AkGameObject.m_positionOffsetData != null)
        {
            m_AkGameObject.m_positionOffsetData.positionOffset = EditorGUILayout.Vector3Field("Position Offset", m_AkGameObject.m_positionOffsetData.positionOffset);

            GUILayout.Space(2);

            if (hideDefaultHandle)
            {
                if (GUILayout.Button("Show Main Transform"))
                {
                    hideDefaultHandle     = false;
                    DefaultHandles.Hidden = hideDefaultHandle;
                }
            }
            else
            {
                if (GUILayout.Button("Hide Main Transform"))
                {
                    hideDefaultHandle     = true;
                    DefaultHandles.Hidden = hideDefaultHandle;
                }
            }
        }
        else
        {
            if (hideDefaultHandle == true)
            {
                hideDefaultHandle     = false;
                DefaultHandles.Hidden = hideDefaultHandle;
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);

        GUILayout.BeginVertical("Box");


        m_AkGameObject.isEnvironmentAware = EditorGUILayout.Toggle("Environment Aware: ", m_AkGameObject.isEnvironmentAware);

        if (m_AkGameObject.isEnvironmentAware && m_AkGameObject.GetComponent <Rigidbody>() == null)
        {
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;
            style.wordWrap         = true;
            GUILayout.Label("Objects affected by Environment need to have a RigidBody attached.", style);
            if (GUILayout.Button("Add Rigidbody!"))
            {
                Rigidbody rb = m_AkGameObject.gameObject.AddComponent <Rigidbody>();
                rb.useGravity  = false;
                rb.isKinematic = true;
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);

        string [] maskLabels = new string[AkSoundEngine.AK_NUM_LISTENERS];
        for (int i = 0; i < AkSoundEngine.AK_NUM_LISTENERS; i++)
        {
            maskLabels[i] = "L" + i;
        }
        m_AkGameObject.listenerMask = EditorGUILayout.MaskField("Listeners", m_AkGameObject.listenerMask, maskLabels);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(m_AkGameObject);
        }
    }
    public override void OnInspectorGUI()
    {
        GUILayout.BeginVertical("Box");

        bool applyPosOffset = m_AkGameObject.m_posOffsetData != null;

        applyPosOffset = EditorGUILayout.Toggle("Apply Position Offset: ", applyPosOffset);
        if (m_AkGameObject.m_posOffsetData == null && applyPosOffset)
        {
            m_AkGameObject.m_posOffsetData = ScriptableObject.CreateInstance <AkGameObjPosOffsetData>();
        }
        else if (!applyPosOffset)
        {
            m_AkGameObject.m_posOffsetData = null;
        }

        if (m_AkGameObject.m_posOffsetData != null)
        {
            m_AkGameObject.m_posOffsetData.positionOffset = EditorGUILayout.Vector3Field("Position Offset", m_AkGameObject.m_posOffsetData.positionOffset);

            GUILayout.Space(2);

            if (hideDefaultHandle)
            {
                if (GUILayout.Button("Show Main Transform"))
                {
                    hideDefaultHandle     = false;
                    DefaultHandles.Hidden = hideDefaultHandle;
                }
            }
            else
            {
                if (GUILayout.Button("Hide Main Transform"))
                {
                    hideDefaultHandle     = true;
                    DefaultHandles.Hidden = hideDefaultHandle;
                }
            }
        }
        else
        {
            if (hideDefaultHandle == true)
            {
                hideDefaultHandle     = false;
                DefaultHandles.Hidden = hideDefaultHandle;
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);

        GUILayout.BeginVertical("Box");


        m_AkGameObject.isEnvironmentAware = EditorGUILayout.Toggle("Environment Aware: ", m_AkGameObject.isEnvironmentAware);

        if (m_AkGameObject.isEnvironmentAware && m_AkGameObject.GetComponent <Rigidbody>() == null)
        {
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;
            style.wordWrap         = true;
            GUILayout.Label("Objects affected by Environment need to have a RigidBody attached.", style);
            if (GUILayout.Button("Add Rigidbody!"))
            {
                Rigidbody rb = m_AkGameObject.gameObject.AddComponent <Rigidbody>();
                rb.useGravity  = false;
                rb.isKinematic = true;
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);


        if (GUI.changed)
        {
            EditorUtility.SetDirty(m_AkGameObject);
        }
    }
示例#5
0
    public override void OnInspectorGUI()
    {
        // Unity tries to construct a AkGameObjPositionOffsetData all the time. Need this ugly workaround
        // to prevent it from doing this.
        if (m_AkGameObject.m_positionOffsetData != null)
        {
            if (!m_AkGameObject.m_positionOffsetData.KeepMe)
            {
                m_AkGameObject.m_positionOffsetData = null;
            }
        }

        AkGameObjPositionOffsetData positionOffsetData = m_AkGameObject.m_positionOffsetData;
        Vector3 positionOffset = Vector3.zero;

#if UNITY_5_3_OR_NEWER
        EditorGUI.BeginChangeCheck();
#endif

        GUILayout.BeginVertical("Box");

        bool applyPosOffset = EditorGUILayout.Toggle("Apply Position Offset:", positionOffsetData != null);

        if (applyPosOffset != (positionOffsetData != null))
        {
            positionOffsetData = applyPosOffset ? new AkGameObjPositionOffsetData(true) : null;
        }

        if (positionOffsetData != null)
        {
            positionOffset = EditorGUILayout.Vector3Field("Position Offset", positionOffsetData.positionOffset);

            GUILayout.Space(2);

            if (hideDefaultHandle)
            {
                if (GUILayout.Button("Show Main Transform"))
                {
                    hideDefaultHandle     = false;
                    DefaultHandles.Hidden = hideDefaultHandle;
                }
            }
            else if (GUILayout.Button("Hide Main Transform"))
            {
                hideDefaultHandle     = true;
                DefaultHandles.Hidden = hideDefaultHandle;
            }
        }
        else if (hideDefaultHandle)
        {
            hideDefaultHandle     = false;
            DefaultHandles.Hidden = hideDefaultHandle;
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);

        GUILayout.BeginVertical("Box");

        bool isEnvironmentAware = EditorGUILayout.Toggle("Environment Aware:", m_AkGameObject.isEnvironmentAware);

        if (isEnvironmentAware && m_AkGameObject.GetComponent <Rigidbody>() == null)
        {
            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;
            style.wordWrap         = true;
            GUILayout.Label("Objects affected by Environment need to have a RigidBody attached.", style);
            if (GUILayout.Button("Add Rigidbody!"))
            {
                Rigidbody rb = m_AkGameObject.gameObject.AddComponent <Rigidbody>();
                rb.useGravity  = false;
                rb.isKinematic = true;
            }
        }

        GUILayout.EndVertical();

        GUILayout.Space(3);

        string[] maskLabels = new string[AkSoundEngine.AK_NUM_LISTENERS];
        for (int i = 0; i < AkSoundEngine.AK_NUM_LISTENERS; i++)
        {
            maskLabels[i] = "L" + i;
        }

        int listenerMask = EditorGUILayout.MaskField("Listeners", m_AkGameObject.listenerMask, maskLabels);

#if UNITY_5_3_OR_NEWER
        if (EditorGUI.EndChangeCheck())
#else
        if (GUI.changed)
#endif
        {
#if UNITY_5_3_OR_NEWER
            Undo.RecordObject(target, "AkGameObj Parameter Change");
#endif
            m_AkGameObject.m_positionOffsetData = positionOffsetData;

            if (positionOffsetData != null)
            {
                m_AkGameObject.m_positionOffsetData.positionOffset = positionOffset;
            }

            m_AkGameObject.isEnvironmentAware = isEnvironmentAware;
            m_AkGameObject.listenerMask       = listenerMask;

#if !UNITY_5_3_OR_NEWER
            EditorUtility.SetDirty(m_AkGameObject);
#endif
        }
    }