public void Init_Ref()
    {
        event_Instance    = RuntimeManager.CreateInstance(event_Ref);
        event_Description = RuntimeManager.GetEventDescription(event_Ref);
        event_Description.getMaximumDistance(out maxDistance);
        event_Description.getMinimumDistance(out minDistance);

        EventDescription isShyEventDescription;

        event_Instance.getDescription(out isShyEventDescription);
        PARAMETER_DESCRIPTION isShyParameterDescription;

        isShyEventDescription.getParameterDescriptionByName("isShy", out isShyParameterDescription);
        isShyParameterId = isShyParameterDescription.id;

        event_Description.is3D(out is3D);
        if (is3D)
        {
            Init_Attachment(transform, GetComponent <Rigidbody>());
        }
        if (playFromStart)
        {
            Init_Event();
        }
    }
        /// <summary>
        /// Get all important information of EventInstance
        /// </summary>
        /// <param name="eventInstance">current EvnentInstance</param>
        private void GetEventInfo(EventInstance eventInstance)
        {
            ///Create EventDescription
            EventDescription eventDescription = new EventDescription();

            eventInstance.getDescription(out eventDescription);

            ///Get min and max distance
            eventDescription.getMaximumDistance(out m_maxDistance);
            eventDescription.getMinimumDistance(out m_minumDistance);

            ///Get number of instance enabled
            eventDescription.getInstanceCount(out m_instanceCount);

            ///Check if has cue
            eventDescription.hasCue(out m_hasCue);

            eventInstance.getVolume(out m_volume, out m_maxVolume);

            ///Get all userPropery
            int _count;

            eventDescription.getUserPropertyCount(out _count);
            USER_PROPERTY[] userProperty = new USER_PROPERTY[_count];
            m_userProperty = new string[_count];

            for (int i = 0; i < _count; i++)
            {
                eventDescription.getUserPropertyByIndex(i, out userProperty[i]);
                m_userProperty[i] = userProperty[i].name + " | " + userProperty[i].stringValue();
            }

            ///Check if is 3D or 2D
            bool _is3D = false;

            eventDescription.is3D(out _is3D);
            if (_is3D)
            {
                m_soundType = SoundType.is3D;
            }
            else
            {
                m_soundType = SoundType.is2D;
            }
        }
Esempio n. 3
0
    /// <summary>
    /// Get all important information of EventInstance
    /// </summary>
    /// <param name="eventInstance">current EvnentInstance</param>
    private void GetEventInfo(EventInstance eventInstance)
    {
        ///Create EventDescription
        EventDescription eventDescription = new EventDescription();

        eventInstance.getDescription(out eventDescription);

        ///Get min and max distance
        eventDescription.getMaximumDistance(out m_maxDistance);
        eventDescription.getMinimumDistance(out m_minumDistance);

        //USER_PROPERTY ada;
        //int userPropertyCount;
        //eventDescription.getUserPropertyCount(out userPropertyCount);
        //Debug.Log(userPropertyCount);

        //for (int i = 0; i < userPropertyCount; i++)
        //{
        //    eventDescription.getUserPropertyByIndex(i, out ada);
        //    Debug.Log(ada.name);
        //}

        ///Get number of instance enabled
        eventDescription.getInstanceCount(out m_instanceCount);

        ///Check if has cue
        eventDescription.hasCue(out m_hasCue);

        ///Check if is 3D or 2D
        bool _is3D = false;

        eventDescription.is3D(out _is3D);
        if (_is3D)
        {
            m_soundType = SoundType.is3D;
        }
        else
        {
            m_soundType = SoundType.is2D;
        }
    }
Esempio n. 4
0
    // Gets the minimum attenuation on the 3D Object.
    public static float GetMinDistance(string eventName)
    {
        EventDescription description = RuntimeManager.GetEventDescription(eventName);

        float minDistance = 0;

        if (!description.isValid())
        {
            Debug.LogError("Invalid Event Name" + eventName);
            return(minDistance);
        }

        description.is3D(out bool is3D);
        if (!is3D)
        {
            Debug.LogError(eventName + "Does not have 3D Property set. Are you sure this is a 3D event?");
            return(minDistance);
        }

        description.getMinimumDistance(out minDistance);
        return(minDistance);
    }
