Esempio n. 1
0
    protected void loadReverbsFromFile(FmodEventAsset asset)
    {
        List <FmodReverb> reverbs = new List <FmodReverb>();

        FMOD.REVERB_PROPERTIES curReverb = new FMOD.REVERB_PROPERTIES();
        IntPtr curReverbName             = new IntPtr();
        string curReverbNameAsString;
        int    numReverbs = 0;

        FMOD.RESULT result    = FMOD.RESULT.OK;
        FmodReverb  newReverb = null;

        result = getEventSystem().getNumReverbPresets(ref numReverbs);
        ERRCHECK(result);
        if (result == FMOD.RESULT.OK)
        {
            for (int i = 0; i < numReverbs; i++)
            {
                result = getEventSystem().getReverbPresetByIndex(i, ref curReverb, ref curReverbName);
                ERRCHECK(result);
                if (result == FMOD.RESULT.OK)
                {
                    curReverbNameAsString = Marshal.PtrToStringAnsi(curReverbName);
                    newReverb             = ScriptableObject.CreateInstance(typeof(FmodReverb)) as FmodReverb;
                    newReverb.Initialize(curReverbNameAsString, curReverb);
                    reverbs.Add(newReverb);
                }
            }
        }
        asset.setReverbs(reverbs);
    }
Esempio n. 2
0
    public void RestoreAsset()
    {
        if (m_source == null && m_pathToAssetFile != null)
        {
#if UNITY_EDITOR
            FmodEventAsset asset = AssetDatabase.LoadMainAssetAtPath(m_pathToAssetFile) as FmodEventAsset;

            if (asset == null)
            {
                Debug.LogWarning("FmodEventAudioSource (" + name + "): Error while restoring source: could not find asset at path '" + m_pathToAssetFile + "'.");
            }
            else
            {
                FmodEvent evt = null;

                if (m_sourceEventGUID != null && m_sourceEventGUID != "" && m_sourceEventGUID != FmodEvent.EMPTY_GUIDSTRING)
                {
                    evt = asset.getEventWithGUID(m_sourceEventGUID);
                }
                if (evt == null && m_sourceEventFullName != null && m_sourceEventFullName != "")
                {
                    evt = asset.getEventWithFullName(m_sourceEventFullName);
                }
                if (evt == null)
                {
                    Debug.LogWarning("FmodEventAudioSource (" + name + "): Error while restoring source: could not find event with GUID '" + m_sourceEventFullName + "' or at '" + m_sourceEventFullName + "'");
                }
                else
                {
                    SetSourceEvent(evt);
                }
            }
#endif
        }
    }
    static void UpdateEventAsset(FmodEventAsset oldAsset, FmodEventAsset newAsset)
    {
        FmodEventAudioSource[] allSources = Resources.FindObjectsOfTypeAll(typeof(FmodEventAudioSource)) as FmodEventAudioSource[];
        FmodReverbZone[] allReverbZones = Resources.FindObjectsOfTypeAll(typeof(FmodReverbZone)) as FmodReverbZone[];

        foreach (FmodEventAudioSource source in allSources) {
            source.CheckForOldFormat();
            if (source.getSource() != null) {
                FmodEvent oldEvent = source.getSource();
                FmodEvent newEvent = newAsset.getMatchingEvent(oldEvent);

                if (newEvent == null) {
                    source.SetSourceEvent(null);
                } else {
                    source.UpdateExistingEvent(newEvent);
                }
            }
        }
        foreach (FmodReverbZone zone in allReverbZones) {
            if (zone.GetReverb() != null) {
                FmodReverb oldReverb = zone.GetReverb();
                FmodReverb newReverb = newAsset.getMatchingReverb(oldReverb);

                if (newReverb == null) {
                    zone.ResetReverb();
                } else {
                    zone.ResetReverb();
                    zone.SetReverb(newReverb);
                }
            }
        }
    }
