Esempio n. 1
0
    public List <FmodEvent> loadEventsFromFile(string assetPath, string assetName, FmodEventAsset asset)
    {
        FMOD.EventGroup       eventgroup  = null;
        FMOD.RESULT           result      = FMOD.RESULT.OK;
        List <FmodEvent>      events      = new List <FmodEvent>();
        List <FmodEventGroup> eventGroups = new List <FmodEventGroup>();
        int            numGroups          = 0;
        FmodEventGroup toAdd = null;

        FMOD.EVENT_LOADINFO loadInfo = new FMOD.EVENT_LOADINFO();
        FMOD.EventProject   project  = null;

        _loadFile(assetPath, assetName, ref loadInfo, ref project);
        _getSoundBankNames(asset);

        FMOD.EVENT_PROJECTINFO projectInfo = new FMOD.EVENT_PROJECTINFO();
        project.getInfo(ref projectInfo);
        asset.setProjectName(new string(projectInfo.name));

        result = project.getNumGroups(ref numGroups);
        ERRCHECK(result);
        for (int i = 0; i < numGroups; i++)
        {
            result = project.getGroupByIndex(i, false, ref eventgroup);
            ERRCHECK(result);
            toAdd = FmodEventGroup.CreateInstance("FmodEventGroup") as FmodEventGroup;
            toAdd.Initialize(eventgroup, null, asset);
            eventGroups.Add(toAdd);
            events.AddRange(toAdd.getAllEvents());
        }
        asset.setEventGroups(eventGroups);
        loadReverbsFromFile(asset);
        return(events);
    }
Esempio n. 2
0
 public void Initialize(FmodEventGroup eventGroup, int indexInGroup, FmodEventAsset asset)
 {
             #if UNITY_EDITOR
     hideFlags      = HideFlags.HideInHierarchy;
     m_group        = eventGroup;
     m_indexInGroup = indexInGroup;
     m_asset        = asset;
     m_name         = "(This event could not be loaded. Are you missing a .fsb ?)";
             #endif
 }
Esempio n. 3
0
    public void Initialize(FMOD.EventGroup eventgroup, FmodEventGroup parentGroup, FmodEventAsset asset)
    {
        FMOD.EventGroup childEventgroup   = null;
        FMOD.RESULT     result            = FMOD.RESULT.OK;
        FmodEventGroup  child             = null;
        int             numChildrenGroups = 0;
        int             numEvents         = 0;

        FMOD.Event e     = null;
        FmodEvent  toAdd = null;

        hideFlags     = HideFlags.HideInHierarchy;
        m_projectName = asset.getProjectName();
        m_parent      = parentGroup;
        _getName(eventgroup);
        result = eventgroup.loadEventData();
        ERRCHECK(result);
        result = eventgroup.getNumEvents(ref numEvents);
        ERRCHECK(result);
        for (int j = 0; j < numEvents; j++)
        {
            e      = null;
            result = eventgroup.getEventByIndex(j, FMOD.EVENT_MODE.DEFAULT | FMOD.EVENT_MODE.ERROR_ON_DISKACCESS, ref e);
            ERRCHECK(result);
            if (result != FMOD.RESULT.OK)
            {
                result = FMOD.RESULT.OK;
            }
            toAdd = FmodEvent.CreateInstance("FmodEvent") as FmodEvent;
            if (e != null)
            {
                toAdd.Initialize(e, this, j, asset);
                e.release();
            }
            else
            {
                toAdd.Initialize(this, j, asset);
            }
            m_events.Add(toAdd);
        }
        result = eventgroup.freeEventData(false);
        ERRCHECK(result);
        result = eventgroup.getNumGroups(ref numChildrenGroups);
        for (int k = 0; k < numChildrenGroups; k++)
        {
            result = eventgroup.getGroupByIndex(k, false, ref childEventgroup);
            ERRCHECK(result);
            child = FmodEventGroup.CreateInstance("FmodEventGroup") as FmodEventGroup;
            child.Initialize(childEventgroup, this, asset);
            m_children.Add(child);
        }
        name = getFullName();
    }
