Esempio n. 1
0
        public MonitorMaterialProperty(Material material, NGShaderProperty propertyInfo) : base(propertyInfo.name, null)
        {
            this.material     = material;
            this.propertyInfo = propertyInfo;

            switch (this.propertyInfo.type)
            {
            case NGShader.ShaderPropertyType.Color:
                this.typeHandler = TypeHandlersManager.GetTypeHandler(typeof(Color));
                this.value       = this.material.GetColor(this.propertyInfo.name);
                break;

            case NGShader.ShaderPropertyType.Float:
            case NGShader.ShaderPropertyType.Range:
                this.typeHandler = TypeHandlersManager.GetTypeHandler(typeof(float));
                this.value       = this.material.GetFloat(this.propertyInfo.name);
                break;

            case NGShader.ShaderPropertyType.TexEnv:
                this.typeHandler = TypeHandlersManager.GetTypeHandler(typeof(Texture));
                this.value       = this.material.GetTexture(this.propertyInfo.name);
                break;

            case NGShader.ShaderPropertyType.Vector:
                this.typeHandler = TypeHandlersManager.GetTypeHandler(typeof(Vector4));
                this.value       = this.material.GetVector(this.propertyInfo.name);
                break;
            }
        }
Esempio n. 2
0
        public static void      Serialize(ByteBuffer buffer, Material mat, NGShaderProperty prop)
        {
            buffer.AppendUnicodeString(prop.description);
            buffer.AppendUnicodeString(prop.name);
            buffer.Append((int)prop.type);
            buffer.Append(prop.hidden);
            buffer.Append(prop.rangeMin);
            buffer.Append(prop.rangeMax);

            Type        type = null;
            TypeHandler typeHandler;

            if (prop.type == NGShader.ShaderPropertyType.Color)
            {
                type = typeof(Color);
            }
            else if (prop.type == NGShader.ShaderPropertyType.Float ||
                     prop.type == NGShader.ShaderPropertyType.Range)
            {
                type = typeof(float);
            }
            else if (prop.type == NGShader.ShaderPropertyType.TexEnv)
            {
                type = typeof(Texture);
            }
            else if (prop.type == NGShader.ShaderPropertyType.Vector)
            {
                type = typeof(Vector4);
            }

            typeHandler = TypeHandlersManager.GetTypeHandler(type);
            InternalNGDebug.Assert(typeHandler != null, "TypeHandler for " + prop.name + " is not supported.");

            if (prop.type == NGShader.ShaderPropertyType.Color)
            {
                typeHandler.Serialize(buffer, type, mat.GetColor(prop.name));
            }
            else if (prop.type == NGShader.ShaderPropertyType.Float ||
                     prop.type == NGShader.ShaderPropertyType.Range)
            {
                typeHandler.Serialize(buffer, type, mat.GetFloat(prop.name));
            }
            else if (prop.type == NGShader.ShaderPropertyType.TexEnv)
            {
                typeHandler.Serialize(buffer, type, mat.GetTexture(prop.name));

                TypeHandler vector2Handler = TypeHandlersManager.GetTypeHandler <Vector2>();

                vector2Handler.Serialize(buffer, typeof(Vector2), mat.GetTextureOffset(prop.name));
                vector2Handler.Serialize(buffer, typeof(Vector2), mat.GetTextureScale(prop.name));
            }
            else if (prop.type == NGShader.ShaderPropertyType.Vector)
            {
                typeHandler.Serialize(buffer, type, mat.GetVector(prop.name));
            }

            //Debug.Log("NetMP.Ser " + prop.description + " " + prop.name + " " + prop.type + "	" + prop.hidden);
        }
Esempio n. 3
0
        public MonitorField(string path, Func <object> getInstance, FieldInfo fieldInfo) : base(path, getInstance)
        {
            this.fieldInfo   = fieldInfo;
            this.typeHandler = TypeHandlersManager.GetTypeHandler(this.fieldInfo.FieldType);
            this.isStruct    = this.fieldInfo.FieldType.IsStruct();
            this.value       = this.fieldInfo.GetValue(this.getInstance());

            this.MonitorSubData(this.fieldInfo.FieldType, () => this.fieldInfo.GetValue(this.getInstance()));
        }
