Unity(C#)获取Texture2D

获取Texture2D:

public Texture2D GetTexture2DFromPath(string path)

        {

            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            int byteLength = (int)fs.Length;

            byte[] imgBytes = new byte[byteLength];

            fs.Read(imgBytes, 0, byteLength);

            fs.Close();

            fs.Dispose();

            Texture2D tex = new Texture2D(0, 0);

            tex.LoadImage(imgBytes);

            tex.Apply();

            return tex;

        }

你可能感兴趣的:(unity,c#,游戏引擎)