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