Esempio n. 4
0
        private NetMaterialProperty(ByteBuffer buffer)
        {
            this.displayName = buffer.ReadUnicodeString();
            this.name        = buffer.ReadUnicodeString();
            this.type        = (NGShader.ShaderPropertyType)buffer.ReadInt32();
            this.hidden      = buffer.ReadBoolean();
            this.rangeMin    = buffer.ReadSingle();
            this.rangeMax    = buffer.ReadSingle();

            Type        type = null;
            TypeHandler typeHandler;

            if (this.type == NGShader.ShaderPropertyType.Color)
            {
                type = typeof(Color);
            }
            else if (this.type == NGShader.ShaderPropertyType.Float ||
                     this.type == NGShader.ShaderPropertyType.Range)
            {
                type = typeof(float);
            }
            else if (this.type == NGShader.ShaderPropertyType.TexEnv)
            {
                type = typeof(Texture);
            }
            else if (this.type == NGShader.ShaderPropertyType.Vector)
            {
                type = typeof(Vector4);
            }

            typeHandler = TypeHandlersManager.GetTypeHandler(type);
            InternalNGDebug.Assert(typeHandler != null, "TypeHandler for " + this.name + " is not supported.");

            if (this.type == NGShader.ShaderPropertyType.Color)
            {
                this.colorValue = (Color)typeHandler.Deserialize(buffer, type);
            }
            else if (this.type == NGShader.ShaderPropertyType.Float ||
                     this.type == NGShader.ShaderPropertyType.Range)
            {
                this.floatValue = (float)typeHandler.Deserialize(buffer, type);
            }
            else if (this.type == NGShader.ShaderPropertyType.TexEnv)
            {
                this.textureValue = (UnityObject)typeHandler.Deserialize(buffer, type);

                TypeHandler vector2Handler = TypeHandlersManager.GetTypeHandler <Vector2>();
                this.textureOffset = (Vector2)vector2Handler.Deserialize(buffer, typeof(Vector2));
                this.textureScale  = (Vector2)vector2Handler.Deserialize(buffer, typeof(Vector2));
            }
            else if (this.type == NGShader.ShaderPropertyType.Vector)
            {
                this.vectorValue = (Vector4)typeHandler.Deserialize(buffer, type);
            }

            //Debug.Log("NGMP.Des " + this.displayName + " " + this.name + " " + this.type + "	" + this.hidden);
        }
