Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// メニューファイルを読み込む
        /// </summary>
        /// <returns></returns>
        bool loadMenu()
        {
            nodes = new Dictionary<string, int>();
            foreach (var nodekey in Params.Nodenames.Keys)
            {
                if (menuFile.delNodes.Contains(nodekey))
                {
                    nodes.Add(nodekey, 1);
                }
                else if (menuFile.showNodes.Contains(nodekey))
                {
                    nodes.Add(nodekey, 2);
                }
                else
                {
                    nodes.Add(nodekey, 0);
                }
            }
            masks = new Dictionary<string, bool>();
            foreach (var slotkey in Params.Slotnames.Keys)
            {
                if (menuFile.maskItems.Contains(slotkey))
                {
                    masks.Add(slotkey, true);
                }
                else
                {
                    masks.Add(slotkey, false);
                }
            }

            addItems = new List<ModelFile>();
            foreach (var target in menuFile.addItems)
            {
                if (Params.Slotnames.Keys.Contains(target[1]))
                {
                    ModelFile model = new ModelFile();
                    if (model.LoadFile(target[0]))
                    {
                        model.category = menuFile.category;
                        model.slotname = target[1];
                        if (Params.AttachPoints.ContainsKey(target[1]))
                        {
                            //手持ちアイテム
                            model.addItemType = ModelFile.AddItemType.handItem;
                            model.attachSlot = MenuFile.AttachBoneString;
                            model.attachName = Params.AttachPoints[target[1]];
                        }
                        else if (target.Length == 4 && target[2] == MenuFile.AttachBoneString)
                        {
                            //ボーンにアタッチ
                            model.addItemType = ModelFile.AddItemType.attachBone;
                            model.attachSlot = MenuFile.AttachBoneString;
                            model.attachName = target[3];
                        }
                        else if (target.Length == 5 && target[2] == MenuFile.AttachString)
                        {
                            //アタッチ
                            model.addItemType = ModelFile.AddItemType.attach;
                            model.attachSlot = target[3];
                            model.attachName = target[4];
                        }
                        addItems.Add(model);
                    }
                }
            }

            mateFiles = new List<MateFile>();
            foreach (var target in menuFile.materials)
            {
                if (Params.Slotnames.Keys.Contains(target[0]))
                {
                    int matno;
                    if (int.TryParse(target[1], out matno))
                    {
                        MateFile mate = new MateFile();
                        if (mate.LoadFile(target[2]))
                        {
                            mate.matno = matno;
                            mate.category = menuFile.category;
                            mate.slotname = target[0];
                            mateFiles.Add(mate);
                        }
                    }
                }
            }

            resourceFiles = new List<MenuFile>();
            foreach (var target in menuFile.resources)
            {
                MenuFile menu = new MenuFile();
                if (menu.LoadFile(target[1]))
                {
                    menu.resourceName = target[0];
                    resourceFiles.Add(menu);
                }
            }


            delItems = new Dictionary<string, bool>();
            foreach (var slot in Params.Slotnames.Keys)
            {
                // 削除アイテムのチェック
                bool exists = false;
                foreach (var target in menuFile.items)
                {
                    if (target.Contains(slot) && target.Contains("_del"))
                    {
                        exists = true;
                        break;
                    }
                }
                delItems.Add(slot, exists);
            }
            scrollPos = Vector2.zero;
            wearMpnsCombo.SelectedItemIndex = 0;
            foreach (var category in wearMpns)
            {
                if (category.text == menuFile.category)
                {
                    break;
                }
                wearMpnsCombo.SelectedItemIndex++;
            }
            return true;
        }