Esempio n. 4
0
 public void releaseAllEventsFromGroup(FmodEventGroup grp)
 {
     if (grp != null)
     {
         foreach (FmodEvent evt in grp.getAllEvents())
         {
             if (m_eventPoolManager.eventPoolExists(evt))
             {
                 m_eventPoolManager.getEventPool(evt).releaseAllHandles();
             }
         }
     }
 }
Esempio n. 5
0
    public int getNumberRunningInstancesInGroup(FmodEventGroup grp)
    {
        if (grp == null)
        {
            return(0);
        }
        int total = 0;

        foreach (FmodEvent evt in grp.getAllEvents())
        {
            if (m_eventPoolManager.eventPoolExists(evt))
            {
                total += m_eventPoolManager.getEventPool(evt).getNumberRunningInstances();
            }
        }
        return(total);
    }
Esempio n. 6
0
    private void freeEventData()
    {
        FmodEvent evt = getSource();

        if (evt != null && m_runtimeEvent != null)
        {
            FmodEventGroup evtGroup = evt.getEventGroup();

            if (m_eventSystemHandle != null &&
                m_eventSystemHandle.getEventSystem() != null &&
                m_eventSystemHandle.getEventSystem().wasCleaned() == false)
            {
                if (m_eventSystemHandle.getEventSystem().getNumberRunningInstancesInGroup(evtGroup) == 0)
                {
                    evtGroup.freeWholeGroup();
                }
            }
        }
    }
    public void _eventHierarchyGUI(FmodEventGroup curGroup)
    {
        List <FmodEvent> events = curGroup.getEvents();

        if (m_style == null)
        {
            m_style = new GUIStyle(GUI.skin.label);
        }

        curGroup.showEventsInEditor = EditorGUILayout.Foldout(curGroup.showEventsInEditor, curGroup.getName());
        if (curGroup.showEventsInEditor)
        {
            EditorGUI.indentLevel += 1;
            foreach (FmodEvent e in events)
            {
                if (e.WasLoaded())
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(e.getName(), m_style, GUILayout.ExpandWidth(true));
                    if (Event.current.type == EventType.Repaint)
                    {
                        Rect lastRect = GUILayoutUtility.GetLastRect();
                        m_eventsRectangle[m_curNbEvents].Set(lastRect.xMin, lastRect.yMin, lastRect.width, lastRect.height);
                        m_events[m_curNbEvents] = e;
                    }
                    EditorGUILayout.LabelField((e.getSourceType() == FmodEvent.SourceType.SOURCE_2D ? "2D" : "3D"));
                    EditorGUILayout.EndHorizontal();
                    m_curNbEvents++;
                }
                else
                {
                    EditorGUILayout.HelpBox("Could not load this event. Are you missing a .fsb ?", MessageType.Error);
                }
            }
            foreach (FmodEventGroup child in curGroup.getChildrenGroups())
            {
                _eventHierarchyGUI(child);
            }
            EditorGUI.indentLevel -= 1;
        }
    }
Esempio n. 8
0
    /// <summary>
    /// Gets an event based on the full path from the root of the asset. A starting slash is not required.
    /// Double slashes, i.e. "Group1//Group2/Event" are ignored.
    /// </summary>
    /// <returns>
    /// The event, or null if not found.
    /// </returns>
    /// <param name='fullName'>
    /// Full name of an event, meaning path from the root of the asset, e.g. "FeatureDemonstration/Basics/BasicSoundWithLooping"
    /// </param>
    public FmodEvent getEventWithFullName(string fullName)
    {
        List <FmodEventGroup> curChildrenGroups;
        List <FmodEvent>      curChildrenEvents;

        string[] explodedPath;

        explodedPath = fullName.Split(new char[1] {
            '/'
        });
        curChildrenGroups = m_eventGroups;
        curChildrenEvents = m_events;

        for (int i = 0; i < explodedPath.Length - 1; i++)
        {
            string pathElement = explodedPath[i];

            if (pathElement != "")               // we skip null paths in things such as "elem1/elem2//elem3". Also, enables not caring about a starting /
            {
                FmodEventGroup grp = _getChildGroupWithName(curChildrenGroups, pathElement);

                if (grp == null)
                {
                    Debug.LogWarning("FmodEventAsset (" + getName() + "): getEventWithFullName: Could not find event group with name '" + pathElement + "'");
                    return(null);
                }
                curChildrenGroups = grp.getChildrenGroups();
                curChildrenEvents = grp.getEvents();
            }
        }
        string    eventName = explodedPath[explodedPath.Length - 1];
        FmodEvent ret       = _getEventFromListWithName(curChildrenEvents, eventName);

        if (ret != null)
        {
            return(ret);
        }
        Debug.LogWarning("FmodEventAsset (" + getName() + "): getEventWithFullName: Could not find event with name '" + eventName + "'");
        return(null);
    }
