예제 #1
0
        public override void    In(ByteBuffer buffer)
        {
            if (this.InResponseStatus(buffer) == true)
            {
                this.typeIndex       = buffer.ReadInt32();
                this.editableMembers = new bool[buffer.ReadInt32()];
                this.netMembers      = new NetField[this.editableMembers.Length];

                for (int i = 0; i < this.netMembers.Length; i++)
                {
                    using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError))
                    {
                        if (unwrap.IsValid() == true)
                        {
                            try
                            {
                                this.editableMembers[i] = buffer.ReadBoolean();
                                this.netMembers[i]      = NetField.Deserialize(buffer);
                            }
                            catch (Exception ex)
                            {
                                InternalNGDebug.LogException("Inspectable type index \"" + this.typeIndex + "\" at static member #" + i + " failed.", ex);
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public override void    Out(ByteBuffer buffer)
        {
            if (this.OutResponseStatus(buffer))
            {
                buffer.Append(this.typeIndex);
                buffer.Append(this.members.Length);

                for (int i = 0; i < this.members.Length; i++)
                {
                    using (SafeWrapByteBuffer wrap = SafeWrapByteBuffer.Get(buffer))
                    {
                        try
                        {
                            if (this.members[i] is FieldModifier)
                            {
                                FieldModifier modifier = (this.members[i] as FieldModifier);

                                buffer.Append(modifier.fieldInfo.IsLiteral == false || modifier.fieldInfo.IsInitOnly == true);
                            }
                            else
                            {
                                buffer.Append((this.members[i] as PropertyModifier).propertyInfo.GetSetMethod() != null);
                            }

                            NetField.Serialize(buffer, null, this.members[i]);
                        }
                        catch (Exception ex)
                        {
                            InternalNGDebug.LogException("Inspectable type index \"" + this.typeIndex + "\" at static member \"" + this.members[i].Name + "\" failed.", ex);
                            wrap.Erase();
                        }
                    }
                }
            }
        }
예제 #3
0
 public Field(NetField field)
 {
     this.fieldType     = field.fieldType;
     this.name          = field.name;
     this.isPublic      = field.isPublic;
     this.handler       = field.handler;
     this.typeSignature = field.typeSignature;
     this.value         = field.value;
 }
예제 #4
0
        private ClientClass(ByteBuffer buffer)
        {
            using (SafeUnwrapByteBuffer.Get(buffer, this.GetError))
            {
                int length = buffer.ReadInt32();

                if (length > -1)
                {
                    this.fields = new Field[length];
                    for (int i = 0; i < this.fields.Length; i++)
                    {
                        this.fields[i] = new Field(NetField.Deserialize(buffer));
                    }
                }
            }
        }
예제 #5
0
        private NetComponent(ByteBuffer buffer)
        {
            using (SafeUnwrapByteBuffer.Get(buffer, this.GetError))
            {
                this.instanceID = buffer.ReadInt32();
                buffer.ReadBooleans(out this.togglable, out this.deletable);
                this.type = Type.GetType(buffer.ReadUnicodeString());
                this.name = buffer.ReadUnicodeString();

                int length = buffer.ReadInt32();

                this.fields = new NetField[length];

                for (int i = 0; i < length; i++)
                {
                    try
                    {
                        this.fields[i] = NetField.Deserialize(buffer);
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException("Component \"" + this.name + "\" failed on field " + (i + 1) + "/" + length + ".", ex);
                        throw;
                    }
                }

                length = buffer.ReadInt32();

                this.methods = new NetMethod[length];

                for (int i = 0; i < length; i++)
                {
                    try
                    {
                        this.methods[i] = NetMethod.Deserialize(buffer);
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException("Component \"" + this.name + "\" failed on method " + (i + 1) + "/" + length + ".", ex);
                        throw;
                    }
                }
            }
        }
예제 #6
0
        public static void      Serialize(ByteBuffer buffer, ServerComponent component)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                Type componentType = component.component.GetType();

                buffer.Append(component.instanceID);
                buffer.Append(Utility.IsComponentEnableable(component.component),
                              (component.component is Transform) == false);                             // Deletable
                buffer.AppendUnicodeString(componentType.GetShortAssemblyType());
                buffer.AppendUnicodeString(componentType.Name);
                buffer.Append(component.fields.Length);

                for (int i = 0; i < component.fields.Length; i++)
                {
                    try
                    {
                        NetField.Serialize(buffer, component.component, component.fields[i]);
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException("Component \"" + componentType.Name + "\" failed on field \"" + component.fields[i].Name + "\" (" + (i + 1) + "/" + component.fields.Length + ").", ex);
                        throw;
                    }
                }

                buffer.Append(component.methods.Length);

                for (int i = 0; i < component.methods.Length; i++)
                {
                    try
                    {
                        NetMethod.Serialize(buffer, component.methods[i]);
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException("Component \"" + componentType.Name + "\" failed on method \"" + component.methods[i].methodInfo.Name + "\" (" + (i + 1) + "/" + component.methods.Length + ").", ex);
                        throw;
                    }
                }
            }
        }
예제 #7
0
        public static void      Serialize(ByteBuffer buffer, Type fieldType, object instance)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                if (instance == null)
                {
                    buffer.Append(-1);
                    return;
                }

                FieldInfo[] fields = fieldType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                int lengthPosition      = buffer.Length;
                int countFieldsAppended = 0;
                buffer.Append(0);

                for (int i = 0; i < fields.Length; i++)
                {
                    if (Utility.CanExposeFieldInInspector(fields[i]) == false)
                    {
                        continue;
                    }

                    NetField.Serialize(buffer, instance, new FieldModifier(fields[i]));
                    ++countFieldsAppended;
                }

                if (countFieldsAppended > 0)
                {
                    int restoreLengthPosition = buffer.Length;
                    buffer.Length = lengthPosition;
                    buffer.Append(countFieldsAppended);
                    buffer.Length = restoreLengthPosition;
                }
            }
        }