1. 程式人生 > >Unity 讀取檔案

Unity 讀取檔案

UIPrefab.bytes 

Name,AssetBundleName,AssetNames 1.png,picture,Assets/Resources/1.png 2.png,picture,Assets/Resources/2.png

 Bytes.cs

public class Bytes {     static Bytes b;     public List<string> m_ArrayData;

    public static Bytes GetInstance()     {         if (b == null)         {             b = new Bytes();         }         return b;     }

    private Bytes() { m_ArrayData = new List<string>(); }

    public string GetInfo(string config, string name, PackVo.Column get)     {         m_ArrayData.Clear();

        string line;         string[] arr = null;         StreamReader sr = null;         sr = File.OpenText(Application.dataPath + "/Resources/Config/" + config);

        while ((line = sr.ReadLine()) != null)         {             arr = line.Split(new char[] { ',', ',' });             if (arr[0] == name) break;         }         sr.Close();         sr.Dispose();         return arr[0] == name ? arr[(int)get] : "";     } }

public class PackVo {     public const string UI = "UIPrefab.bytes";

    public enum Column     {         Name = 0,         AssetBundleName = 1,         AssetNames = 2     } }

應用

Debug.Log(Bytes.GetInstance().GetInfo(PackVo.UI,"1.png",PackVo.Column.AssetNames));