Пример #1
0
        /// <summary>
        /// Writes all properties for the given <paramref name="obj"/> that have the <see cref="SyncValueAttribute"/>
        /// attribute to the given <see cref="IValueWriter"/>.
        /// </summary>
        /// <param name="obj">The object to write the persistent values for.</param>
        /// <param name="writer">The <see cref="IValueWriter"/> to write to.</param>
        public static void Write(object obj, IValueWriter writer)
        {
            var propertySyncs = PropertySyncHelper.GetPropertySyncs(obj.GetType());

            foreach (var ps in propertySyncs)
            {
                ps.WriteValue(obj, writer);
            }
        }
Пример #2
0
        /// <summary>
        /// Reads all properties for the given <paramref name="obj"/> that have the <see cref="SyncValueAttribute"/>
        /// attribute from the given <see cref="IValueWriter"/>.
        /// </summary>
        /// <param name="obj">The object to read the persistent values for.</param>
        /// <param name="reader">The <see cref="IValueReader"/> to read the values from.</param>
        public static void Read(object obj, IValueReader reader)
        {
            var propertySyncs = PropertySyncHelper.GetPropertySyncs(obj.GetType());

            foreach (var ps in propertySyncs)
            {
                ps.ReadValue(obj, reader);
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicEntity"/> class.
        /// </summary>
        /// <param name="position">The initial world position.</param>
        /// <param name="size">The initial size.</param>
        protected DynamicEntity(Vector2 position, Vector2 size) : base(position, size)
        {
            // Get the PropertySyncBases for this DynamicEntity instance
            // OrderBy() will make sure every PropertySync where SkipNetworkSync is true is at the end of the array
            _propertySyncs = PropertySyncHelper.GetPropertySyncs(GetType()).OrderBy(x => x.SkipNetworkSync).ToArray();

            // Store the index of the last PropertySync that needs to be synchronized over the network
            _lastNetworkSyncIndex = (byte)(_propertySyncs.Count(x => !x.SkipNetworkSync) - 1);

            AssertValidPropertySyncs();
        }
Пример #4
0
 public TestClass()
 {
     _propertySyncs = PropertySyncHelper.GetPropertySyncs(GetType()).ToArray();
 }