示例#1
0
        /// <summary>
        /// Register to the button events
        /// </summary>
        private void OnEnable()
        {
            if (_registered)
            {
                return;
            }
            if (_provider == null)
            {
                var context = metaContext;
                if (context == null)
                {
                    Debug.LogWarning("Could not get Meta Context. Button events will not be provided");
                    return;
                }

                if (!context.ContainsModule <IMetaButtonEventProvider>())
                {
                    Debug.LogWarning("Could not get Meta Button Event Provider. Button events will not be broadcasted");
                    return;
                }
                _provider = context.Get <IMetaButtonEventProvider>();
            }

            _provider.Subscribe(ProcessButtonEvents);
            _registered = true;
        }
        /// <summary>
        /// Connect all the components in the childrens to the main Event Provider
        /// </summary>
        private void OnEnable()
        {
            if (_broadcaster == null)
            {
                _broadcaster = GetComponent <IMetaButtonEventProvider>();
            }
            if (_controllers == null)
            {
                _controllers = GetComponentsInChildren <IOnMetaButtonEvent>();
            }

            for (int i = 0; i < _controllers.Length; ++i)
            {
                _broadcaster.Subscribe(_controllers[i].OnMetaButtonEvent);
            }
        }