コード例 #1
0
 // Token: 0x060001A5 RID: 421 RVA: 0x0000FC7C File Offset: 0x0000DE7C
 public bool Write(ACCMaterial target, string mateText, int apply)
 {
     using (StringReader stringReader = new StringReader(mateText))
     {
         FileUtilEx instance = FileUtilEx.Instance;
         stringReader.ReadLine();
         Material material = target.material;
         stringReader.ReadLine();
         stringReader.ReadLine();
         string text = stringReader.ReadLine();
         stringReader.ReadLine();
         if ((apply & MateHandler.MATE_SHADER) > 0 && material.shader.name != text)
         {
             target.ChangeShader(text, -1);
         }
         ShaderType    type  = target.type;
         string        text2 = stringReader.ReadLine();
         List <string> list  = new List <string>();
         while (text2 != null)
         {
             if (text2.Length != 0 && text2[0] != '\t')
             {
                 list.Clear();
                 string text3 = text2.Trim();
                 while ((text2 = stringReader.ReadLine()) != null)
                 {
                     if (text2.Length != 0)
                     {
                         if (text2[0] != '\t')
                         {
                             break;
                         }
                         string text4 = text2.Trim();
                         if (text4.Length > 0)
                         {
                             list.Add(text4);
                         }
                     }
                 }
                 string a;
                 if (list.Count != 0 && (a = text3) != null)
                 {
                     if (!(a == "tex"))
                     {
                         if (!(a == "col") && !(a == "vec"))
                         {
                             if (a == "f")
                             {
                                 if ((apply & MateHandler.MATE_FLOAT) > 0 && list.Count >= 2)
                                 {
                                     string     text5      = list[0];
                                     ShaderProp shaderProp = type.GetShaderProp(text5);
                                     float      value;
                                     if (shaderProp == null)
                                     {
                                         LogUtil.Log(new object[]
                                         {
                                             "シェーダに対応していないプロパティのためスキップします.propName=",
                                             text5
                                         });
                                     }
                                     else if (!float.TryParse(list[1], out value))
                                     {
                                         LogUtil.Log(new object[]
                                         {
                                             "指定文字列はfloatに変換できません。スキップします。propName={0}, text={1}",
                                             text5,
                                             list[1]
                                         });
                                     }
                                     else
                                     {
                                         material.SetFloat(shaderProp.propId, value);
                                         LogUtil.DebugF("float set({0})", new object[]
                                         {
                                             text5
                                         });
                                     }
                                 }
                             }
                         }
                         else if ((apply & MateHandler.MATE_COLOR) > 0 && list.Count >= 2)
                         {
                             string     text6       = list[0];
                             ShaderProp shaderProp2 = type.GetShaderProp(text6);
                             if (shaderProp2 == null)
                             {
                                 LogUtil.Log(new object[]
                                 {
                                     "シェーダに対応していないプロパティのためスキップします.propName=",
                                     text6
                                 });
                             }
                             else
                             {
                                 float[] array = this.ParseVals(list[1], text6, 4);
                                 if (array != null)
                                 {
                                     Color value2 = new Color(array[0], array[1], array[2], array[3]);
                                     material.SetColor(shaderProp2.propId, value2);
                                     LogUtil.DebugF("color set ({0})", new object[]
                                     {
                                         text6
                                     });
                                 }
                             }
                         }
                     }
                     else if ((apply & MateHandler.MATE_TEX) > 0)
                     {
                         if (list.Count == 2)
                         {
                             if (list[1] == "null")
                             {
                                 material.SetTexture(list[0], null);
                             }
                         }
                         else if (list.Count < 5)
                         {
                             string text7 = string.Empty;
                             if (list.Count >= 1)
                             {
                                 text7 = "propName=" + list[0];
                             }
                             LogUtil.Log(new object[]
                             {
                                 "指定パラメータが不足しているためtexの適用をスキップします.",
                                 text7
                             });
                         }
                         else
                         {
                             string     text8       = list[0];
                             string     text9       = list[2];
                             ShaderProp shaderProp3 = type.GetShaderProp(text8);
                             if (shaderProp3 == null)
                             {
                                 LogUtil.Log(new object[]
                                 {
                                     "シェーダに対応していないプロパティのためスキップします.propName=",
                                     text8
                                 });
                             }
                             else
                             {
                                 Texture texture = material.GetTexture(shaderProp3.propId);
                                 if (texture == null || texture.name != text9)
                                 {
                                     if (!text9.ToLower().EndsWith(FileConst.EXT_TEXTURE, StringComparison.Ordinal))
                                     {
                                         text9 += FileConst.EXT_TEXTURE;
                                     }
                                     if (!instance.Exists(text9))
                                     {
                                         LogUtil.LogF("tex({0}) not found. (propName={1})", new object[]
                                         {
                                             text9,
                                             text8
                                         });
                                         continue;
                                     }
                                     Texture2D value3 = instance.LoadTexture(text9);
                                     material.SetTexture(shaderProp3.propId, value3);
                                 }
                                 float[] array2 = this.ParseVals(list[4], text8, 4);
                                 if (array2 == null)
                                 {
                                     LogUtil.DebugF("tex({0}) prop is null", new object[]
                                     {
                                         text9
                                     });
                                 }
                                 else
                                 {
                                     material.SetTextureOffset(shaderProp3.propId, new Vector2(array2[0], array2[1]));
                                     material.SetTextureScale(shaderProp3.propId, new Vector2(array2[2], array2[3]));
                                     LogUtil.DebugF("tex({0}) loaded to {1}", new object[]
                                     {
                                         text9,
                                         shaderProp3.keyName
                                     });
                                 }
                             }
                         }
                     }
                 }
             }
             else
             {
                 text2 = stringReader.ReadLine();
             }
         }
     }
     return(true);
 }