Esempio n. 5
0
    void OnGUI()
    {
        boundactive = false;
        GUI.depth   = -5000;
        if (editing == this)
        {
            if (Vector3.Dot(Camera.main.transform.forward, (transform.position - Camera.main.transform.position).normalized) > 0.1f)
            {
                GUI.skin = gskin;
                Vector3 screenPoint = Camera.main.WorldToScreenPoint(transform.position);
                screenPoint.x -= 30f;
                screenPoint.y -= 25f;

                int height = 120;
                if (audioSrc.audioInst != null)
                {
                    int slidercnt = 0;
                    audioSrc.audioInst.getParameterCount(out slidercnt);
                    height = 304 + 25 * slidercnt;
                }

                GUI.BeginGroup(new Rect(screenPoint.x, Screen.height - screenPoint.y, 300, height));
                GUI.Box(new Rect(0, 0, 300, height), "");
                GUILayout.BeginHorizontal();
                GUILayout.Space(5);
                GUILayout.BeginVertical();
                GUILayout.Space(8);
                {
                    GUILayout.Label("Load Event");
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(13);
                        inputPath = GUILayout.TextField(inputPath, GUILayout.Width(200));
                        if (GUILayout.Button("Load", GUILayout.Width(50)))
                        {
                            audioSrc.path = inputPath;
                        }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(15);
                    GUILayout.Label("Audio Settings");
                    if (audioSrc.audioInst != null)
                    {
                        EventDescription desc = null;
                        audioSrc.audioInst.getDescription(out desc);
                        if (desc != null && desc.isValid())
                        {
                            bool is3D = false;
                            desc.is3D(out is3D);
                            bool isOneshot = false;
                            desc.isOneshot(out isOneshot);
                            float mindist = 0, maxdist = 0;
                            if (is3D)
                            {
                                desc.getMinimumDistance(out mindist);
                                desc.getMaximumDistance(out maxdist);
                                boundactive = true;
                                bound.transform.localScale = Vector3.one * audioSrc.maxDistance * 2f;
                            }
                            string is3Dstr = is3D ? "3D Sound" : "2D Sound";
                            string diststr = is3D ? ("Distance Area ( " + mindist.ToString("0.##") + "m ~ " + maxdist.ToString("0.##") + "m )") : ("");

                            if (listener != null)
                            {
                                LabelField("Distance", listenDist.ToString("#,##0.00") + " m");
                            }
                            else
                            {
                                LabelField("Distance", "-");
                            }

                            LabelField(is3Dstr, diststr);

                            audioSrc.minDistance = FloatField("Min Dist", audioSrc.minDistance);
                            audioSrc.maxDistance = FloatField("Max Dist", audioSrc.maxDistance);

                            LabelField("Is Oneshot", isOneshot.ToString());

                            audioSrc.volume = Slider("Volume", audioSrc.volume, 0f, 1f);
                            audioSrc.pitch  = Slider("Pitch", audioSrc.pitch, 0f, 4f);

                            int pcnt = 0;
                            audioSrc.audioInst.getParameterCount(out pcnt);

                            for (int i = 0; i < pcnt; ++i)
                            {
                                ParameterInstance pinst = null;
                                audioSrc.audioInst.getParameterByIndex(i, out pinst);
                                PARAMETER_DESCRIPTION pdesc = new PARAMETER_DESCRIPTION();
                                pinst.getDescription(out pdesc);
                                float val = 0f, _val = 0f;
                                pinst.getValue(out val);
                                _val = Slider(pdesc.name, val, pdesc.minimum, pdesc.maximum);
                                if (_val != val)
                                {
                                    pinst.setValue(_val);
                                }
                            }

                            GUILayout.Space(8);
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Space(17);
                                if (GUILayout.Button("Play", GUILayout.Width(80)))
                                {
                                    audioSrc.Play();
                                }
                                GUILayout.Space(4);
                                if (GUILayout.Button("Stop", GUILayout.Width(80)))
                                {
                                    audioSrc.Stop();
                                }
                                GUILayout.Space(4);
                                if (GUILayout.Button("Unload", GUILayout.Width(80)))
                                {
                                    audioSrc.path = "";
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(13);
                            GUILayout.Label("No Event Loaded");
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                GUI.EndGroup();
            }
            else
            {
                if (audioSrc.is3D)
                {
                    boundactive = true;
                    bound.transform.localScale = Vector3.one * audioSrc.maxDistance * 2f;
                }
            }
        }
    }
Esempio n. 6
0
 private void UpdateEventInfoList()
 {
     this.eventInfoList.Clear();
     try
     {
         FMOD.Studio.ATTRIBUTES_3D aTTRIBUTES_3D;
         FMOD_Listener.THROW_ERRORS(FMOD_StudioSystem.instance.System.getListenerAttributes(0, out aTTRIBUTES_3D));
         Vector3 b2    = aTTRIBUTES_3D.position.toUnityVector();
         Bank[]  array = null;
         FMOD_Listener.THROW_ERRORS(FMOD_StudioSystem.instance.System.getBankList(out array));
         Bank[] array2 = array;
         for (int i = 0; i < array2.Length; i++)
         {
             Bank bank = array2[i];
             try
             {
                 EventDescription[] array3 = null;
                 FMOD_Listener.THROW_ERRORS(bank.getEventList(out array3));
                 if (array3 != null)
                 {
                     EventDescription[] array4 = array3;
                     for (int j = 0; j < array4.Length; j++)
                     {
                         EventDescription eventDescription = array4[j];
                         int num = 0;
                         FMOD_Listener.THROW_ERRORS(eventDescription.getInstanceCount(out num));
                         if (num > 0)
                         {
                             FMOD_Listener.EventInfo item = default(FMOD_Listener.EventInfo);
                             item.streamCount = 0;
                             FMOD_Listener.THROW_ERRORS(eventDescription.getPath(out item.path));
                             if (FMOD_Listener.PathFilter.Length > 0)
                             {
                                 bool     flag       = false;
                                 string[] pathFilter = FMOD_Listener.PathFilter;
                                 for (int k = 0; k < pathFilter.Length; k++)
                                 {
                                     string value = pathFilter[k];
                                     if (!item.path.ToLowerInvariant().Contains(value))
                                     {
                                         flag = true;
                                         break;
                                     }
                                 }
                                 if (flag)
                                 {
                                     goto IL_3F4;
                                 }
                             }
                             FMOD_Listener.THROW_ERRORS(eventDescription.getLength(out item.timelineLength));
                             FMOD_Listener.THROW_ERRORS(eventDescription.is3D(out item.is3D));
                             float num2 = 0f;
                             FMOD_Listener.THROW_ERRORS(eventDescription.getMinimumDistance(out num2));
                             float num3 = 0f;
                             FMOD_Listener.THROW_ERRORS(eventDescription.getMaximumDistance(out num3));
                             float num4 = num3 - num2;
                             if (item.timelineLength > 0)
                             {
                                 item.normalizedPositions = new List <float>(num);
                             }
                             else
                             {
                                 item.normalizedPositions = null;
                             }
                             EventInstance[] array5 = null;
                             FMOD_Listener.THROW_ERRORS(eventDescription.getInstanceList(out array5));
                             item.instances = new List <FMOD_Listener.EventInstanceInfo>(num);
                             EventInstance[] array6 = array5;
                             for (int l = 0; l < array6.Length; l++)
                             {
                                 EventInstance eventInstance = array6[l];
                                 try
                                 {
                                     if (FMOD_Listener.IsEventInstancePlaying(eventInstance))
                                     {
                                         FMOD_Listener.EventInstanceInfo item2 = default(FMOD_Listener.EventInstanceInfo);
                                         float num5 = 0f;
                                         FMOD_Listener.THROW_ERRORS(eventInstance.getProperty(EVENT_PROPERTY.STREAM_COUNT, out num5));
                                         item2.streamCount = (int)num5;
                                         item.streamCount += item2.streamCount;
                                         FMOD_Listener.THROW_ERRORS(eventInstance.get3DAttributes(out item2.attributes3D));
                                         Vector3 a2   = item2.attributes3D.position.toUnityVector();
                                         float   num6 = Vector3.Distance(a2, b2);
                                         item2.distance           = num6;
                                         item2.normalizedDistance = Mathf.Clamp01((num6 - num2) / num4);
                                         if (item.timelineLength > 0)
                                         {
                                             int num7 = 0;
                                             FMOD_Listener.THROW_ERRORS(eventInstance.getTimelinePosition(out num7));
                                             item2.normalizedPosition = Mathf.Clamp01((float)num7 / (float)item.timelineLength);
                                         }
                                         else
                                         {
                                             item2.normalizedPosition = 0f;
                                         }
                                         int num8 = 0;
                                         FMOD_Listener.THROW_ERRORS(eventInstance.getParameterCount(out num8));
                                         if (num8 > 0)
                                         {
                                             item2.parameters = new List <FMOD_Listener.ParameterInfo>(num8);
                                             for (int m = 0; m < num8; m++)
                                             {
                                                 ParameterInstance parameterInstance;
                                                 FMOD_Listener.THROW_ERRORS(eventInstance.getParameterByIndex(m, out parameterInstance));
                                                 PARAMETER_DESCRIPTION pARAMETER_DESCRIPTION;
                                                 FMOD_Listener.THROW_ERRORS(parameterInstance.getDescription(out pARAMETER_DESCRIPTION));
                                                 float num9 = 0f;
                                                 FMOD_Listener.THROW_ERRORS(parameterInstance.getValue(out num9));
                                                 float num10 = pARAMETER_DESCRIPTION.maximum - pARAMETER_DESCRIPTION.minimum;
                                                 FMOD_Listener.ParameterInfo item3;
                                                 item3.name            = pARAMETER_DESCRIPTION.name;
                                                 item3.value           = num9;
                                                 item3.normalizedValue = (num9 - pARAMETER_DESCRIPTION.minimum) / num10;
                                                 item2.parameters.Add(item3);
                                             }
                                             item2.parameters.Sort();
                                         }
                                         else
                                         {
                                             item2.parameters = null;
                                         }
                                         item.instances.Add(item2);
                                         if (item.normalizedPositions != null)
                                         {
                                             item.normalizedPositions.Add(item2.normalizedPosition);
                                         }
                                     }
                                 }
                                 catch (FMOD_Listener.FMODErrorException ex)
                                 {
                                     if (ex.Error != RESULT.ERR_INVALID_HANDLE)
                                     {
                                         UnityEngine.Debug.LogWarning(ex);
                                     }
                                 }
                             }
                             this.eventInfoList.Add(item);
                         }
                         IL_3F4 :;
                     }
                 }
             }
             catch (FMOD_Listener.FMODErrorException ex2)
             {
                 if (ex2.Error != RESULT.ERR_INVALID_HANDLE)
                 {
                     UnityEngine.Debug.LogWarning(ex2);
                 }
             }
         }
         this.eventInfoList.Sort((FMOD_Listener.EventInfo a, FMOD_Listener.EventInfo b) => string.Compare(a.path, b.path, StringComparison.InvariantCultureIgnoreCase));
     }
     catch (FMOD_Listener.FMODErrorException message)
     {
         UnityEngine.Debug.LogWarning(message);
     }
 }
 public void Init_Ref()
 {
     event_Description = RuntimeManager.GetEventDescription(event_Ref);
     event_Description.getMaximumDistance(out maxDistance);
     event_Description.getMinimumDistance(out minDistance);
 }