Esempio n. 4
0
    protected void _getSoundBankNames(FmodEventAsset asset)
    {
        FMOD.EVENT_SYSTEMINFO     sysinfo   = new FMOD.EVENT_SYSTEMINFO();
        FMOD.EVENT_WAVEBANKINFO[] bankinfos = new FMOD.EVENT_WAVEBANKINFO[MAX_SOUND_BANKS_PER_FILE];
        IntPtr bankInfosPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO)) * bankinfos.Length);
        IntPtr c            = new IntPtr(bankInfosPtr.ToInt32());

        FMOD.RESULT   result        = FMOD.RESULT.OK;
        List <string> soundBankList = new List <string>();


        for (int i = 0; i < bankinfos.Length; i++)
        {
            Marshal.StructureToPtr(bankinfos[i], c, true);
            c = new IntPtr(c.ToInt32() + Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO)));
        }
        sysinfo.maxwavebanks = MAX_SOUND_BANKS_PER_FILE;
        sysinfo.wavebankinfo = bankInfosPtr;
        result = getEventSystem().getInfo(ref sysinfo);
        ERRCHECK(result);
        if (result == FMOD.RESULT.OK)
        {
            for (int i = 0; i < sysinfo.maxwavebanks; i++)
            {
                bankinfos[i] = (FMOD.EVENT_WAVEBANKINFO)Marshal.PtrToStructure(new IntPtr(bankInfosPtr.ToInt32() +
                                                                                          i * Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO))), typeof(FMOD.EVENT_WAVEBANKINFO));
                string newString      = new string(bankinfos[i].name);
                int    index          = newString.IndexOf('\0');
                string adjustedString = new string(bankinfos[i].name, 0, index);
                soundBankList.Add(adjustedString);
            }
            asset.setSoundBankList(soundBankList);
        }
    }
Esempio n. 5
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. 6
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. 7
0
 public void CreateAsset(string assetFile, FmodEventAsset asset)
 {
     #if UNITY_EDITOR
     AssetDatabase.AddObjectToAsset(this, asset);
     //		AssetDatabase.ImportAsset(assetFile); // force a save
     foreach (FmodEventGroup g in m_children) {
         g.CreateAsset(assetFile, asset);
     }
     #endif
 }
Esempio n. 8
0
    public void CreateAsset(string assetFile, FmodEventAsset asset)
    {
#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(this, asset);
//		AssetDatabase.ImportAsset(assetFile); // force a save
        foreach (FmodEventGroup g in m_children)
        {
            g.CreateAsset(assetFile, asset);
        }
#endif
    }
    private int m_curNbEvents  = 0;    // to know the number of events currently displayed, for indexing events and their drawing rectangle

    void OnEnable()
    {
        serializedObject.Update();
        FmodEventAsset asset = this.serializedObject.targetObject as FmodEventAsset;

        m_nbEvents                    = asset.getEvents().Count;
        m_eventsRectangle             = new Rect[m_nbEvents];
        m_reverbsRectangle            = new Rect[asset.getReverbs().Count];
        m_events                      = new FmodEvent[m_nbEvents];
        SceneView.onSceneGUIDelegate += this.OnSceneGUI;
    }
Esempio n. 10
0
    public void CreateAsset(string assetFile, FmodEventAsset asset)
    {
#if UNITY_EDITOR
        AssetDatabase.AddObjectToAsset(this, asset);
//		AssetDatabase.ImportAsset(assetFile); // force a save
        foreach (FmodEventParameter param in m_parameters)
        {
            param.CreateAsset(assetFile, this);
        }
#endif
    }