Esempio n. 9
0
    public void Initialize(FMOD.Event e, FmodEventGroup eventGroup, int indexInGroup, FmodEventAsset asset)
    {
#if UNITY_EDITOR
        FMOD.EVENT_INFO     info   = new FMOD.EVENT_INFO();
        FMOD.GUID           guid   = new FMOD.GUID();
        FMOD.EventParameter param  = null;
        FMOD.RESULT         result = FMOD.RESULT.OK;
        FmodEventParameter  toAdd  = null;
        IntPtr name          = new IntPtr(0);
        int    numParameters = 0;
        int    index         = 0;

        Initialize(eventGroup, indexInGroup, asset);
        int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(FMOD.GUID));
        info.guid = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
        result    = e.getInfo(ref index, ref name, ref info);
        ERRCHECK(result);
        m_name       = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
        this.name    = m_name;
        guid         = (FMOD.GUID)System.Runtime.InteropServices.Marshal.PtrToStructure(info.guid, typeof(FMOD.GUID));
        m_guidString = "{" + String.Format("{0:x8}-{1:x4}-{2:x4}-{3:x2}{4:x2}-{5:x2}{6:x2}{7:x2}{8:x2}{9:x2}{10:x2}",
                                           guid.Data1, guid.Data2, guid.Data3,
                                           guid.Data4[0], guid.Data4[1],
                                           guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]
                                           ) + "}";

        int    mode    = 0;
        IntPtr modePtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int));
        e.getPropertyByIndex((int)FMOD.EVENTPROPERTY.MODE, modePtr, false);
        mode = System.Runtime.InteropServices.Marshal.ReadInt32(modePtr);
        System.Runtime.InteropServices.Marshal.FreeHGlobal(modePtr);
        m_sourceType = (SourceType)mode;

        if (m_sourceType == SourceType.SOURCE_3D)
        {
            IntPtr  range;
            float[] tmp    = new float[1];
            int[]   tmpInt = new int[1];

            range  = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_ROLLOFF, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmpInt, 0, 1);
            if (tmpInt[0] == (int)FMOD.MODE._3D_CUSTOMROLLOFF)
            {
                m_rolloffType = RolloffType.CUSTOM;
            }
            else if (tmpInt[0] == (int)FMOD.MODE._3D_INVERSEROLLOFF)
            {
                m_rolloffType = RolloffType.INVERSE;
            }
            else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARROLLOFF)
            {
                m_rolloffType = RolloffType.LINEAR;
            }
            else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARSQUAREROLLOFF)
            {
                m_rolloffType = RolloffType.LINEARSQUARE;
            }
            else if (tmpInt[0] == (int)FMOD.MODE._3D_LOGROLLOFF)
            {
                m_rolloffType = RolloffType.LOGARITHMIC;
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);

            range  = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MINDISTANCE, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1);
            m_minRange = tmp[0];
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);
            range  = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MAXDISTANCE, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1);
            m_maxRange = tmp[0];
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);
        }


        e.getNumParameters(ref numParameters);
        for (int k = 0; k < numParameters; k++)
        {
            e.getParameterByIndex(k, ref param);
            toAdd = FmodEventParameter.CreateInstance("FmodEventParameter") as FmodEventParameter;
            toAdd.Initialize(param, this);
            m_parameters.Add(toAdd);
        }
        m_wasLoaded = true;
