Ejemplo n.º 1
0
    public void LoadTiles()
    {
        if (Loaded)
        {
            return;
        }


        TileList  = new List <TileListEntry>(270);
        Materials = new List <MaterialListEntry>(30);

        string[] files = System.IO.Directory.GetFiles(IO.GetCrashdayPath() + "/data/content/tiles/");

        for (int i = 0; i < files.Length; i++)
        {
            //read only cfl files in tiles folder
            if (files [i].Contains(".cfl"))
            {
                string name = files[i].Substring(files[i].LastIndexOf('/') + 1);

                //files[i] already contains crashday path, so we dont add it
                string[] cflFIle = System.IO.File.ReadAllLines(files[i]);

                //get model path from cfl file
                string pathToModel = cflFIle[2];
                pathToModel = IO.GetCrashdayPath() + "/data/content/models/" + IO.RemoveComment(pathToModel);

                //get the size of the model in tiles
                //the size is stored in form of (w h #some comment maybe)
                //so we just remove the coment and take the first and third char
                string sizeStr = cflFIle[3];
                sizeStr = IO.RemoveComment(sizeStr);
                IntVector2 size = new IntVector2(sizeStr[0] - '0', sizeStr[2] - '0');
                Texture    ic   = TGAParser.LoadTGA(IO.GetCrashdayPath() + "/data/content/textures/pictures/tiles/" + name.Split('.')[0] + ".tga");

                TileList.Add(new TileListEntry(name, pathToModel, ic, size));
            }
        }

        Loaded = true;
    }
Ejemplo n.º 2
0
    void Start()
    {
        // load tga
        TGAInfo tgaInfo = TGAParser.loadTGAData(File.ReadAllBytes("wtf.tga"));

        Texture2D texture = new Texture2D(1, 1);
        // 判断用哪种纹理格式
        TextureFormat format = texture.format;

        if (tgaInfo.bitDepth == 24)
        {
            format = TextureFormat.RGB24;
        }
        else if (tgaInfo.bitDepth == 32)
        {
            format = TextureFormat.ARGB32;
        }
        texture.Resize(tgaInfo.width, tgaInfo.height, format, false); // 主要为了设置一下format
        texture.SetPixels32(tgaInfo.data);
        texture.Apply();
    }