public AGSComponentBinding(IComponentsCollection collection, Action <TComponent> onAdded,
                                   Action <TComponent> onRemoved)
        {
            _collection    = collection;
            this.onAdded   = onAdded;
            this.onRemoved = onRemoved;
            collection.OnComponentsChanged.Subscribe(onComponentsChanged);
            TComponent component = collection.GetComponent <TComponent>();

            if (component != null)
            {
                onAdded.Invoke(component);
            }
            else if (!collection.ComponentsInitialized)
            {
                collection.OnComponentsInitialized.Subscribe(onComponentsInitialized);
            }
        }
示例#2
0
 public AGSComponentBinding(IComponentsCollection collection, Action <TComponent> onAdded,
                            Action <TComponent> onRemoved)
 {
     _collection = collection;
     _componentChangedCallback      = new Action <AGSListChangedEventArgs <IComponent> >(onComponentsChanged);
     _componentsInitializedCallback = new Action(onComponentsInitialized);
     this.onAdded   = onAdded;
     this.onRemoved = onRemoved;
     collection.OnComponentsChanged.Subscribe(_componentChangedCallback);
     _component = collection.GetComponent <TComponent>();
     if (_component != null)
     {
         onAdded.Invoke(_component);
     }
     else if (!collection.ComponentsInitialized)
     {
         collection.OnComponentsInitialized.Subscribe(_componentsInitializedCallback);
     }
 }