#endif
    }
Esempio n. 10
0
 public void releaseAllEventsFromGroup(FmodEventGroup grp)
 {
     if (grp != null) {
         foreach (FmodEvent evt in grp.getAllEvents()) {
             if (m_eventPoolManager.eventPoolExists(evt)) {
                 m_eventPoolManager.getEventPool(evt).releaseAllHandles();
             }
         }
     }
 }
Esempio n. 11
0
    public int getNumberRunningInstancesInGroup(FmodEventGroup grp)
    {
        if (grp == null) {
            return (0);
        }
        int total = 0;

        foreach (FmodEvent evt in grp.getAllEvents()) {
            if (m_eventPoolManager.eventPoolExists(evt)) {
                total += m_eventPoolManager.getEventPool(evt).getNumberRunningInstances();
            }
        }
        return (total);
    }
Esempio n. 12
0
    public void Initialize(FMOD.EventGroup eventgroup, FmodEventGroup parentGroup, FmodEventAsset asset)
    {
        FMOD.EventGroup childEventgroup     	= null;
        FMOD.RESULT 	result 			= FMOD.RESULT.OK;
        FmodEventGroup  child = null;
        int 			numChildrenGroups 		= 0;
        int 			numEvents 		= 0;
        FMOD.Event 		e 				= null;
        FmodEvent 		toAdd 			= null;

        hideFlags = HideFlags.HideInHierarchy;
        m_projectName = asset.getProjectName();
        m_parent = parentGroup;
        _getName(eventgroup);
        result = eventgroup.loadEventData();
        ERRCHECK(result);
        result = eventgroup.getNumEvents(ref numEvents);
        ERRCHECK(result);
        for (int j = 0; j < numEvents; j++) {
            e = null;
            result = eventgroup.getEventByIndex(j, FMOD.EVENT_MODE.DEFAULT | FMOD.EVENT_MODE.ERROR_ON_DISKACCESS, ref e);
            ERRCHECK(result);
            if (result != FMOD.RESULT.OK) {
                result = FMOD.RESULT.OK;
            }
            toAdd = FmodEvent.CreateInstance("FmodEvent") as FmodEvent;
            if (e != null) {
                toAdd.Initialize(e, this, j, asset);
                e.release();
            } else {
                toAdd.Initialize(this, j, asset);
            }
            m_events.Add (toAdd);
        }
        result = eventgroup.freeEventData(false);
        ERRCHECK(result);
        result = eventgroup.getNumGroups(ref numChildrenGroups);
        for (int k = 0; k < numChildrenGroups; k++) {
            result = eventgroup.getGroupByIndex(k, false, ref childEventgroup);
            ERRCHECK(result);
            child = FmodEventGroup.CreateInstance("FmodEventGroup") as FmodEventGroup;
            child.Initialize(childEventgroup, this, asset);
            m_children.Add(child);
        }
        name = getFullName();
    }
