示例#1
0
        public object AddOwnValue(FieldKey key, Type type = null)
        {
            if (type == null)
            {
                type = FieldMeta.Get(key).FieldType;
            }
            object value = null;

            if (type.IsArray)
            {
                value = Activator.CreateInstance(type, 0);
            }
            else
            {
                if (type == typeof(String) || type == typeof(string))
                {
                    value = String.Empty;
                }
                else
                {
                    value = Activator.CreateInstance(type);
                }
            }
            SetValue(key, value);
            return(value);
        }
            public void InspectEntity(Entity entity)
            {
                Layout.Label("Fields:");
                foreach (var key in entity.Fields.OwnValues.Keys.ToList())
                {
                    var type = FieldMeta.Get(key).FieldType;

                    if (type == typeof(int))
                    {
                        var value = entity.Fields.GetValue <int>(key, entity);
                        if (Layout.IntField(key.GetName(), ref value))
                        {
                            entity.Fields.SetValue(key, value);
                        }
                    }
                    else if (type == typeof(string))
                    {
                        var value = entity.Fields.GetValue <string>(key, entity);
                        if (Layout.TextField(key.GetName(), ref value))
                        {
                            entity.Fields.SetValue(key, value);
                        }
                    }
                    else if (type == typeof(Entity))
                    {
                        var link = entity.Fields.GetValue <Entity>(key, entity);
                        Layout.Button("Link: " + Utils.ToString(link), () => DataExplorer.Instance.Select(link));
                    }
                }
            }
示例#3
0
        public object AddOwnValue(FieldKey key, FieldBytes fieldBytes, bool sort = false)
        {
            var slice = fieldBytes.ByteSlice;

            Serializer.Instance.State = GameState.Instance.OriginalState;
            Serializer.Instance.State.StartLocalGroup();
            var resolver = MessagePack.MessagePackSerializer.DefaultResolver;
            var value    = FieldMeta.Get(key).Deserialize(slice.GetBytes(), slice.Offset, resolver, out int readSize);

            Serializer.Instance.State = null;
            SetValue(key, value);
            OwnValues.AddFieldBytes(fieldBytes);
            if (sort)
            {
                OwnValues.OriginalBytes.Sort();
            }
            return(value);
        }
示例#4
0
        public void SetValue(FieldKey key, object value)
        {
            var type         = value.GetType();
            var fieldMeta    = FieldMeta.Get(key);
            var expectedType = fieldMeta.FieldType;

            if (type != expectedType)
            {
                var producerInterace = typeof(IValueProducer <>).MakeGenericType(expectedType);
                if (!type.IsImplementInterface(producerInterace))
                {
                    throw new System.Exception("Field type doesn't match!");
                }
            }

            if (OwnValues == null)
            {
                OwnValues = new FieldList();
            }

            OwnValues[key] = value;
        }