Exemplo n.º 1
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();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }
Exemplo n.º 3
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;
                }
            }
        }