/// <summary>
        /// Attempts to unsubscribe a value-changed listener from a node.
        /// </summary>
        /// <param name="node">The node to unsubscribe the listener from.</param>
        /// <param name="callback">The listener to unsubscribe.</param>
        /// <param name="strict">Whether to throw an exception if something goes wrong.</param>
        /// <exception cref="ArgumentException">Thrown if operating in strict mode and the callback wasn't registered to the node.</exception>
        public void Unsubscribe(BusNode node, OnValueChangedCallback callback, bool strict = true)
        {
            NodeEntry entry = null;

            entry = _nodes[node];

            lock (entry)
            {
                if (!entry.Subscribers.Remove(callback) && strict)
                {
                    throw new ArgumentException("Unable to unsubscribe from node " + node + " as the delegate wasn't subscribed properly.");
                }
            }
        }
        /// <summary>
        /// Attempts to subscribe a value-changed listener to a node.
        /// </summary>
        /// <typeparam name="T">The type of the object to attach to the node. Must be a serializable type.</typeparam>
        /// <param name="node">The node to subscribe the listener to.</param>
        /// <param name="callback">The delegate to call when a node has been changed.</param>
        public void Subscribe(BusNode node, OnValueChangedCallback callback)
        {
            NodeEntry entry;

            entry = _nodes[node];

            lock (entry)
            {
                if (!entry.Subscribers.Contains(callback))
                {
                    entry.Subscribers.Add(callback);
                }
            }
        }
        public override void CheckForValueUpdate()
        {
            // Check if we are the owner of this
            if (ShouldReplicate())
            {
                return;
            }

            uint RemoteTick   = GameClock.GetRemoteTick();
            bool ValueChanged = false;

            // Find the most recent update
            List <uint> touchedKeys = new List <uint>();

            foreach (uint key in ValueList.Keys)
            {
                if (key > RemoteTick)
                {
                    break;
                }

                ValueList[key].ForEach(parameters => GetCommandReplicator().MDProcessCommand((object[])parameters));
                ValueChanged = true;
                touchedKeys.Add(key);
            }

            if (ValueChanged)
            {
                // Remove old
                touchedKeys.ForEach(k => ValueList.Remove(k));

                // Send event
                if (OnValueChangedCallback != null)
                {
                    Node Instance = NodeRef.GetRef() as Node;
                    OnValueChangedCallback.Invoke(Instance, null);
                }
            }
        }
        public override void SetValues(uint Tick, params object[] Parameters)
        {
            // If the tick this update is for is past the current tick
            if (GameClock.GetRemoteTick() >= Tick || IsSynchInProgress())
            {
                GetCommandReplicator().MDProcessCommand(Parameters);
                if (OnValueChangedCallback != null)
                {
                    Node Instance = NodeRef.GetRef() as Node;
                    OnValueChangedCallback.Invoke(Instance, null);
                }
            }
            else
            {
                if (!ValueList.ContainsKey(Tick))
                {
                    ValueList.Add(Tick, new List <object>());
                }

                ValueList[Tick].Add(Parameters);
            }
        }
Example #5
0
 public override void OnValueChanged(Enum newValue)
 {
     OnValueChangedCallback?.Invoke((T)newValue);
 }
Example #6
0
 public void OnValueChanged(T newValue)
 {
     OnValueChangedCallback?.Invoke(newValue);
 }