protected static SfxrItem FindParameters( Component gameComponent, FieldInfo synthFieldInfo, bool autoInitParams) { SfxrParams parameters = null; var synth = (synthFieldInfo.GetValue(gameComponent) as SfxrSynth); if ((synth == null) && autoInitParams) { synth = new SfxrSynth(); synthFieldInfo.SetValue(gameComponent, synth); } if (synth != null) { parameters = synth.parameters; if ((parameters == null) && autoInitParams) { parameters = new SfxrParams(); synth.parameters = parameters; } } SfxrItem item = null; if (parameters != null) { item = new SfxrItem(parameters, gameComponent, synthFieldInfo); } return(item); }
protected static IEnumerable <SfxrItem> FindParameters( UnityEngine.Object @object, bool autoInitParams) { var gameObject = (@object as GameObject); if (!gameObject) { yield break; } foreach (var gameComponent in gameObject.GetComponents <Component>()) { if (!gameComponent) { continue; } // Search through all the fields of the game-component // and identify all fields that contain SFXR parameters FieldInfo[] fieldInfos = gameComponent.GetType().GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var fieldInfo in fieldInfos) { if (typeof(SfxrSynth).IsAssignableFrom(fieldInfo.FieldType)) { SfxrItem item = FindParameters(gameComponent, fieldInfo, autoInitParams); if (item != null) { yield return(item); } } else if (typeof(SfxrParams).IsAssignableFrom(fieldInfo.FieldType)) { SfxrParams parameters = (fieldInfo.GetValue(gameComponent) as SfxrParams); if ((parameters == null) && autoInitParams) { parameters = new SfxrParams(); fieldInfo.SetValue(gameComponent, parameters); } if (parameters != null) { yield return(new SfxrItem(parameters, gameComponent, fieldInfo)); } } } } }