コード例 #2
0
        public bool Write(ACCMaterial target, string mateText, int apply = MATE_ALL)
        {
            using (var sr = new StringReader(mateText)) {
                var outUtil = FileUtilEx.Instance;

                sr.ReadLine(); // version
                var mate = target.material;

                // TODO マテリアル名を変更か、あるいはマテリアル名に対応するRenderQueueを設定
                sr.ReadLine();              // name1
                sr.ReadLine();              // name2

                var shader = sr.ReadLine(); // shader1
                sr.ReadLine();              // shader2
                if ((apply & MATE_SHADER) > 0)
                {
                    if (mate.shader.name != shader)
                    {
                        target.ChangeShader(shader);
                    }
                }
                var shaderType = target.type;

                // シェーダに対応していないプロパティはスルー
                //

                // ヘッダ部分は読み捨て
                for (int i = 0; i < 5; i++)
                {
                    sr.ReadLine();
                }

                var line = sr.ReadLine();
                var work = new List <string>();
                while (line != null)
                {
                    if (line.Length != 0 && line[0] != '\t')
                    {
                        work.Clear();
                        // 次のタイプまで読み込み
                        string type = line.Trim();
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Length == 0)
                            {
                                continue;
                            }
                            if (line[0] == '\t')
                            {
                                var val = line.Trim();
                                if (val.Length > 0)
                                {
                                    work.Add(val);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (work.Count == 0)
                        {
                            continue;
                        }

                        switch (type)
                        {
                        case "tex":
                            if ((apply & MATE_TEX) > 0)
                            {
                                if (work.Count == 2)
                                {
                                    if (work[1] == "null")
                                    {
                                        mate.SetTexture(work[0], null);
                                    }
                                    continue;
                                }
                                else if (work.Count < 5)
                                {
                                    string tmp = string.Empty;
                                    if (work.Count >= 1)
                                    {
                                        tmp = "propName=" + work[0];
                                    }
                                    LogUtil.Log("指定パラメータが不足しているためtexの適用をスキップします.", tmp);
                                    continue;
                                }
                                var propName1 = work[0];
                                var texName   = work[2];
                                var texKey    = shaderType.GetShaderProp(propName1);
                                if (texKey == null)
                                {
                                    LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName1);
                                    continue;
                                }
                                // tex名が同一の場合はは変更しない
                                var prevTex = mate.GetTexture(texKey.propId);
                                if (prevTex != null && prevTex.name == texName)
                                {
                                    continue;
                                }

                                var fvals = parseVals(work[4], propName1, 4);
                                if (fvals == null)
                                {
                                    continue;
                                }

                                if (!texName.ToLower().EndsWith(FileConst.EXT_TEXTURE, StringComparison.Ordinal))
                                {
                                    texName += FileConst.EXT_TEXTURE;
                                }

                                if (!outUtil.Exists(texName))
                                {
                                    LogUtil.LogF("tex({0}) not found. (propName={1})", texName, propName1);
                                    continue;
                                }
                                // テクスチャの適用
                                var tex2d = outUtil.LoadTexture(texName);
                                mate.SetTexture(texKey.propId, tex2d);
                                mate.SetTextureOffset(propName1, new UnityEngine.Vector2(fvals[0], fvals[1]));
                                mate.SetTextureScale(propName1, new UnityEngine.Vector2(fvals[2], fvals[3]));
                                LogUtil.DebugF("tex({0}) loaded to {1}", texName, propName1);
                            }
                            break;

                        case "col":
                        case "vec":
                            if ((apply & MATE_COLOR) > 0)
                            {
                                if (work.Count < 2)
                                {
                                    continue;
                                }

                                var propName2 = work[0];
                                var texKey2   = shaderType.GetShaderProp(propName2);
                                if (texKey2 == null)
                                {
                                    LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName2);
                                    continue;
                                }
                                var colVals = parseVals(work[1], propName2, 4);
                                if (colVals == null)
                                {
                                    continue;
                                }

                                var color = new Color(colVals[0], colVals[1], colVals[2], colVals[3]);
                                mate.SetColor(texKey2.propId, color);
                                LogUtil.DebugF("color set ({0})", propName2);
                            }
                            break;

                        case "f":
                            if ((apply & MATE_FLOAT) > 0)
                            {
                                if (work.Count < 2)
                                {
                                    continue;
                                }

                                var propName3 = work[0];
                                var texKey3   = shaderType.GetShaderProp(propName3);
                                if (texKey3 == null)
                                {
                                    LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName3);
                                    continue;
                                }
                                float fVal;
                                if (!float.TryParse(work[1], out fVal))
                                {
                                    LogUtil.Log("指定文字列はfloatに変換できません。スキップします。propName={0}, text={1}", propName3, work[1]);
                                    continue;
                                }

                                mate.SetFloat(texKey3.propId, fVal);
                                LogUtil.DebugF("float set({0})", propName3);
                            }
                            break;
                        }
                    }
                    else
                    {
                        line = sr.ReadLine();
                    }
                }
            }
            return(true);
        }