Esempio n. 11
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. 12
0
    public void UpdateRestorationData()
    {
        if (m_source != null)
        {
#if UNITY_EDITOR
            FmodEventAsset asset = m_source.getAsset();
            string         tmp   = AssetDatabase.GetAssetPath(asset);

            if (tmp != null && tmp != "")
            {
                m_pathToAssetFile = tmp;
            }
            m_sourceEventFullName = m_source.getFullName();
            m_sourceEventGUID     = m_source.getGUIDString();
#endif
        }
    }
    private void _SetupDragAndDrop(FmodEventAsset asset)
    {
        Event e = Event.current;

        if (e.type == EventType.MouseUp || e.type == EventType.MouseDown)
        {
            _clearDragAndDrop();
        }
        if (e.type == EventType.MouseDrag)
        {
            FmodEvent  fmodEvent = _getHoveredEvent();
            FmodReverb reverb    = _getHoveredReverb();

            if (fmodEvent != null)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.paths            = new string[0];
                DragAndDrop.objectReferences = new Object[1] {
                    fmodEvent
                };
                DragAndDrop.SetGenericData(ONGOING_DRAG_KEY, true);
                DragAndDrop.SetGenericData(SOURCE_ASSET_KEY, asset);
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                DragAndDrop.StartDrag("Creating sound from event '" + fmodEvent.getName() + "'");
                m_ongoingDrag = true;
                e.Use();
            }
            else if (reverb != null)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.paths            = new string[0];
                DragAndDrop.objectReferences = new Object[1] {
                    reverb
                };
                DragAndDrop.SetGenericData(ONGOING_DRAG_KEY, true);
                DragAndDrop.SetGenericData(SOURCE_ASSET_KEY, asset);
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                DragAndDrop.StartDrag("Creating reverb zone from reverb '" + reverb.getName() + "'");
                m_ongoingDrag = true;
                e.Use();
            }
        }
    }
    private FmodReverb _getHoveredReverb()
    {
        if (m_showReverbs && Event.current.isMouse)
        {
            FmodEventAsset asset    = this.serializedObject.targetObject as FmodEventAsset;
            Vector2        mousePos = Event.current.mousePosition;
            int            i        = 0;

            foreach (Rect r in m_reverbsRectangle)
            {
                if (r.Contains(mousePos))
                {
                    return(asset.getReverbs()[i]);
                }
                i++;
            }
        }
        return(null);
    }
    static void UpdateEventAsset(FmodEventAsset oldAsset, FmodEventAsset newAsset)
    {
        FmodEventAudioSource[] allSources     = Resources.FindObjectsOfTypeAll(typeof(FmodEventAudioSource)) as FmodEventAudioSource[];
        FmodReverbZone[]       allReverbZones = Resources.FindObjectsOfTypeAll(typeof(FmodReverbZone)) as FmodReverbZone[];

        foreach (FmodEventAudioSource source in allSources)
        {
            source.CheckForOldFormat();
            if (source.getSource() != null)
            {
                FmodEvent oldEvent = source.getSource();
                FmodEvent newEvent = newAsset.getMatchingEvent(oldEvent);

                if (newEvent == null)
                {
                    source.SetSourceEvent(null);
                }
                else
                {
                    source.UpdateExistingEvent(newEvent);
                }
            }
        }
        foreach (FmodReverbZone zone in allReverbZones)
        {
            if (zone.GetReverb() != null)
            {
                FmodReverb oldReverb = zone.GetReverb();
                FmodReverb newReverb = newAsset.getMatchingReverb(oldReverb);

                if (newReverb == null)
                {
                    zone.ResetReverb();
                }
                else
                {
                    zone.ResetReverb();
                    zone.SetReverb(newReverb);
                }
            }
        }
    }
Esempio n. 16
0
    public FMOD.RESULT loadEventFromFile(FmodEventAudioSource src)
    {
        FmodEvent      evt   = src.getSource();
        FmodEventAsset asset = evt.getAsset();

        FMOD.RESULT         result    = FMOD.RESULT.OK;
        FMOD.EVENT_LOADINFO loadInfo  = new FMOD.EVENT_LOADINFO();
        FMOD.EventProject   project   = null;
        FMOD.Event          fmodEvent = null;

        _loadFile(asset.getMediaPath(), asset.getName(), ref loadInfo, ref project);
        _loadEventGroup(evt);
        result = _loadEvent(evt, ref fmodEvent);
        ERRCHECK(result);
        if (result == FMOD.RESULT.OK)
        {
            src.SetEvent(fmodEvent);
        }
        return(result);
    }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string str in importedAssets)
        {
            if (str.EndsWith(@".fev"))
            {
                if (File.Exists(str + @".asset"))
                {
                    FmodEventAsset newAsset = FmodEventAsset.CreateInstance("FmodEventAsset") as FmodEventAsset;
                    FmodEventAsset oldAsset = AssetDatabase.LoadAssetAtPath(str + @".asset", typeof(FmodEventAsset)) as FmodEventAsset;

                    newAsset.Initialize(str);
                    UpdateEventAsset(oldAsset, newAsset);
                    newAsset.CreateAsset(str);
                    AssetDatabase.SaveAssets();
                    CheckForRemainsOfDeletedParameters();
                    FmodEventSystem.ClearHolder();
                }
                else
                {
                    FmodEventAsset asset = FmodEventAsset.CreateInstance("FmodEventAsset") as FmodEventAsset;
                    asset.Initialize(str);
                    asset.CreateAsset(str);
                    FmodEventSystem.ClearHolder();
                }
            }
            else if (Application.isPlaying && Application.isEditor &&
                     (str.EndsWith(@".cs") || str.EndsWith(@".js")))
            {
                                 #if UNITY_EDITOR
                EditorApplication.isPlaying = false;                         // we are forced to stop the application in the editor at this point, or else Mono will rebuild the app and we'll lose the managed memory. Unfortunately, the C++ application will still be running and we won't be able to come back.
                Debug.LogWarning("FMOD_Unity : Forced to leave the application because source code was about to be built");
                                #endif
            }
        }
    }
