Ejemplo n.º 1
0
 public static Offset <ShaderProperty> CreateShaderProperty(FlatBufferBuilder builder,
                                                            StringOffset namesOffset       = default(StringOffset),
                                                            ShaderPropertyType type        = ShaderPropertyType.Float,
                                                            ShaderPropertyValue value_type = ShaderPropertyValue.NONE,
                                                            int valueOffset = 0)
 {
     builder.StartObject(4);
     ShaderProperty.AddValue(builder, valueOffset);
     ShaderProperty.AddNames(builder, namesOffset);
     ShaderProperty.AddValueType(builder, value_type);
     ShaderProperty.AddType(builder, type);
     return(ShaderProperty.EndShaderProperty(builder));
 }
Ejemplo n.º 2
0
        public ResourceObject Parse(ByteBuffer bb)
        {
            Schema.Material _material = Schema.Material.GetRootAsMaterial(bb);

            ResourceObjectMaterial result = new ResourceObjectMaterial(_material.Shader);

            UnityEngine.Material material = result.Unity3dObject as UnityEngine.Material;
            material.name = _material.Name;

            for (int i = 0; i < _material.PropertiesLength; i++)
            {
                Schema.ShaderProperty p = _material.GetProperties(i);
                switch (p.Type)
                {
                case ShaderPropertyType.Float:
                case ShaderPropertyType.Range:
                {
                    Schema.ShaderPropertyFloat f = p.GetValue <Schema.ShaderPropertyFloat>(fObj);
                    material.SetFloat(p.Names, f.Value);
                }
                break;

                case ShaderPropertyType.Color:
                {
                    Schema.ShaderPropertyColor c = p.GetValue <Schema.ShaderPropertyColor>(cObj);
                    material.SetColor(p.Names, new UnityEngine.Color(c.Color.R, c.Color.G, c.Color.B, c.Color.A));
                }
                break;

                case ShaderPropertyType.Vector:
                {
                    Schema.ShaderPropertyVector v = p.GetValue <Schema.ShaderPropertyVector>(vObj);
                    material.SetVector(p.Names, new Vector4(v.Vector.X, v.Vector.Y, v.Vector.Z, v.Vector.W));
                }
                break;

                case ShaderPropertyType.TexEnv:
                {
                    Schema.ShaderPropertyTexture t = p.GetValue <Schema.ShaderPropertyTexture>(tObj);
                    material.SetTextureOffset(p.Names, new Vector2(t.Offset.X, t.Offset.Y));
                    material.SetTextureScale(p.Names, new Vector2(t.Scale.X, t.Scale.Y));
                    result.AddTexture(t.Name, p.Names);
                }
                break;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void AllPropertiesExist()
        {
            Dictionary <string, Schema.ShaderProperty> dictProperties = new Dictionary <string, ShaderProperty>();

            for (int i = 0; i < material.PropertiesLength; i++)
            {
                Schema.ShaderProperty p = material.GetProperties(i);
                dictProperties.Add(p.Names, p);
            }


            int count = ShaderUtil.GetPropertyCount(originMaterial.shader);

            Assert.AreEqual(count, material.PropertiesLength);


            for (int i = 0; i < count; i++)
            {
                string name = ShaderUtil.GetPropertyName(originMaterial.shader, i);
                Assert.IsTrue(dictProperties.ContainsKey(name));
            }
        }
Ejemplo n.º 4
0
 public ShaderProperty GetProperties(ShaderProperty obj, int j)
 {
     int o = __offset(8); return(o != 0 ? obj.__init(__indirect(__vector(o) + j * 4), bb) : null);
 }
Ejemplo n.º 5
0
        public void EqualSource()
        {
            UnityEngine.Material realMaterial = resultMaterial.Unity3dObject as UnityEngine.Material;

            Assert.AreEqual(material.Name, realMaterial.name);
            Assert.AreEqual(material.Shader, realMaterial.shader.name);
            for (int i = 0; i < material.PropertiesLength; i++)
            {
                Schema.ShaderProperty p = material.GetProperties(i);

                Assert.IsTrue(realMaterial.HasProperty(p.Names));

                switch (p.Type)
                {
                case ShaderPropertyType.Float:
                case ShaderPropertyType.Range:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyFloat);

                    float originValue     = realMaterial.GetFloat(p.Names);
                    ShaderPropertyFloat f = p.GetValue <ShaderPropertyFloat>(new ShaderPropertyFloat());
                    Assert.AreEqual(f.Value, originValue);
                }
                break;

                case ShaderPropertyType.Color:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyColor);

                    UnityEngine.Color   originValue = realMaterial.GetColor(p.Names);
                    ShaderPropertyColor c           = p.GetValue <ShaderPropertyColor>(new ShaderPropertyColor());
                    Assert.AreEqual(originValue.a, c.Color.A);
                    Assert.AreEqual(originValue.g, c.Color.G);
                    Assert.AreEqual(originValue.b, c.Color.B);
                    Assert.AreEqual(originValue.r, c.Color.R);
                }
                break;

                case ShaderPropertyType.Vector:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyVector);

                    UnityEngine.Vector4  originValue = realMaterial.GetVector(p.Names);
                    ShaderPropertyVector v           = p.GetValue <ShaderPropertyVector>(new ShaderPropertyVector());
                    Assert.AreEqual(originValue.x, v.Vector.X);
                    Assert.AreEqual(originValue.y, v.Vector.Y);
                    Assert.AreEqual(originValue.z, v.Vector.Z);
                    Assert.AreEqual(originValue.w, v.Vector.W);
                }
                break;

                case ShaderPropertyType.TexEnv:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyTexture);
                    //UnityEngine.Texture texture = realMaterial.GetTexture(p.Names);
                    Vector2 offset = realMaterial.GetTextureOffset(p.Names);
                    Vector2 scale  = realMaterial.GetTextureScale(p.Names);

                    //这个测试用例不真正装载 texture.
                    //Assert.IsFalse(texture == null);
                    ShaderPropertyTexture t = p.GetValue <ShaderPropertyTexture>(new ShaderPropertyTexture());
                    string texturePath      = resultMaterial.GetTexturePath(t.Name);

                    Assert.IsTrue(realMaterial.HasProperty(p.Names));
                    Assert.IsTrue(dictTextures.ContainsKey(texturePath));
                    Assert.IsNotNull(realMaterial.GetTexture(p.Names));
                    Assert.AreEqual(dictTextures[texturePath].resourceObject.Unity3dObject.GetInstanceID(), realMaterial.GetTexture(p.Names).GetInstanceID());

                    Assert.AreEqual(offset.x, t.Offset.X);
                    Assert.AreEqual(offset.y, t.Offset.Y);
                    Assert.AreEqual(scale.x, t.Scale.X);
                    Assert.AreEqual(scale.y, t.Scale.Y);
                }
                break;
                }
            }
        }
