Exemplo n.º 1
0
 private static MaterialPropertyAccessor[] CreateAccessors(Material[] materials, string propertyName)
 {
     MaterialPropertyAccessor[] accessors = new MaterialPropertyAccessor[materials.Length];
     for (int i = 0; i < materials.Length; ++i)
     {
         accessors[i] = new MaterialPropertyAccessor(materials[i], propertyName);
     }
     return(accessors);
 }
 public static MaterialPropertyDescriptor CreatePropertyDescriptor(Material material, PropertyInfo propertyInfo, string propertyDescr, string propertyName, RTShaderPropertyType propertyType, TextureDimension dim, RuntimeShaderInfo.RangeLimits limits)
 {
     return(new MaterialPropertyDescriptor(
                material,
                new MaterialPropertyAccessor(material, propertyName),
                propertyDescr, propertyType, propertyInfo, limits, dim, null,
                (accessorRef, newTarget) =>
     {
         MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
         accessor.Material = newTarget as Material;
     }));
 }
 public void EraseAccessorTarget(object accessorRef, object target)
 {
     if (accessorRef is StandardMaterialValueConverter)
     {
         StandardMaterialValueConverter accessor = (StandardMaterialValueConverter)accessorRef;
         accessor.Material = target as Material;
     }
     else if (accessorRef is MaterialPropertyAccessor)
     {
         MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
         accessor.Material = target as Material;
     }
 }
Exemplo n.º 4
0
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor)
        {
            RuntimeShaderInfo shaderInfo = RuntimeShaderUtil.GetShaderInfo(editor.Material.shader);

            if (shaderInfo == null)
            {
                return(null);
            }
            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            for (int i = 0; i < shaderInfo.PropertyCount; ++i)
            {
                bool isHidden = shaderInfo.IsHidden[i];
                if (isHidden)
                {
                    continue;
                }

                string propertyDescr = shaderInfo.PropertyDescriptions[i];
                string propertyName  = shaderInfo.PropertyNames[i];
                if (propertyName != "_Color" && propertyName != "_MainTex")
                {
                    continue;
                }

                RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                PropertyInfo     propertyInfo = null;
                switch (propertyType)
                {
                case RTShaderPropertyType.Color:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color);
                    break;

                case RTShaderPropertyType.Float:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;

                case RTShaderPropertyType.Range:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;

                case RTShaderPropertyType.TexEnv:
                    switch (dim)
                    {
                    case TextureDimension.Any:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture);
                        break;

                    case TextureDimension.Cube:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Cubemap);
                        break;

                    case TextureDimension.None:
                        propertyInfo = null;
                        break;

                    case TextureDimension.Tex2D:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2D);
                        break;

                    case TextureDimension.Tex2DArray:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2DArray);
                        break;

                    case TextureDimension.Tex3D:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture3D);
                        break;

                    case TextureDimension.Unknown:
                        propertyInfo = null;
                        break;
                    }

                    break;

                case RTShaderPropertyType.Vector:
                    propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float);
                    break;
                }

                if (propertyInfo == null)
                {
                    continue;
                }

                MaterialPropertyAccessor   accessor           = new MaterialPropertyAccessor(editor.Material, propertyName);
                MaterialPropertyDescriptor propertyDescriptor = new MaterialPropertyDescriptor(accessor, propertyDescr, propertyType, propertyInfo, limits, dim, null);
                descriptors.Add(propertyDescriptor);
            }

            return(descriptors.ToArray());
        }
Exemplo n.º 5
0
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor, object converter)
        {
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(editor.Material.shader);
            }


            if (shaderInfo == null)
            {
                return(null);
            }

            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            if (shaderInfo != null)
            {
                for (int i = 0; i < shaderInfo.PropertyCount; ++i)
                {
                    bool isHidden = shaderInfo.IsHidden[i];
                    if (isHidden)
                    {
                        continue;
                    }

                    string propertyDescr = shaderInfo.PropertyDescriptions[i];
                    string propertyName  = shaderInfo.PropertyNames[i];
                    RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                    RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                    TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                    PropertyInfo     propertyInfo = null;
                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Color:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color, "Color");
                        break;

                    case RTShaderPropertyType.Float:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.Range:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.TexEnv:
                        switch (dim)
                        {
                        case TextureDimension.Any:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture, "Texture");
                            break;

                        case TextureDimension.Cube:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Cubemap, "Cubemap");
                            break;

                        case TextureDimension.None:
                            propertyInfo = null;
                            break;

                        case TextureDimension.Tex2D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2D, "Texture2D");
                            break;

                        case TextureDimension.Tex2DArray:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2DArray, "Texture2DArray");
                            break;

                        case TextureDimension.Tex3D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture3D, "Texture3D");
                            break;

                        case TextureDimension.Unknown:
                            propertyInfo = null;
                            break;
                        }

                        break;

                    case RTShaderPropertyType.Vector:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Vector, "Vector");
                        break;
                    }

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    MaterialPropertyDescriptor propertyDescriptor = new MaterialPropertyDescriptor(
                        editor.Material,
                        new MaterialPropertyAccessor(editor.Material, propertyName),
                        propertyDescr, propertyType, propertyInfo, limits, dim, null,
                        (accessorRef, newTarget) =>
                    {
                        MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
                        accessor.Material = newTarget as Material;
                    });
                    descriptors.Add(propertyDescriptor);
                }
            }

            return(descriptors.ToArray());
        }