// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ static void AddEventListeners(exUIControl _ctrl, string _eventName, List <SlotInfo> _slots) { foreach (SlotInfo slot in _slots) { bool foundMethod = false; if (slot.receiver == null) { continue; } MonoBehaviour[] allMonoBehaviours = slot.receiver.GetComponents <MonoBehaviour>(); for (int i = 0; i < allMonoBehaviours.Length; ++i) { MonoBehaviour monoBehaviour = allMonoBehaviours[i]; // don't get method from control if (monoBehaviour is exUIControl) { continue; } MethodInfo mi = monoBehaviour.GetType().GetMethod(slot.method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(exUIEvent) }, null); if (mi != null) { Action <exUIEvent> func = (Action <exUIEvent>)Delegate.CreateDelegate(typeof(Action <exUIEvent>), monoBehaviour, mi); _ctrl.AddEventListener(_eventName, func, slot.capturePhase); foundMethod = true; } } if (foundMethod == false) { Debug.LogWarning("Can not find method " + slot.method + " in " + slot.receiver.name); } } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void AddState_Color(exUIControl _ctrl, EffectState_Color _state) { for (int i = 0; i < _state.info.propInfos.Count; ++i) { EffectInfo_Color.PropInfo propInfo = _state.info.propInfos[i]; switch (propInfo.type) { case EffectEventType.Deactive: _ctrl.AddEventListener("onDeactive", delegate(exUIEvent _event) { enabled = true; _state.Begin(propInfo.val); }); _ctrl.AddEventListener("onActive", delegate(exUIEvent _event) { enabled = true; _state.Begin(_state.info.normal); }); break; case EffectEventType.Press: _ctrl.AddEventListener("onPressDown", delegate(exUIEvent _event) { enabled = true; _state.Begin(propInfo.val); }); _ctrl.AddEventListener("onPressUp", delegate(exUIEvent _event) { enabled = true; _state.Begin(_state.info.GetValue(EffectEventType.Hover)); }); break; case EffectEventType.Hover: _ctrl.AddEventListener("onHoverIn", delegate(exUIEvent _event) { enabled = true; _state.Begin(propInfo.val); }); _ctrl.AddEventListener("onHoverOut", delegate(exUIEvent _event) { enabled = true; _state.Begin(_state.info.normal); }); break; case EffectEventType.Unchecked: exUIToggle toggle = _ctrl as exUIToggle; if (toggle != null) { _ctrl.AddEventListener("onUnchecked", delegate(exUIEvent _event) { enabled = true; _state.Begin(propInfo.val); }); _ctrl.AddEventListener("onChecked", delegate(exUIEvent _event) { enabled = true; _state.Begin(_state.info.GetValue(EffectEventType.Hover)); }); } break; } } states.Add(_state); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ void AddState_Scale( exUIControl _ctrl, EffectState_Scale _state ) { for ( int i = 0; i < _state.info.propInfos.Count; ++i ) { EffectInfo_Scale.PropInfo propInfo = _state.info.propInfos[i]; switch ( propInfo.type ) { case EffectEventType.Deactive: _ctrl.AddEventListener( "onDeactive", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( propInfo.val ); } ); _ctrl.AddEventListener( "onActive", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( _state.info.normal ); } ); break; case EffectEventType.Press: _ctrl.AddEventListener ( "onPressDown", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( propInfo.val ); } ); _ctrl.AddEventListener ( "onPressUp", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( _state.info.GetValue( EffectEventType.Hover ) ); } ); _ctrl.AddEventListener ( "onHoverOut", delegate ( exUIEvent _event ) { if ( _ctrl.grabMouseOrTouch == false ) { enabled = true; _state.Begin( _state.info.normal ); } } ); break; case EffectEventType.Hover: _ctrl.AddEventListener ( "onHoverIn", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( propInfo.val ); } ); _ctrl.AddEventListener ( "onHoverOut", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( _state.info.normal ); } ); break; case EffectEventType.Unchecked: exUIToggle toggle = _ctrl as exUIToggle; if ( toggle != null ) { _ctrl.AddEventListener ( "onUnchecked", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( propInfo.val ); } ); _ctrl.AddEventListener ( "onChecked", delegate ( exUIEvent _event ) { enabled = true; _state.Begin( _state.info.GetValue( EffectEventType.Hover ) ); } ); } break; } } states.Add(_state); }