Ejemplo n.º 6
0
 public static ShaderProperty GetRootAsShaderProperty(ByteBuffer _bb, ShaderProperty obj)
 {
     return(obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb));
 }
Ejemplo n.º 7
0
        public void EqualSource()
        {
            Assert.AreEqual(material.Name, originMaterial.name);
            Assert.AreEqual(material.Shader, originMaterial.shader.name);
            for (int i = 0; i < material.PropertiesLength; i++)
            {
                Schema.ShaderProperty p = material.GetProperties(i);

                Assert.IsTrue(originMaterial.HasProperty(p.Names));

                switch (p.Type)
                {
                case ShaderPropertyType.Float:
                case ShaderPropertyType.Range:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyFloat);

                    float originValue     = originMaterial.GetFloat(p.Names);
                    ShaderPropertyFloat f = p.GetValue <ShaderPropertyFloat>(new ShaderPropertyFloat());
                    Assert.AreEqual(f.Value, originValue);
                }
                break;

                case ShaderPropertyType.Color:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyColor);

                    UnityEngine.Color   originValue = originMaterial.GetColor(p.Names);
                    ShaderPropertyColor c           = p.GetValue <ShaderPropertyColor>(new ShaderPropertyColor());
                    Assert.AreEqual(originValue.a, c.Color.A);
                    Assert.AreEqual(originValue.g, c.Color.G);
                    Assert.AreEqual(originValue.b, c.Color.B);
                    Assert.AreEqual(originValue.r, c.Color.R);
                }
                break;

                case ShaderPropertyType.Vector:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyVector);

                    UnityEngine.Vector4  originValue = originMaterial.GetVector(p.Names);
                    ShaderPropertyVector v           = p.GetValue <ShaderPropertyVector>(new ShaderPropertyVector());
                    Assert.AreEqual(originValue.x, v.Vector.X);
                    Assert.AreEqual(originValue.y, v.Vector.Y);
                    Assert.AreEqual(originValue.z, v.Vector.Z);
                    Assert.AreEqual(originValue.w, v.Vector.W);
                }
                break;

                case ShaderPropertyType.TexEnv:
                {
                    Assert.AreEqual(p.ValueType, ShaderPropertyValue.ShaderPropertyTexture);
                    UnityEngine.Texture texture = originMaterial.GetTexture(p.Names);
                    Vector2             offset  = originMaterial.GetTextureOffset(p.Names);
                    Vector2             scale   = originMaterial.GetTextureScale(p.Names);

                    Assert.IsFalse(texture == null);
                    ShaderPropertyTexture t = p.GetValue <ShaderPropertyTexture>(new ShaderPropertyTexture());

                    Assert.AreEqual(texture.name, t.Name);
                    Assert.AreEqual(offset.x, t.Offset.X);
                    Assert.AreEqual(offset.y, t.Offset.Y);
                    Assert.AreEqual(scale.x, t.Scale.X);
                    Assert.AreEqual(scale.y, t.Scale.Y);
                }
                break;
                }
            }
        }