Ejemplo n.º 1
0
        public override void Bind(object obj, string name)
        {
            object value = MpReflection.GetValue(obj, name);
            Type   type  = value.GetType();

            SyncSerialization.WriteSyncObject(writer, value, type);
        }
Ejemplo n.º 2
0
        public override void Bind(object obj, string name)
        {
            object value = MpReflection.GetValue(obj, name);

            Type type = value.GetType();

            var res = SyncSerialization.ReadSyncObject(reader, type);

            MpReflection.SetValue(obj, name, res);
        }
Ejemplo n.º 3
0
        // todo what happens on exceptions?
        public static void FieldWatchPostfix()
        {
            if (Multiplayer.Client == null)
            {
                return;
            }

            while (watchedStack.Count > 0)
            {
                FieldData data = watchedStack.Pop();

                if (data == null)
                {
                    break; // The marker
                }
                SyncField handler = data.handler;

                object newValue = MpReflection.GetValue(data.target, handler.memberPath, data.index);
                bool   changed  = !Equals(newValue, data.oldValue);
                var    cache    = (handler.bufferChanges && !Multiplayer.IsReplay) ? bufferedChanges.GetValueSafe(handler) : null;

                if (cache != null && cache.TryGetValue(new Pair <object, object>(data.target, data.index), out BufferData cached))
                {
                    if (changed && cached.sent)
                    {
                        cached.sent = false;
                    }

                    cached.toSend = newValue;
                    MpReflection.SetValue(data.target, handler.memberPath, cached.actualValue, data.index);
                    continue;
                }

                if (!changed)
                {
                    continue;
                }

                if (cache != null)
                {
                    BufferData bufferData = new BufferData(data.oldValue, newValue);
                    cache[new Pair <object, object>(data.target, data.index)] = bufferData;
                }
                else
                {
                    handler.DoSync(data.target, newValue, data.index);
                }

                MpReflection.SetValue(data.target, handler.memberPath, data.oldValue, data.index);
            }
        }
Ejemplo n.º 4
0
 public static object GetPropertyOrField(this object obj, string memberPath, object index = null)
 {
     return(MpReflection.GetValue(obj, memberPath, index));
 }