Beispiel #1
0
 protected virtual void OnSetState(NetworkComponentState componentState, int timeStamp)
 {
     foreach (var componentProperty in componentState.Properties)
     {
         if (m_properties.TryGetValue(componentProperty.Name, out var propertyInfo))
         {
             propertyInfo.SetValue(this, JsonSerializer.Deserialize(componentProperty.Value, propertyInfo.PropertyType));
         }
         else
         {
             Debug.LogError($"Property not exists : {componentProperty.Name}");
         }
     }
 }
Beispiel #2
0
        protected virtual NetworkComponentState OnGetState()
        {
            var componentState = new NetworkComponentState
            {
                Name       = GetType().Name,
                Properties = new List <NetworkComponentProperty>()
            };

            foreach (var propertyInfo in m_properties.Values)
            {
                componentState.Properties.Add(new NetworkComponentProperty
                {
                    Name  = propertyInfo.Name,
                    Value = JsonSerializer.Serialize(propertyInfo.GetValue(this, null), propertyInfo.PropertyType)
                });
            }

            ShouldUpdate = false;

            return(componentState);
        }
Beispiel #3
0
 internal void SetState(NetworkComponentState componentState, int timeStamp)
 {
     Assert.AreEqual(GetType().Name, componentState.Name);
     OnSetState(componentState, timeStamp);
 }