Ejemplo n.º 1
0
 public void CopyFromSrc(CustomMaterialProperty src)
 {
     _name          = src._name;
     _propType      = src._propType;
     _value_Float   = src._value_Float;
     _value_Int     = src._value_Int;
     _value_Vector  = src._value_Vector;
     _value_Color   = src._value_Color;
     _value_Texture = src._value_Texture;
 }
                static CustomMaterialProperty Deserialize(string data, object[] args)
                {
                    ShaderProperty shaderProperty = ShaderGenerator2.CurrentConfig.customMaterialPropertyShaderProperty;

                    // find the class name of the implementation, as it is needed to create an instance of CustomMaterialProperty
                    string serializedClassName = data.Substring(data.IndexOf("cimp:") + "cimp:".Length);

                    serializedClassName = serializedClassName.Substring(0, serializedClassName.IndexOf('('));
                    Type implementationType = null;
                    var  allTypes           = typeof(Serialization).Assembly.GetTypes();

                    foreach (var t in allTypes)
                    {
                        var classAttributes = t.GetCustomAttributes(typeof(Serialization.SerializeAsAttribute), false);
                        if (classAttributes != null && classAttributes.Length == 1)
                        {
                            var name = (classAttributes[0] as Serialization.SerializeAsAttribute).serializedName;
                            if (name == serializedClassName)
                            {
                                //match!
                                implementationType = t;
                            }
                        }
                    }
                    var customMaterialProperty = new CustomMaterialProperty(shaderProperty, implementationType);

                    Func <object, string, object> onDeserializeImplementation = (impObj, impData) =>
                    {
                        // Make sure to deserialize as a new object, so that final Implementation subtype is kept instead of creating base Implementation class
                        // Imp should only be an Imp_MaterialProperty
                        var imp = Serialization.Deserialize(impData, new object[] { shaderProperty });
                        return(imp);
                    };
                    var implementationHandling = new Dictionary <Type, Func <object, string, object> > {
                        { typeof(Imp_MaterialProperty), onDeserializeImplementation }
                    };

                    Serialization.DeserializeTo(customMaterialProperty, data, typeof(CustomMaterialProperty), args, implementationHandling);

                    return(customMaterialProperty);
                }