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); }
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(); } } } } } }