Esempio n. 18
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. 19
0
    protected void _getSoundBankNames(FmodEventAsset asset)
    {
        FMOD.EVENT_SYSTEMINFO 		sysinfo 		= new FMOD.EVENT_SYSTEMINFO();
        FMOD.EVENT_WAVEBANKINFO[] 	bankinfos 		= new FMOD.EVENT_WAVEBANKINFO[MAX_SOUND_BANKS_PER_FILE];
        IntPtr 						bankInfosPtr 	= Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO)) * bankinfos.Length);
        IntPtr 						c 				= new IntPtr(bankInfosPtr.ToInt32());
        FMOD.RESULT 				result 			= FMOD.RESULT.OK;
        List<string>				soundBankList = new List<string>();

        for (int i = 0; i < bankinfos.Length; i++)
        {
            Marshal.StructureToPtr(bankinfos[i], c, true);
            c = new IntPtr(c.ToInt32() + Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO)));
        }
        sysinfo.maxwavebanks = MAX_SOUND_BANKS_PER_FILE;
        sysinfo.wavebankinfo = bankInfosPtr;
        result = getEventSystem().getInfo(ref sysinfo);
        ERRCHECK (result);
        if (result == FMOD.RESULT.OK) {
            for (int i = 0; i < sysinfo.maxwavebanks; i++)
            {
                bankinfos[i] = (FMOD.EVENT_WAVEBANKINFO)Marshal.PtrToStructure(new IntPtr(bankInfosPtr.ToInt32() +
                    i * Marshal.SizeOf(typeof(FMOD.EVENT_WAVEBANKINFO))), typeof(FMOD.EVENT_WAVEBANKINFO));
                string newString = new string(bankinfos[i].name);
                int index = newString.IndexOf('\0');
                string adjustedString = new string(bankinfos[i].name, 0, index);
                soundBankList.Add(adjustedString);
            }
            asset.setSoundBankList(soundBankList);
        }
    }
Esempio n. 20
0
    protected void loadReverbsFromFile(FmodEventAsset asset)
    {
        List<FmodReverb> reverbs = new List<FmodReverb>();
        FMOD.REVERB_PROPERTIES curReverb = new FMOD.REVERB_PROPERTIES();
        IntPtr curReverbName = new IntPtr();
        string curReverbNameAsString;
        int numReverbs = 0;
        FMOD.RESULT result = FMOD.RESULT.OK;
        FmodReverb newReverb = null;

        result = getEventSystem().getNumReverbPresets(ref numReverbs);
        ERRCHECK(result);
        if (result == FMOD.RESULT.OK) {
            for (int i = 0; i < numReverbs; i++) {
                result = getEventSystem().getReverbPresetByIndex(i, ref curReverb, ref curReverbName);
                ERRCHECK(result);
                if (result == FMOD.RESULT.OK) {
                    curReverbNameAsString = Marshal.PtrToStringAnsi(curReverbName);
                    newReverb = ScriptableObject.CreateInstance(typeof(FmodReverb)) as FmodReverb;
                    newReverb.Initialize(curReverbNameAsString, curReverb);
                    reverbs.Add(newReverb);
                }
            }
        }
        asset.setReverbs(reverbs);
    }
Esempio n. 21
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. 22
0
 public void CreateAsset(string assetFile, FmodEventAsset asset)
 {
     #if UNITY_EDITOR
     AssetDatabase.AddObjectToAsset(this, asset);
     //		AssetDatabase.ImportAsset(assetFile); // force a save
     #endif
 }
Esempio n. 23
0
	public void CreateAsset(string assetFile, FmodEventAsset asset) {
#if UNITY_EDITOR
		AssetDatabase.AddObjectToAsset(this, asset);
//		AssetDatabase.ImportAsset(assetFile); // force a save
#endif
	}
Esempio n. 24
0
 public void CreateAsset(string assetFile, FmodEventAsset asset)
 {
     #if UNITY_EDITOR
     AssetDatabase.AddObjectToAsset(this, asset);
     //		AssetDatabase.ImportAsset(assetFile); // force a save
     foreach (FmodEventParameter param in m_parameters) {
         param.CreateAsset(assetFile, this);
     }
     #endif
 }
