Ejemplo n.º 1
0
        /// <summary>
        /// Removes element from the set.
        /// <para />Warning: Decorators which alter the data on remove will not change which element is removed.
        /// </summary>
        /// <returns>If successful, index of removed element. Otherwise -1.</returns>
        public int Remove(TData element)
        {
            // Auto-bound SmartRefs get bound first time value added/removed after they're queued
            if (_binder.hasRefsToBind)
            {
                _binder.AutoBind();
            }

            int  index  = _runtimeSet.IndexOf(element);
            bool result = index >= 0;
            var  data   = new SetEventData <TData>(element, element, SetOperation.REMOVED, index);

            if (_hasDecorators)
            {
                // Execute decorators without altering data
                for (int i = 0; i < _decorators.Length; ++i)
                {
                    ((SmartSetDecoratorBase <TData>)_decorators[i]).OnChanged(data);
                }
            }

            if (result)
            {
                _runtimeSet.Remove(element);

                // Auto-bound SmartRefs get bound first time value added/removed after they're queued
                if (_binder.hasRefsToBind)
                {
                    _binder.AutoBind();
                }

                _relay.Dispatch(data);
            }
            return(index);
        }
Ejemplo n.º 2
0
        public bool Add(TData element, bool allowDuplicates = true)
        {
            if (allowDuplicates || !_runtimeSet.Contains(element))
            {
                // Auto-bound SmartRefs get bound first time value added/removed after they're queued
                if (_binder.hasRefsToBind)
                {
                    _binder.AutoBind();
                }

                SetEventData <TData> data = new SetEventData <TData>(element, default(TData), SetOperation.ADDED, count);
                if (_hasDecorators)
                {
                    var temp = data;
                    temp    = ExecuteDecoratorsOnChanged(temp);
                    data    = temp;
                    element = temp.value;
                }

                _runtimeSet.Add(element);
                _relay.Dispatch(data);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
 SetEventData <TData> ExecuteDecoratorsOnChanged(SetEventData <TData> data)
 {
     for (int i = 0; i < _decorators.Length; ++i)
     {
         data = ((SmartSetDecoratorBase <TData>)_decorators[i]).OnChanged(data);
     }
     return(data);
 }
Ejemplo n.º 4
0
        bool RemoveAt(int index, SetOperation operation)
        {
            TData element = this[index];
            bool  result  = _runtimeSet.Count > index;
            var   data    = new SetEventData <TData>(element, element, operation, index);

            if (_hasDecorators)
            {
                data = ExecuteDecoratorsOnChanged(data);
            }

            _runtimeSet.RemoveAt(index);
            _relay.Dispatch(data);
            return(result);
        }
Ejemplo n.º 5
0
        protected sealed override void InvokeUnityEvent(SetEventData <bool> d)
        {
            switch (d.operation)
            {
            case SetOperation.ADDED:
                _onAdd.Invoke(d.value);
                break;

            case SetOperation.REMOVED:
                _onRemove.Invoke(d.value);
                break;

            case SetOperation.CHANGED:
                _onChange.Invoke(d.value);
                break;
            }
        }
Ejemplo n.º 6
0
        void OnSetChanged(SetEventData <float> d)
        {
            switch (d.operation)
            {
            case SetOperation.ADDED:
                OnAdded(d.value);
                break;

            case SetOperation.REMOVED:
                OnRemoved(d.value);
                break;

            case SetOperation.CHANGED:
                OnChanged(d.value);
                break;
            }
        }
        /// <summary>
        /// Call to receive an update from the network.
        /// </summary>
        public void Receive(SetEventData <TData> data)
        {
            this.active = false;

            switch (data.operation)
            {
            case SetOperation.ADDED:
                owner.Add(data.value);
                break;

            case SetOperation.REMOVED:
                owner.RemoveAt(data.index);
                break;

            case SetOperation.CHANGED:
                owner[data.index] = data.value;
                break;
            }

            this.active = true;
        }
Ejemplo n.º 8
0
        public TData this[int index] {
            get { return(_runtimeSet[index]); }
            set {
                // Auto-bound SmartRefs get bound first time value added/removed after they're queued
                if (_binder.hasRefsToBind)
                {
                    _binder.AutoBind();
                }

                var data = new SetEventData <TData>(value, _runtimeSet[index], SetOperation.CHANGED, index);
                if (_hasDecorators)
                {
                    var temp = data;
                    temp  = ExecuteDecoratorsOnChanged(temp);
                    data  = temp;
                    value = temp.value;
                }

                _runtimeSet[index] = value;
                _relay.Dispatch(data);
            }
        }
 protected abstract void Send(SetEventData <TData> data, RestoreMode restoreMode);
 public override SetEventData <TData> OnChanged(SetEventData <TData> data)
 {
     Send(data, _currentRestoreMode);
     return(data);
 }
Ejemplo n.º 11
0
 protected abstract void InvokeUnityEvent(SetEventData <TData> data);