Ejemplo n.º 1
0
        public bool LoadFile(string filename)
        {
            if (String.IsNullOrEmpty(Path.GetExtension(filename)) || Path.GetExtension(filename) != Params.ExtentionOfPmat)
            {
                filename += Params.ExtentionOfPmat;
            }
            basePmatFile = new PmatFile();
            this.filename = Path.GetFileNameWithoutExtension(filename);
            basePmatFile.filename = Path.GetFileNameWithoutExtension(filename);

            byte[] cd = null;
            try
            {
                using (AFileBase aFileBase = global::GameUty.FileOpen(filename))
                {
                    if (!aFileBase.IsValid())
                    {
                        logger.DebugLog("pmatファイルが見つかりません。", filename);
                        return false;
                    }
                    cd = aFileBase.ReadAll();
                }
            }
            catch (Exception ex2)
            {
                logger.ErrorLog("pmatファイルが見つかりません。", filename, ex2.Message);
                return false;
            }
            try
            {
                using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8))
                {
                    string header = binaryReader.ReadString();
                    if (header != pmatHeaderString)
                    {
                        logger.ErrorLog("例外: ヘッダーファイルが不正です。" + header);
                        return false;
                    }
                    version = binaryReader.ReadInt32();
                    basePmatFile.version = version;
                    int hashKey = binaryReader.ReadInt32();
                    name = binaryReader.ReadString();
                    basePmatFile.name = name;
                    value = binaryReader.ReadSingle();
                    basePmatFile.value = value;
                    shader = binaryReader.ReadString();
                    basePmatFile.shader = shader;
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        public bool LoadFile(string filename)
        {
            if (String.IsNullOrEmpty(Path.GetExtension(filename)) || Path.GetExtension(filename) != Params.ExtentionOfMate)
            {
                filename += Params.ExtentionOfMate;
            }
            baseMateFile = new MateFile();
            this.filename = Path.GetFileNameWithoutExtension(filename);
            baseMateFile.filename = Path.GetFileNameWithoutExtension(filename);
            byte[] cd = null;
            try
            {
                using (AFileBase aFileBase = global::GameUty.FileOpen(filename))
                {
                    if (!aFileBase.IsValid())
                    {
                        logger.ErrorLog("マテリアルファイルが見つかりません。", filename);
                        return false;
                    }
                    cd = aFileBase.ReadAll();
                }
            }
            catch (Exception ex2)
            {
                logger.ErrorLog("マテリアルファイルが読み込めませんでした。", filename, ex2.Message);
                return false;
            }

            using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8))
            {
                string text = binaryReader.ReadString();
                if (text != materialHeaderString)
                {
                    logger.ErrorLog("例外: ヘッダーファイルが不正です。" + text);
                    return false;
                }
                version = binaryReader.ReadInt32();
                baseMateFile.version = version;
                name = binaryReader.ReadString();
                baseMateFile.name = name;
                string pmat = binaryReader.ReadString();
                pmatFile = new PmatFile();
                pmatFile.LoadFile(pmat);
                shader1 = binaryReader.ReadString();
                baseMateFile.shader1 = shader1;
                shader2 = binaryReader.ReadString();
                baseMateFile.shader2 = shader2;

                while (true)
                {
                    string key = binaryReader.ReadString();
                    if (key == "end")
                    {
                        break;
                    }

                    string propertyName = binaryReader.ReadString();
                    if (key == "tex")
                    {
                        TexParams tex = new TexParams();
                        tex.mateFile = this;
                        tex.propertyName = propertyName;
                        tex.type = binaryReader.ReadString();
                        if (tex.type == "null")
                        {
                        }
                        else if (tex.type == TexParams.TexTypeTex2d)
                        {
                            tex.filename = binaryReader.ReadString();
                            tex.assets = binaryReader.ReadString();

                            Vector2 offset;
                            offset.x = binaryReader.ReadSingle();
                            offset.y = binaryReader.ReadSingle();
                            tex.offset = offset;

                            Vector2 scale;
                            scale.x = binaryReader.ReadSingle();
                            scale.y = binaryReader.ReadSingle();
                            tex.scale = scale;

                            tex.texFile = new TexFile();
                            tex.texFile.LoadFile(tex.filename);
                        }
                        else if (tex.type == TexParams.TexTypeTexRT)
                        {
                            tex.text7 = binaryReader.ReadString();
                            tex.text8 = binaryReader.ReadString();
                        }
                        if (texs == null)
                        {
                            texs = new Dictionary<string, TexParams>();
                        }
                        else if (texs.ContainsKey(propertyName))
                        {
                            continue;
                        }
                        texs.Add(propertyName, tex);
                    }
                    else if (key == "col")
                    {
                        Color color;
                        color.r = binaryReader.ReadSingle();
                        color.g = binaryReader.ReadSingle();
                        color.b = binaryReader.ReadSingle();
                        color.a = binaryReader.ReadSingle();
                        if (colors == null)
                        {
                            colors = new Dictionary<string, Color>();
                        }
                        else if (colors.ContainsKey(propertyName))
                        {
                            continue;
                        }
                        colors.Add(propertyName, color);
                    }
                    else if (key == "vec")
                    {
                        Vector4 vector;
                        vector.x = binaryReader.ReadSingle();
                        vector.y = binaryReader.ReadSingle();
                        vector.z = binaryReader.ReadSingle();
                        vector.w = binaryReader.ReadSingle();
                        if (vecs == null)
                        {
                            vecs = new Dictionary<string, Vector4>();
                        }
                        else if (vecs.ContainsKey(propertyName))
                        {
                            continue;
                        }
                        vecs.Add(propertyName, vector);
                    }
                    else if (key == "f")
                    {
                        float value = binaryReader.ReadSingle();
                        if (parameters == null)
                        {
                            parameters = new Dictionary<string, float>();
                        }
                        else if (parameters.ContainsKey(propertyName))
                        {
                            continue;
                        }
                        parameters.Add(propertyName, value);
                    }
                    else
                    {
                        logger.ErrorLog("マテリアルが読み込めません。不正なマテリアルプロパティ型です ", key);
                        return false;
                    }

                }
            }
            return true;
        }