Пример #1
0
        public bool LoadFile(string filename)
        {
            reset();
            if (String.IsNullOrEmpty(Path.GetExtension(filename)) || Path.GetExtension(filename) != Params.ExtentionOfMenu)
            {
                filename += Params.ExtentionOfMenu;
            }
            this.baseMenuFile = new MenuFile();
            this.filename = Path.GetFileNameWithoutExtension(filename);
            this.baseMenuFile.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;
            }
            try
            {
                using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8))
                {
                    string text = binaryReader.ReadString();
                    if (text != menuHeaderString)
                    {
                        logger.ErrorLog("例外: ヘッダーファイルが不正です。" + text);
                        return false;
                    }
                    version = binaryReader.ReadInt32();

                    assetPath = binaryReader.ReadString();

                    headerName = binaryReader.ReadString();

                    headerCategory = binaryReader.ReadString();

                    headerSetumei = binaryReader.ReadString().Replace(Params.ReturnString, "\n");

                    int num2 = (int)binaryReader.ReadInt32();
                    while (true)
                    {
                        byte b = binaryReader.ReadByte();
                        int size = (int)b;
                        if (size == 0)
                        {
                            break;
                        }
                        string[] param = new string[size];
                        for (int i = 0; i < size; i++)
                        {
                            param[i] = binaryReader.ReadString();
                        }
                        string[] p1 = new string[size - 1];
                        string[] p2 = new string[size - 1];
                        for (int i = 0; i < size - 1; i++)
                        {
                            p1[i] = param[i + 1];
                            p2[i] = param[i + 1];
                        }
                        switch (param[0])
                        {
                            case menuFolderString:
                                baseMenuFile.menuFolder = param[1];
                                menuFolder = param[1];
                                break;
                            case categoryString:
                                baseMenuFile.category = param[1].ToLower();
                                category = param[1].ToLower();
                                break;
                            case catnoString:
                                baseMenuFile.catno = param[1];
                                catno = param[1];
                                break;
                            case addAttributeString:
                                baseMenuFile.addAttributes.Add(p1);
                                addAttributes.Add(p2);
                                break;
                            case priorityString:
                                baseMenuFile.priority = param[1];
                                priority = param[1];
                                break;
                            case nameString:
                                baseMenuFile.name = param[1];
                                name = param[1];
                                break;
                            case setumeiString:
                                baseMenuFile.setumei = param[1].Replace(Params.ReturnString, "\n");
                                setumei = param[1].Replace(Params.ReturnString, "\n");
                                break;
                            case iconsString:
                                baseMenuFile.icons = param[1];
                                icons = param[1];
                                iconFile = new TexFile();
                                iconFile.LoadFile(icons);
                                baseMenuFile.iconFile = new TexFile();
                                baseMenuFile.iconFile.LoadFile(icons);
                                break;
                            case itemParameterString:
                                baseMenuFile.itemParams.Add(p1);
                                itemParams.Add(p2);
                                break;
                            case itemString:
                                baseMenuFile.items.Add(param[1]);
                                items.Add(param[1]);
                                break;
                            case additemString:
                                baseMenuFile.addItems.Add(p1);
                                addItems.Add(p2);
                                break;
                            case maskitemString:
                                baseMenuFile.maskItems.Add(param[1]);
                                maskItems.Add(param[1]);
                                break;
                            case changeMaterialString:
                                baseMenuFile.materials.Add(p1);
                                materials.Add(p2);
                                break;
                            case delNodeString:
                                baseMenuFile.delNodes.Add(param[1]);
                                delNodes.Add(param[1]);
                                break;
                            case showNodeString:
                                baseMenuFile.showNodes.Add(param[1]);
                                showNodes.Add(param[1]);
                                break;
                            case delPartsNodeString:
                                baseMenuFile.delPartsNodes.Add(p1);
                                delPartsNodes.Add(p2);
                                break;
                            case showPartsNodeString:
                                baseMenuFile.showPartsNodes.Add(p1);
                                showPartsNodes.Add(p2);
                                break;
                            case resourceReferenceString:
                                baseMenuFile.resources.Add(p1);
                                resources.Add(p2);
                                break;
                            case texString:
                            case changeTextureString:
                                baseMenuFile.texs.Add(p1);
                                texs.Add(p2);
                                break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                return false;
            }
            return true;
        }
Пример #2
0
        public bool LoadFile(string filename)
        {
            if (String.IsNullOrEmpty(Path.GetExtension(filename)) || Path.GetExtension(filename) != Params.ExtentionOfTex)
            {
                filename += Params.ExtentionOfTex;
            }
            baseTexFile = new TexFile();
            this.filename = Path.GetFileNameWithoutExtension(filename);
            baseTexFile.filename = Path.GetFileNameWithoutExtension(filename);

            byte[] cd = null;
            try
            {
                using (AFileBase aFileBase = global::GameUty.FileOpen(filename))
                {
                    if (!aFileBase.IsValid())
                    {
                        logger.ErrorLog("texファイルが見つかりません。", filename);
                        return false;
                    }
                    cd = aFileBase.ReadAll();
                }
            }
            catch (Exception ex2)
            {
                logger.ErrorLog("texファイルが読み込めませんでした。", filename, ex2.Message);
                return false;
            }
            try
            {
                using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(cd), Encoding.UTF8))
                {
                    string header = binaryReader.ReadString();
                    if (header != texHeaderString)
                    {
                        logger.ErrorLog("例外: ヘッダーファイルが不正です。" + header);
                        return false;
                    }
                    version = binaryReader.ReadInt32();
                    assets = binaryReader.ReadString();
                    baseTexFile.assets = assets;
                    int size = binaryReader.ReadInt32();
                    byte[] data = new byte[Math.Max(500000, size)];
                    if (data.Length < size)
                    {
                        data = new byte[size];
                    }
                    binaryReader.Read(data, 0, size);
                    texture = new Texture2D(2, 2, TextureFormat.RGBA32, false);
                    texture.LoadImage(data);
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
                return false;
            }

            return true;
        }