Example #1
0
 public static void GetTextureFromFile(string u, FileInfo f, Action <Texture2D> callback)
 {
     if (f == null)
     {
         callback(null);
     }
     else
     {
         if (f.Name.Is(FileType.Asset))
         {
             GetAssetFromFile <Texture2D>(f, callback);
         }
         else
         {
             string texPath = f.FullName;
             var    texData = TexData.Load(texPath);
             var    tex     = new Texture2D(4, 4, TextureFormatEx.Get(u), texData.mipmap, texData.linear);
             tex.wrapMode   = texData.wrapMode;
             tex.filterMode = texData.filterMode;
             bool success = tex.LoadImage(File.ReadAllBytes(texPath), true);
             if (success)
             {
                 if (texData.crunch)
                 {
                     tex.Compress(true);
                 }
             }
             else
             {
                 log.Warn("Can't load textures {0}", u);
             }
             callback(tex);
         }
     }
 }
Example #2
0
        public static void Save(string texPath, TexData data)
        {
#if !UNITY_WEBGL
            string path = GetPath(texPath);
            Stream s    = new FileStream(path, FileMode.Create, FileAccess.Write);
            data.Write(s);
            s.Close();
#endif
        }
Example #3
0
        public static TexData Load(string texPath)
        {
            TexData data = new TexData();

#if !UNITY_WEBGL
            string path = GetPath(texPath);
            if (File.Exists(path))
            {
                Stream s = new FileStream(path, FileMode.Open, FileAccess.Read);
                data.Read(s);
                s.Close();
            }
            else
            {
                // default value
                data.mipmap     = false;
                data.filterMode = FilterMode.Bilinear;
                data.wrapMode   = TextureWrapMode.Clamp;
                data.linear     = false;
                data.crunch     = false;
            }
#endif
            return(data);
        }