Esempio n. 5
0
        private ArrayData(ByteBuffer buffer, Type fieldType)
        {
            using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError))
            {
                this.serverType   = fieldType;
                this.originLength = buffer.ReadInt32();

                if (this.originLength == -1)
                {
                    this.isNull = true;
                }
                else
                {
                    this.isBigArray = buffer.ReadBoolean();

                    if (this.isBigArray == false)
                    {
                        string typeHandlerType = buffer.ReadUnicodeString();

                        if (string.IsNullOrEmpty(typeHandlerType) == false)
                        {
                            TypeHandler subHandler = TypeHandlersManager.GetTypeHandler(typeHandlerType);

                            if (subHandler != null)
                            {
                                TypeSignature typeSignature = (TypeSignature)buffer.ReadByte();

                                if (typeSignature != TypeSignature.Null)
                                {
                                    Type subType = TypeHandlersManager.GetClientType(this.serverType, typeSignature);

                                    this.array = Array.CreateInstance(subHandler.type, this.originLength);

                                    for (int i = 0; i < this.originLength; i++)
                                    {
                                        try
                                        {
                                            this.array.SetValue(subHandler.Deserialize(buffer, subType), i);
                                        }
                                        catch (Exception ex)
                                        {
                                            InternalNGDebug.LogException("Array of type " + fieldType.Name + " (" + subType + ") at " + i + " failed.", ex);
                                            throw;
                                        }
                                    }
                                }
                            }
                            else                             // Client does not know how to deserialize the element.
                            {
                                unwrap.ForceFallback();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public MonitorArrayItem(string path, Func <object> getArray, int index) : base(path, getArray)
        {
            this.index       = index;
            this.subType     = Utility.GetArraySubType(this.getInstance().GetType());
            this.typeHandler = TypeHandlersManager.GetTypeHandler(this.subType);
            this.isStruct    = this.subType.IsStruct();

            this.value = this.GetValue();

            this.MonitorSubData(this.subType, this.GetValue);
        }
Esempio n. 7
0
        public MonitorArray(string path, IFieldModifier fieldInfo, Func <object> getInstance) : base(path, getInstance)
        {
            this.sizeHandler = TypeHandlersManager.GetTypeHandler(typeof(int));
            this.fieldInfo   = fieldInfo;
            this.lastSize    = this.GetSize();

            object instance = this.fieldInfo.GetValue(this.getInstance());

            if (instance != null)
            {
                this.MonitorSubData(instance.GetType(), () => this.fieldInfo.GetValue(this.getInstance()));
            }
        }
Esempio n. 8
0
        public MonitorProperty(string path, Func <object> getInstance, PropertyInfo propertyInfo) : base(path, getInstance)
        {
            this.propertyInfo = propertyInfo;
            this.typeHandler  = TypeHandlersManager.GetTypeHandler(this.propertyInfo.PropertyType);
            this.isStruct     = this.propertyInfo.PropertyType.IsStruct();

            try
            {
                this.value = this.propertyInfo.GetValue(this.getInstance());
            }
            catch (Exception ex)
            {
                InternalNGDebug.LogException("Monitoring property \"" + path + "\" (" + propertyInfo.PropertyType.FullName + ") failed.", ex);
                throw;
            }

            this.MonitorSubData(this.propertyInfo.PropertyType, () => this.propertyInfo.GetValue(this.getInstance()));
        }
Esempio n. 9
0
        public override Packet[]        CreateUpdatePackets()
        {
            Packet[] packets = new Packet[this.lastSize + 1];

            packets[0] = new NotifyFieldValueUpdatedPacket(this.path, this.sizeHandler.Serialize(this.lastSize));

            Type        subType        = Utility.GetArraySubType(this.fieldInfo.Type);
            TypeHandler subTypeHandler = TypeHandlersManager.GetTypeHandler(subType);
            IEnumerable array          = this.fieldInfo.GetValue(this.getInstance()) as IEnumerable;
            int         i = 0;

            foreach (object element in array)
            {
                packets[i + 1] = new NotifyFieldValueUpdatedPacket(this.path + NGServerScene.ValuePathSeparator + i, subTypeHandler.Serialize(subType, element));
                ++i;
            }

            return(packets);
        }
Esempio n. 10
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);
                }
            }
        }
Esempio n. 11
0
        private NetField(ByteBuffer buffer)
        {
            using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError))
            {
                this.fieldType = Type.GetType(buffer.ReadUnicodeString());
                this.name      = buffer.ReadUnicodeString();
                this.isPublic  = buffer.ReadBoolean();

                string typeHandlerType = buffer.ReadUnicodeString();

                if (string.IsNullOrEmpty(typeHandlerType) == false)
                {
                    this.handler = TypeHandlersManager.GetTypeHandler(typeHandlerType);

                    if (this.handler != null)
                    {
                        this.typeSignature = (TypeSignature)buffer.ReadByte();
                        this.fieldType     = this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature);

                        if (this.typeSignature != TypeSignature.Null)
                        {
                            try
                            {
                                this.value = this.handler.Deserialize(buffer, this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature));
                            }
                            catch (Exception ex)
                            {
                                InternalNGDebug.LogException("Member \"" + this.name + "\" of type \"" + this.fieldType + "\" failed.", ex);
                                throw;
                            }
                        }
                    }
                    else                     // Client does not know how to deserialize this field.
                    {
                        unwrap.ForceFallback();
                    }
                }
            }
        }
Esempio n. 12
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);
                    }
                }
            }
        }
Esempio n. 13
0
 public MonitorColor(string path, Func <object> getInstance, IValueGetter valueGetter) : base(path, getInstance)
 {
     this.valueGetter = valueGetter;
     this.typeHandler = TypeHandlersManager.GetTypeHandler(valueGetter.Type);
     this.value       = valueGetter.GetValue <Color>(this.getInstance());
 }