private AudioSource CheckForHiddenAudioSources() { AudioSource[] sources = script.gameObject.GetComponents <AudioSource>(); List <AudioSource> eligibleSources = new List <AudioSource>(); foreach (AudioSource aSource in sources) { if (aSource.hideFlags == (HideFlags.HideInInspector | HideFlags.NotEditable)) { eligibleSources.Add(aSource); } } if (eligibleSources.Count == 0) { return(null); } AudioSourcePro[] pros = script.gameObject.GetComponents <AudioSourcePro>(); foreach (AudioSource eligibleSource in eligibleSources) { AudioSourcePro tempPro = ArrayUtility.Find <AudioSourcePro>(pros, delegate(AudioSourcePro obj) { return(obj.audioSource == eligibleSource); }); if (tempPro == null) { return(eligibleSource); } } return(null); }
public void Bind(AudioSourcePro sourcePro) { if (isBound || isStandardEvent || sourceComponent == null) { return; } #if !(UNITY_WP8 || UNITY_METRO) owner = sourcePro; if (!componentIsValid) { Debug.LogError(string.Format("Invalid binding configuration - Source:{0}", sourceComponent)); return; } MethodInfo eventHandlerMethodInfo = getMethodInfoForAction(actionType); targetComponent = owner; eventField = getField(sourceComponent, methodName); if (eventField == null) { Debug.LogError("Event definition not found: " + sourceComponent.GetType().Name + "." + methodName); return; } try { var eventMethod = eventField.FieldType.GetMethod("Invoke"); var eventParams = eventMethod.GetParameters(); eventDelegate = createProxyEventDelegate(targetComponent, eventField.FieldType, eventParams, eventHandlerMethodInfo); } catch (Exception err) { Debug.LogError("Event binding failed - Failed to create event handler: " + err.ToString()); return; } var combinedDelegate = Delegate.Combine(eventDelegate, (Delegate)eventField.GetValue(sourceComponent)); eventField.SetValue(sourceComponent, combinedDelegate); #else Debug.LogError("Windows Store and Windows Phone apps don't support automatic custom binding. You must do it yourself in code."); #endif isBound = true; }
public void Bind(AudioSourcePro sourcePro) { if(isBound || isStandardEvent || sourceComponent == null) return; owner = sourcePro; if(!componentIsValid) { Debug.LogError(string.Format( "Invalid binding configuration - Source:{0}", sourceComponent)); return; } MethodInfo eventHandlerMethodInfo = getMethodInfoForAction(actionType); targetComponent = owner; eventField = getField(sourceComponent, methodName); if(eventField == null) { Debug.LogError( "Event definition not found: " + sourceComponent.GetType().Name + "." + methodName ); return; } try { var eventMethod = eventField.FieldType.GetMethod("Invoke"); var eventParams = eventMethod.GetParameters(); eventDelegate = createProxyEventDelegate(targetComponent, eventField.FieldType, eventParams, eventHandlerMethodInfo); } catch(Exception err) { Debug.LogError("Event binding failed - Failed to create event handler: " + err.ToString()); return; } var combinedDelegate = Delegate.Combine( eventDelegate, (Delegate)eventField.GetValue( sourceComponent ) ); eventField.SetValue( sourceComponent, combinedDelegate ); isBound = true; }
private void OnEnable() { script = target as AudioSourcePro; if(script.audioSource == null) { source = CheckForHiddenAudioSources(); if(source != null) script.audioSource = source; if(script.audioSource == null) { source = script.gameObject.AddComponent<AudioSource>(); script.audioSource = source; } } else source = script.audioSource; source.hideFlags = (HideFlags.HideInInspector | HideFlags.NotEditable); CalculateCurve(); }
private void OnEnable() { script = target as AudioSourcePro; if (script.audioSource == null) { source = CheckForHiddenAudioSources(); if (source != null) { script.audioSource = source; } if (script.audioSource == null) { source = script.gameObject.AddComponent <AudioSource>(); script.audioSource = source; } } else { source = script.audioSource; } source.hideFlags = (HideFlags.HideInInspector | HideFlags.NotEditable); CalculateCurve(); }