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 timer1_Tick(object sender, System.EventArgs e) { if (!initialised) { ERRCHECK(result = FMOD.Event_Factory.EventSystem_Create(ref eventsystem)); ERRCHECK(result = eventsystem.init(64, FMOD.INITFLAGS.NORMAL, (IntPtr)null, FMOD.EVENT_INITFLAGS.NORMAL)); ERRCHECK(result = eventsystem.setMediaPath("../../../../examples/media/")); ERRCHECK(result = eventsystem.load("examples.fev")); ERRCHECK(result = eventsystem.getGroup("examples/AdvancedTechniques", false, ref eventgroup)); ERRCHECK(result = eventgroup.getEvent("car", FMOD.EVENT_MODE.DEFAULT, ref car)); ERRCHECK(result = eventsystem.getCategory("master", ref mastercategory)); ERRCHECK(result = car.getParameter("load", ref load)); ERRCHECK(result = load.getRange(ref load_min, ref load_max)); ERRCHECK(result = load.setValue(load_max)); ERRCHECK(result = car.getParameterByIndex(0, ref rpm)); ERRCHECK(result = rpm.getRange(ref rpm_min, ref rpm_max)); ERRCHECK(result = rpm.setValue(1000.0f)); trackBarRPM.Minimum = (int)rpm_min; trackBarRPM.Maximum = (int)rpm_max; trackBarLoad.Minimum = (int)load_min; trackBarLoad.Maximum = (int)load_max; trackBarRPM.Value = 1000; trackBarLoad.Value = (int)load_max; ERRCHECK(result = car.start()); initialised = true; } /* * "Main Loop" */ if (trackbarscroll) { ERRCHECK(result = rpm.setValue((float)trackBarRPM.Value)); ERRCHECK(result = load.setValue((float)trackBarLoad.Value)); trackbarscroll = false; } float rpmvalue = 0.0f; ERRCHECK(result = rpm.getValue(ref rpmvalue)); statusBar.Text = "RPM Value = " + rpmvalue; ERRCHECK(result = eventsystem.update()); /* * Clean up and exit */ if (exit) { ERRCHECK(result = eventgroup.freeEventData()); ERRCHECK(result = eventsystem.release()); Application.Exit(); } }