Esempio n. 25
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 override void OnInspectorGUI()
    {
        serializedObject.Update();
        FmodEventAsset asset           = this.serializedObject.targetObject as FmodEventAsset;
        List <string>  soundBankList   = asset.getSoundBankList();
        string         currentPath     = asset.getMediaPath();
        string         projectRootPath = System.IO.Path.GetDirectoryName(Application.dataPath);
        string         totalPath       = "";
        bool           soundBankExists = false;

        EditorGUILayout.LabelField("Name", asset.getName());
        EditorGUILayout.LabelField("Sound banks referenced");
        EditorGUI.indentLevel += 1;
        if (soundBankList.Count == 0)
        {
            EditorGUILayout.LabelField("No Sound banks referenced in this file");
        }
        else
        {
            foreach (string soundBank in soundBankList)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append(projectRootPath);
                sb.Append("/");
                sb.Append(currentPath);
                sb.Append("/");
                sb.Append(soundBank);
                sb.Append(@".fsb");
                sb.Replace('/', '\\');

                totalPath = sb.ToString();
//				totalPath = string.Concat(projectRootPath, "/", currentPath, "/", soundBank, @".fsb");
//				totalPath = totalPath.Replace("/", "\\");
                soundBankExists = System.IO.File.Exists(totalPath);
                EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
                EditorGUILayout.PrefixLabel(soundBank);
                if (soundBankExists)
                {
                    EditorGUILayout.HelpBox("(Found)", MessageType.None);
                }
                else
                {
                    EditorGUILayout.HelpBox("The sound bank could not be found at path '" + totalPath + "'. The events relying on it won't work.", MessageType.Error);
                }
                EditorGUILayout.EndHorizontal();
            }
            if (GUILayout.Button("Refresh"))
            {
                AssetDatabase.ImportAsset(currentPath, ImportAssetOptions.ForceUpdate);
                Repaint();
            }
        }
        EditorGUI.indentLevel -= 1;
        EditorGUILayout.HelpBox("Drag the event name onto the scene to create a source ; Alt + Drag for adding the source as component to target GameObject", MessageType.Info);
        m_showEvents  = EditorGUILayout.Foldout(m_showEvents, "Events");
        m_curNbEvents = 0;
        if (m_showEvents)
        {
            EditorGUI.indentLevel += 1;
            foreach (FmodEventGroup eventGroup in asset.getEventGroups())
            {
                _eventHierarchyGUI(eventGroup);
            }
            EditorGUI.indentLevel -= 1;
        }
        _SetupDragAndDrop(asset);
        EditorGUILayout.Separator();
        EditorGUILayout.HelpBox("Drag the reverb name onto the scene to create a reverb zone", MessageType.Info);
        m_showReverbs = EditorGUILayout.Foldout(m_showReverbs, "Reverb presets");
        if (m_showReverbs)
        {
            if (asset.getReverbs().Count > 0)
            {
                int curNbReverbs = 0;

                EditorGUI.indentLevel += 2;
                foreach (FmodReverb reverb in asset.getReverbs())
                {
                    EditorGUILayout.LabelField(reverb.getName());
                    if (Event.current.type == EventType.Repaint)
                    {
                        Rect lastRect = GUILayoutUtility.GetLastRect();
                        m_reverbsRectangle[curNbReverbs++].Set(lastRect.xMin, lastRect.yMin, lastRect.width, lastRect.height);
                    }
                }
                EditorGUI.indentLevel -= 2;
            }
            else
            {
                EditorGUILayout.LabelField("No reverb preset in this file");
            }
        }
    }
Esempio n. 27
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. 28
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
    }
    private void _SetupDragAndDrop(FmodEventAsset asset)
    {
        Event e = Event.current;

        if (e.type == EventType.MouseUp || e.type == EventType.MouseDown) {
            _clearDragAndDrop();
        }
        if (e.type == EventType.MouseDrag) {
            FmodEvent fmodEvent = _getHoveredEvent();
            FmodReverb reverb = _getHoveredReverb();

            if (fmodEvent != null) {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.paths = new string[0];
                DragAndDrop.objectReferences = new Object[1] { fmodEvent };
                DragAndDrop.SetGenericData(ONGOING_DRAG_KEY, true);
                DragAndDrop.SetGenericData(SOURCE_ASSET_KEY, asset);
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                DragAndDrop.StartDrag("Creating sound from event '" + fmodEvent.getName() + "'");
                m_ongoingDrag = true;
                e.Use();
            } else if (reverb != null) {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.paths = new string[0];
                DragAndDrop.objectReferences = new Object[1] { reverb };
                DragAndDrop.SetGenericData(ONGOING_DRAG_KEY, true);
                DragAndDrop.SetGenericData(SOURCE_ASSET_KEY, asset);
                DragAndDrop.visualMode = DragAndDropVisualMode.Move;
                DragAndDrop.StartDrag("Creating reverb zone from reverb '" + reverb.getName() + "'");
                m_ongoingDrag = true;
                e.Use();
            }
        }
    }