コード例 #3
0
        public bool Write(ACCMaterial target, string mateText, int apply=MATE_ALL) {
            using (var sr = new StringReader(mateText)) {
                var outUtil = FileUtilEx.Instance;
                
                sr.ReadLine(); // version
                var mate = target.material;
    
                // TODO マテリアル名を変更か、あるいはマテリアル名に対応するRenderQueueを設定
                sr.ReadLine(); // name1
                sr.ReadLine(); // name2
    
                var shader = sr.ReadLine(); // shader1
                sr.ReadLine(); // shader2
                if ((apply & MATE_SHADER) > 0) {
                    if (mate.shader.name != shader) {
                        target.ChangeShader(shader);
                    }
                }            
                var shaderType = target.type;

                // シェーダに対応していないプロパティはスルー
                // 
                
                // ヘッダ部分は読み捨て
                for (int i = 0; i < 5; i++) sr.ReadLine(); 
                
                var line = sr.ReadLine();
                var work = new List<string>();
                while (line != null) {
                    if (line.Length != 0 && line[0] != '\t') {
                        work.Clear();
                        // 次のタイプまで読み込み
                        string type = line.Trim();
                        while ((line = sr.ReadLine()) != null) {
                            if (line.Length == 0)
                                continue;
                            if (line[0] == '\t') {
                                var val = line.Trim();
                                if (val.Length > 0)
                                    work.Add(val);
                                
                            } else {
                                break;
                            }
                        }
                        if (work.Count == 0)
                            continue;
                        
                        switch (type) {
                            case "tex":
                                if ((apply & MATE_TEX) > 0) {
                                    if (work.Count == 2) {
                                        if (work[1] == "null") {
                                            mate.SetTexture(work[0], null);
                                        }
                                        continue;
                                        
                                    } else if (work.Count < 5)  {
                                        string tmp = string.Empty;
                                        if (work.Count >= 1) {
                                            tmp = "propName="+work[0];
                                        }
                                        LogUtil.Log("指定パラメータが不足しているためtexの適用をスキップします.", tmp);
                                        continue;
                                    }
                                    var propName1 = work[0];
                                    var texName  = work[2];
                                    var texKey = shaderType.GetShaderProp(propName1);
                                    if (texKey == null) {
                                        LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName1);
                                        continue;
                                    }
                                    // tex名が同一の場合はは変更しない
                                    var prevTex = mate.GetTexture(texKey.propId);
                                    if (prevTex != null && prevTex.name == texName) continue;
                                    
                                    var fvals = parseVals(work[4], propName1, 4);
                                    if (fvals == null) continue;
                                    
                                    if (!texName.ToLower().EndsWith(FileConst.EXT_TEXTURE, StringComparison.Ordinal)) {
                                        texName += FileConst.EXT_TEXTURE;
                                    }
                                    
                                    if (!outUtil.Exists(texName)) {
                                        LogUtil.LogF("tex({0}) not found. (propName={1})", texName, propName1);
                                        continue;
                                    }
                                    // テクスチャの適用
                                    var tex2d = outUtil.LoadTexture(texName);
                                    mate.SetTexture(texKey.propId, tex2d);
                                    mate.SetTextureOffset(propName1, new UnityEngine.Vector2(fvals[0], fvals[1]));
                                    mate.SetTextureScale(propName1, new UnityEngine.Vector2(fvals[2], fvals[3]));
                                    LogUtil.DebugF("tex({0}) loaded to {1}", texName, propName1);
                                }
                                break;
    
                            case "col":
                            case "vec":
                                if ((apply & MATE_COLOR) > 0) {
                                    if (work.Count < 2)
                                        continue;
        
                                    var propName2 = work[0];
                                    var texKey2 = shaderType.GetShaderProp(propName2);
                                    if (texKey2 == null) {
                                        LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName2);
                                        continue;
                                    }
                                    var colVals = parseVals(work[1], propName2, 4);
                                    if (colVals == null)
                                        continue;
                                    
                                    var color = new Color(colVals[0], colVals[1], colVals[2], colVals[3]);
                                    mate.SetColor(texKey2.propId, color);
                                    LogUtil.DebugF("color set ({0})", propName2);
                                }
                                break;
                                
                            case "f":
                                if ((apply & MATE_FLOAT) > 0) {
                                    if (work.Count < 2)
                                        continue;
        
                                    var propName3 = work[0];
                                    var texKey3 = shaderType.GetShaderProp(propName3);
                                    if (texKey3 == null) {
                                        LogUtil.Log("シェーダに対応していないプロパティのためスキップします.propName=", propName3);
                                        continue;
                                    }
                                    float fVal;
                                    if (!float.TryParse(work[1], out fVal)) {
                                        LogUtil.Log("指定文字列はfloatに変換できません。スキップします。propName={0}, text={1}", propName3, work[1]);
                                        continue;
                                    }
                                    
                                    mate.SetFloat(texKey3.propId, fVal);
                                    LogUtil.DebugF("float set({0})", propName3);
                                }
                                break;
                        }
                        
                    } else {
                        line = sr.ReadLine();
                    }
                }
            }
            return true;
        }