/// <summary> /// Read a PNG file from the specified location. Expects a full path with extension. /// </summary> static public Texture2D ReadPNG(string path, Texture2D existing = null) { Texture2D tex = null; byte[] bytes = Tools.ReadFile(path); if (bytes != null) { tex = existing ?? new Texture2D(2, 2); if (tex.LoadImage(bytes)) { tex.wrapMode = path.Contains("Repeat") ? TextureWrapMode.Repeat : TextureWrapMode.Clamp; tex.filterMode = FilterMode.Trilinear; tex.anisoLevel = 4; tex.Apply(); return(tex); } if (existing == null) { if (Application.isPlaying) { Object.Destroy(tex); } else { Object.DestroyImmediate(tex); } } } return(null); }
/// <summary> /// Load the specified file. /// </summary> public byte[] LoadFile(string fileName) { byte[] data; if (!mSavedFiles.TryGetValue(fileName, out data)) { data = Tools.ReadFile(fileName); mSavedFiles[fileName] = data; } return(data); }
/// <summary> /// Load the specified file. /// </summary> public byte[] LoadFile(string fileName) { byte[] data; if (!mSavedFiles.TryGetValue(fileName, out data)) { data = Tools.ReadFile(string.IsNullOrEmpty(rootDirectory) ? fileName : Path.Combine(rootDirectory, fileName)); mSavedFiles[fileName] = data; } return(data); }
/// <summary> /// Read the following file as text and return the contents. /// </summary> static public string ReadTextFile(string path) { byte[] bytes = Tools.ReadFile(path); if (bytes != null) { MemoryStream ms = new MemoryStream(bytes); StreamReader sr = new StreamReader(ms); string s = sr.ReadToEnd(); sr.Dispose(); return(s); } return(null); }
/// <summary> /// Read the node hierarchy from the specified file. /// </summary> static public DataNode Read(string path, bool allowConfigAccess = false) { return(Read(Tools.ReadFile(path, allowConfigAccess))); }