public void load(PGraphics g, string path) { this.path = path; if (path.StartsWith("http://") || path.StartsWith("file://")) { StartCoroutine("loadFromURL", path); PGraphics.debuglog("loadImage:loadFromURL " + path); } else { if (!loadFromResources(g, path)) { loadFromLocalFile(path); } } }
bool loadFromLocalFile(string path) { if (!File.Exists(path)) { PGraphics.debuglogWaring("loadImage:loadFromLocalFile <NotFound> " + path);; return(false); } byte[] bytes = null; FileStream fs = new FileStream(path, FileMode.Open); using (BinaryReader bin = new BinaryReader(fs)) { bytes = bin.ReadBytes((int)bin.BaseStream.Length); } Texture2D tex = new Texture2D(0, 0); tex.LoadImage(bytes); set(tex); if (tex != null) { PGraphics.debuglog("loadImage:loadFromLocalFile " + path); if (width == 0) { width = texWidth; } if (height == 0) { height = texHeight; } } else { PGraphics.debuglogWaring("loadImage:loadFromLocalFile <Failed> " + path); } return(tex != null); }
bool loadFromResources(PGraphics g, string path) { string resPath = g.getResourceName(path); Texture2D tex = Resources.Load(resPath) as Texture2D; set(tex); if (tex != null) { PGraphics.debuglog("loadImage:loadFromResources " + resPath); if (width == 0) { width = texWidth; } if (height == 0) { height = texHeight; } } else { PGraphics.debuglogWaring("loadImage:loadFromResources <Failed> " + resPath); } return(tex != null); }