protected override void Bind()
    {
        base.Bind();

        var context = GetContext(Path);

        if (context == null)
        {
            return;
        }

        _collection = context.FindCollection(Path, this);
        if (_collection == null)
        {
            return;
        }

        _collection.OnItemInsert      += OnItemInsert;
        _collection.OnItemRemove      += OnItemRemove;
        _collection.OnItemsClear      += OnItemsClear;
        _collection.OnSelectionChange += OnCollectionSelectionChange;

        for (var i = 0; i < _collection.ItemsCount; ++i)
        {
            OnItemInsert(i, _collection.GetBaseItem(i));
        }
        OnCollectionSelectionChange();
    }
    public override void UpdateBinding()
    {
        if (_collection != null)
        {
            OnItemsClear();
            _collection.OnItemInsert -= OnItemInsert;
            _collection.OnItemRemove -= OnItemRemove;
            _collection.OnItemsClear -= OnItemsClear;
            _collection.OnSelectionChange -= OnDataSelectionChange;
            _collection = null;
        }

        var context = GetContext();
        if (context == null)
            return;

        _collection = context.FindCollection(Path, this);
        if (_collection == null)
        {
            Debug.LogWarning("iGuiItemsSourceBinding: failed to find collection at " + Path);
            return;
        }

        _collection.OnItemInsert += OnItemInsert;
        _collection.OnItemRemove += OnItemRemove;
        _collection.OnItemsClear += OnItemsClear;
        _collection.OnSelectionChange += OnDataSelectionChange;

        for(var i = 0; i < _collection.ItemsCount; ++i)
        {
            OnItemInsert(i, _collection.GetBaseItem(i));
        }
    }
	protected override void Unbind()
	{
		base.Unbind();
		
		if (_collection != null)
		{
			_collection.OnItemInsert -= OnItemInsert;
			_collection.OnItemRemove -= OnItemRemove;
			_collection.OnItemsClear -= OnItemsClear;
			_collection.OnSelectionChange -= OnCollectionSelectionChange;
			_collection = null;
			OnItemsClear();
		}
	}
    protected override void Unbind()
    {
        base.Unbind();

        if (_collection != null)
        {
            _collection.OnItemInsert      -= OnItemInsert;
            _collection.OnItemRemove      -= OnItemRemove;
            _collection.OnItemsClear      -= OnItemsClear;
            _collection.OnSelectionChange -= OnCollectionSelectionChange;
            _collection = null;
            OnItemsClear();
        }
    }
Esempio n. 5
0
    void UpdateCell(Bag bag, EZData.Collection <BagItemContext> viewBag, int i, int delta)
    {
        var   view = viewBag.GetItem(i - delta);
        IItem data = null;

        if (bag.items.ContainsKey(i + 1))
        {
            data = bag.items[i + 1];
        }
        if (data != null)
        {
            view.Count = data.Count;
            view.Icon  = data.GetUiIcon();
            view.Empty = false;
        }
        else
        {
            view.Empty = true;
        }
    }
    protected override void Bind()
    {
        base.Bind();

        var context = GetContext(Path);
        if (context == null)
            return;

        _collection = context.FindCollection(Path, this);
        if (_collection == null)
            return;

        _collection.OnItemInsert += OnItemInsert;
        _collection.OnItemRemove += OnItemRemove;
        _collection.OnItemsClear += OnItemsClear;
        _collection.OnSelectionChange += OnCollectionSelectionChange;

        for (var i = 0; i < _collection.ItemsCount; ++i)
        {
            OnItemInsert(i, _collection.GetBaseItem(i));
        }
        OnCollectionSelectionChange();
    }