Example #1
0
        public static void      Serialize(ByteBuffer buffer, ServerGameObject NGGameObject)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                NGGameObject.ProcessComponents();

                buffer.Append(NGGameObject.instanceID);
                buffer.AppendUnicodeString(NGGameObject.gameObject.tag);
                buffer.Append(NGGameObject.gameObject.layer);
                buffer.Append(NGGameObject.gameObject.isStatic);
                buffer.Append(NGGameObject.components.Count);

                for (int i = NGGameObject.components.Count - 1; i >= 0; --i)
                {
                    try
                    {
                        NetComponent.Serialize(buffer, NGGameObject.components[i]);
                    }
                    catch (Exception ex)
                    {
                        InternalNGDebug.LogException("GameObject \"" + NGGameObject.gameObject.name + "\" failed on Component \"" + NGGameObject.components[i].component.name + "\" (" + (i + 1) + "/" + NGGameObject.components.Count + ").", ex);
                        throw;
                    }
                }
            }
        }
Example #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();
                        }
                    }
                }
            }
        }
Example #3
0
 public static void      Serialize(ByteBuffer buffer, Type fieldType, UnityObject o)
 {
     using (SafeWrapByteBuffer.Get(buffer))
     {
         buffer.AppendUnicodeString((o.instanceID != 0 ? o.type : fieldType).GetShortAssemblyType());
         buffer.Append(o.gameObjectInstanceID);
         buffer.Append(o.instanceID);
         if (o.instanceID != 0)
         {
             buffer.AppendUnicodeString(o.name);
         }
     }
 }
Example #4
0
        public static void      Serialize(ServerGameObject node, ByteBuffer buffer)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                buffer.Append(node.gameObject.activeSelf);
                buffer.AppendUnicodeString(node.gameObject.name);
                buffer.Append(node.instanceID);
                buffer.Append(node.children.Count);

                for (int i = 0; i < node.children.Count; i++)
                {
                    NetGameObject.Serialize(node.children[i], buffer);
                }
            }
        }
Example #5
0
        public static void      Serialize(ByteBuffer buffer, Type fieldType, Object o)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                if (o != null)
                {
                    GameObject gameObject = o as GameObject;

                    buffer.AppendUnicodeString(o.GetType().GetShortAssemblyType());

                    if (gameObject != null)
                    {
                        buffer.Append(gameObject.GetInstanceID());
                    }
                    else
                    {
                        Component component = o as Component;

                        if (component != null)
                        {
                            buffer.Append(component.gameObject.GetInstanceID());
                        }
                        else
                        {
                            buffer.Append(0);
                        }
                    }

                    int instanceID = o.GetInstanceID();
                    buffer.Append(instanceID);
                    if (instanceID != 0)
                    {
                        buffer.AppendUnicodeString(o.name);
                    }
                }
                else
                {
                    buffer.AppendUnicodeString(fieldType.GetShortAssemblyType());
                    buffer.Append(0);
                    buffer.Append(0);
                }
            }
        }
Example #6
0
        public static void      Serialize(ByteBuffer buffer, object instance, IFieldModifier field)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                buffer.AppendUnicodeString(field.Type.GetShortAssemblyType());
                buffer.AppendUnicodeString(field.Name);
                buffer.Append(field.IsPublic);

                TypeHandler handler = TypeHandlersManager.GetTypeHandler(field.Type);

                if (handler != null)
                {
                    if (field.MemberInfo.DeclaringType.IsGenericTypeDefinition == false || ((field is FieldModifier) == true && (field as FieldModifier).fieldInfo.IsLiteral == true))
                    {
                        buffer.AppendUnicodeString(handler.GetType().GetShortAssemblyType());

                        try
                        {
                            buffer.Append((byte)TypeHandlersManager.GetTypeSignature(field.Type));

                            ByteBuffer handlerBuffer = Utility.GetBBuffer();
                            handler.Serialize(handlerBuffer, field.Type, field.GetValue(instance));
                            buffer.Append(Utility.ReturnBBuffer(handlerBuffer));
                        }
                        catch (Exception ex)
                        {
                            buffer.Append((byte)TypeSignature.Null);
                            InternalNGDebug.LogException("Member \"" + field.Name + "\" failed.", ex);
                            throw;
                        }
                    }
                    else                     // Leave it unsupported.
                    {
                        buffer.Append(0);
                    }
                }
                else
                {
                    buffer.Append(0);
                }
            }
        }
Example #7
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;
                    }
                }
            }
        }
Example #8
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;
                }
            }
        }
Example #9
0
        public static void      Serializer(ByteBuffer buffer, Type fieldType, object instance)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                IEnumerable array = instance as IEnumerable;

                if (array == null)
                {
                    buffer.Append(-1);                     // -1 = null array
                    return;
                }

                bool isBigArray = false;
                int  count      = 0;

                if (fieldType.IsArray == true)
                {
                    Array a = array as Array;

                    count      = a.Length;
                    isBigArray = a.Length > ArrayData.BigArrayThreshold;
                }
                else if (typeof(IList).IsAssignableFrom(fieldType) == true)
                {
                    IList a = array as IList;

                    count      = a.Count;
                    isBigArray = a.Count > ArrayData.BigArrayThreshold;
                }
                else
                {
                    throw new InvalidCastException("Array of type \"" + fieldType + "\" is not supported.");
                }

                buffer.Append(count);

                if (ArrayData.forceBigArray == true)
                {
                    ArrayData.forceBigArray = false;
                    isBigArray = false;
                }

                buffer.Append(isBigArray);

                if (isBigArray == false)
                {
                    Type        subType = Utility.GetArraySubType(fieldType);
                    TypeHandler subHandler;

                    if (subType != null)
                    {
                        subHandler = TypeHandlersManager.GetTypeHandler(subType);
                    }
                    else
                    {
                        subType    = typeof(object);
                        subHandler = TypeHandlersManager.GetTypeHandler(subType);
                    }

                    if (subHandler != null)
                    {
                        buffer.AppendUnicodeString(subHandler.GetType().GetShortAssemblyType());
                        buffer.Append((byte)TypeHandlersManager.GetTypeSignature(subType));

                        foreach (object item in array)
                        {
                            subHandler.Serialize(buffer, subType, item);
                        }
                    }
                    else
                    {
                        buffer.Append(0);
                    }
                }
            }
        }