Exemple #1
0
 public static unsafe bool LoadSpr(string filename, ref List <Texture2D> SprResList)
 {
     byte[] filedata;
     if (!OpenFile(filename, out filedata))
     {
         try
         {
             int size = CoreWrapper.GetFileSize(GLB.GBK.GetBytes(filename));
             Debug.Log("Loading " + filename);
             //Debug.Log("Size " + size);
             if (size <= 0)
             {
                 return(false);
             }
             IntPtr read = CoreWrapper.LoadFile(GLB.GBK.GetBytes(filename));
             filedata = new byte[size];
             Marshal.Copy(read, filedata, 0, size);
         }
         catch (Exception e)
         {
             Debug.Log(e);
         }
     }
     if (filedata == null)
     {
         Debug.LogError("Load Image Error: " + filename);
         return(false);
     }
     if (filename.IndexOf(".spr") > 0)
     {
         return(LoadSpr(filename, filedata, ref SprResList));
     }
     else
     {
         //Debug.LogError("Load Image" + filename);
         Texture2D tx = new Texture2D(1, 1);
         tx.LoadImage(filedata);
         SprResList.Add(tx);
         return(true);
     }
 }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        string file = @"\UImage\第三版\ib系统\ib系统_底图.spr";

        CoreWrapper.InitFile();
        int size = CoreWrapper.GetFileSize(GLB.GBK.GetBytes(file));

        Debug.Log("size = " + size);
        byte[] data = new byte[size];
        //int read = CoreWrapper.LoadFile2(GLB.GBK.GetBytes(file), ref data, size);
        IntPtr read = CoreWrapper.LoadFile(GLB.GBK.GetBytes(file));

        Marshal.Copy(read, data, 0, size);
        Debug.Log(read);

        sr = gameObject.GetComponent <SpriteRenderer>();
        //Sprite sp = sr.sprite;
        //Color32[] colors1 = sp.texture.GetPixels32();
        //Debug.Log(colors1);


        //Color32[] colors = new Color32[100 * 100];
        //for (int i = 0; i < 100 * 100; i++)
        //{
        //    byte c = (byte)i;
        //    colors[i] = new Color32(c, c, c, c);
        //}
        //Texture2D tx = new Texture2D(100, 100);
        //tx.SetPixels32(colors);
        //Sprite newsp = Sprite.Create(tx, new Rect(0f, 0f, 100f, 100f), new Vector2(0.5f, 0.5f));

        Texture2D tx    = SprMgr.GetInstance().LoadSpr(sprPath, 0);
        Sprite    newsp = Sprite.Create(tx, new Rect(0f, 0f, tx.width, tx.height), new Vector2(0f, 1f));

        sr.sprite = newsp;
        sr.flipY  = true;
        //transform.localPosition -= new Vector3(tx.width / 200, tx.height / 200, 0f);
    }