Esempio n. 13
0
    public void Initialize(FMOD.Event e, FmodEventGroup eventGroup, int indexInGroup, FmodEventAsset asset)
    {
        #if UNITY_EDITOR
        FMOD.EVENT_INFO info = new FMOD.EVENT_INFO();
        FMOD.GUID guid = new FMOD.GUID();
        FMOD.EventParameter param = null;
        FMOD.RESULT result = FMOD.RESULT.OK;
        FmodEventParameter toAdd = null;
        IntPtr name = new IntPtr(0);
        int numParameters = 0;
        int index = 0;

        Initialize(eventGroup, indexInGroup, asset);
        int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(FMOD.GUID));
        info.guid = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
        result = e.getInfo(ref index, ref name, ref info);
        ERRCHECK(result);
        m_name = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
        this.name = m_name;
        guid = (FMOD.GUID)System.Runtime.InteropServices.Marshal.PtrToStructure(info.guid, typeof(FMOD.GUID));
        m_guidString = "{" + String.Format("{0:x8}-{1:x4}-{2:x4}-{3:x2}{4:x2}-{5:x2}{6:x2}{7:x2}{8:x2}{9:x2}{10:x2}",
            guid.Data1, guid.Data2, guid.Data3,
            guid.Data4[0], guid.Data4[1],
            guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]
        ) + "}";

        int mode = 0;
        IntPtr modePtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int));
        e.getPropertyByIndex((int)FMOD.EVENTPROPERTY.MODE, modePtr, false);
        mode = System.Runtime.InteropServices.Marshal.ReadInt32(modePtr);
        System.Runtime.InteropServices.Marshal.FreeHGlobal(modePtr);
        m_sourceType = (SourceType)mode;

        if (m_sourceType == SourceType.SOURCE_3D) {
            IntPtr range;
            float[] tmp = new float[1];
            int[] tmpInt = new int[1];

            range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_ROLLOFF, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmpInt, 0, 1);
            if (tmpInt[0] == (int)FMOD.MODE._3D_CUSTOMROLLOFF) {
                m_rolloffType = RolloffType.CUSTOM;
            } else if (tmpInt[0] == (int)FMOD.MODE._3D_INVERSEROLLOFF) {
                m_rolloffType = RolloffType.INVERSE;
            } else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARROLLOFF) {
                m_rolloffType = RolloffType.LINEAR;
            } else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARSQUAREROLLOFF) {
                m_rolloffType = RolloffType.LINEARSQUARE;
            } else if (tmpInt[0] == (int)FMOD.MODE._3D_LOGROLLOFF) {
                m_rolloffType = RolloffType.LOGARITHMIC;
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);

            range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MINDISTANCE, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1);
            m_minRange = tmp[0];
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);
            range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float));
            result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MAXDISTANCE, range, false);
            ERRCHECK(result);
            System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1);
            m_maxRange = tmp[0];
            System.Runtime.InteropServices.Marshal.FreeHGlobal(range);
        }

        e.getNumParameters(ref numParameters);
        for (int k = 0; k < numParameters; k++) {
            e.getParameterByIndex(k, ref param);
            toAdd = FmodEventParameter.CreateInstance("FmodEventParameter") as FmodEventParameter;
            toAdd.Initialize(param, this);
            m_parameters.Add(toAdd);
        }
        m_wasLoaded = true;
        #endif
    }
Esempio n. 14
0
 public void Initialize(FmodEventGroup eventGroup, int indexInGroup, FmodEventAsset asset)
 {
     #if UNITY_EDITOR
         hideFlags = HideFlags.HideInHierarchy;
         m_group = eventGroup;
         m_indexInGroup = indexInGroup;
         m_asset = asset;
         m_name = "(This event could not be loaded. Are you missing a .fsb ?)";
     #endif
 }
    public void _eventHierarchyGUI(FmodEventGroup curGroup)
    {
        List<FmodEvent> events = curGroup.getEvents();

        if (m_style == null) {
            m_style = new GUIStyle(GUI.skin.label);
        }

        curGroup.showEventsInEditor = EditorGUILayout.Foldout(curGroup.showEventsInEditor, curGroup.getName());
        if (curGroup.showEventsInEditor) {
            EditorGUI.indentLevel += 1;
            foreach (FmodEvent e in events) {
                if (e.WasLoaded()) {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(e.getName(), m_style, GUILayout.ExpandWidth(true));
                    if (Event.current.type == EventType.Repaint) {
                        Rect lastRect = GUILayoutUtility.GetLastRect();
                        m_eventsRectangle[m_curNbEvents].Set(lastRect.xMin, lastRect.yMin, lastRect.width, lastRect.height);
                        m_events[m_curNbEvents] = e;
                    }
                    EditorGUILayout.LabelField((e.getSourceType() == FmodEvent.SourceType.SOURCE_2D ? "2D" : "3D"));
                    EditorGUILayout.EndHorizontal();
                    m_curNbEvents++;
                } else {
                    EditorGUILayout.HelpBox("Could not load this event. Are you missing a .fsb ?", MessageType.Error);
                }
            }
            foreach (FmodEventGroup child in curGroup.getChildrenGroups()) {
                _eventHierarchyGUI(child);
            }
            EditorGUI.indentLevel -= 1;
        }
    }