public Texture2DOverrideData(Texture2D originalTexture2D, string texturepath, Texture2D overrideTexture2D) { if (texturepath != null) { this.texturepath = texturepath; } else { this.texturepath = string.Empty; } if (originalTexture2D != null) { this.instanceID = originalTexture2D.GetInstanceID(); this.originalname = originalTexture2D.name; } else { this.instanceID = 0; this.originalname = string.Empty; } this.originalTexture2D = originalTexture2D; if (overrideTexture2D != null) { this.overrideID = overrideTexture2D.GetInstanceID(); } else { this.overrideID = 0; } this.overrideTexture2D = overrideTexture2D; this.cacheID = 0; this.overrideTextureCache = null; }
protected Texture2D GetTexture() { if (base.GetType() != typeof(Sprite)) { return(null); } Texture2D textured = ((Sprite)this)._get_texture(); try { if (textured == null) { return(textured); } if (this.overrideData.OriginalTexture2D != null) { return(this.overrideData.OverrideTexture2D); } Texture2DOverride.LoadTexture2D(((Sprite)this).name, textured, out this.overrideData); if (this.overrideData.OverrideTexture2D != null) { textured = this.overrideData.OverrideTexture2D; } } catch (Exception exception) { IniSettings.Error("SpriteOverride:\n" + exception.ToString()); } return(textured); }
public static bool LoadTGA(Stream TGAStream, out U::UnityEngine.Texture2D texture) { bool flag; try { using (BinaryReader reader = new BinaryReader(TGAStream)) { Texture2D textured; reader.BaseStream.Seek(12L, SeekOrigin.Begin); short width = reader.ReadInt16(); short height = reader.ReadInt16(); int num3 = reader.ReadByte(); reader.BaseStream.Seek(1L, SeekOrigin.Current); Color32[] colors = new Color32[width * height]; if (num3 == 0x20) { textured = new Texture2D(width, height, TextureFormat.RGBA32, false); for (int i = 0; i < (width * height); i++) { byte b = reader.ReadByte(); byte g = reader.ReadByte(); byte r = reader.ReadByte(); byte a = reader.ReadByte(); colors[i] = new Color32(r, g, b, a); } } else { if (num3 != 0x18) { throw new Exception("TGA texture had non 32/24 bit depth."); } textured = new Texture2D(width, height, TextureFormat.RGB24, false); for (int j = 0; j < (width * height); j++) { byte num10 = reader.ReadByte(); byte num11 = reader.ReadByte(); byte num12 = reader.ReadByte(); colors[j] = new Color32(num12, num11, num10, 0xff); } } textured.SetPixels32(colors); textured.Apply(); texture = textured; flag = true; } } catch { texture = null; flag = false; } return(flag); }
public static bool LoadTGA(string fileName, out Texture2D texture) { bool flag; try { using (FileStream stream = File.OpenRead(fileName)) { flag = LoadTGA(stream, out texture); } } catch { texture = null; flag = false; } return(flag); }
private static bool LoadTextureData(string path, out U::UnityEngine.Texture2D texture2D) { bool flag; texture2D = null; try { path = string.Concat(Texture2DOverride.TranslationImageDir, path); string extension = Path.GetExtension(path); if (extension == ".dds") { flag = DXTLoader.LoadDXT(path, out texture2D); } else if (extension == ".jpeg" || extension == ".jpg") { texture2D = new Texture2D(2, 2, TextureFormat.RGB24, false); flag = texture2D.LoadImage(File.ReadAllBytes(path)); } else if (extension == ".png") { texture2D = new Texture2D(2, 2, TextureFormat.ARGB32, false); flag = texture2D.LoadImage(File.ReadAllBytes(path)); } else if (extension == ".psd") { flag = PSDLoader.LoadPSD(path, out texture2D); } else if (extension == ".tga") { flag = TGALoader.LoadTGA(path, out texture2D); } else { return(false); } } catch (Exception exception) { IniSettings.Error(string.Concat("LoadImage:\n", exception.ToString())); return(false); } return(flag); }
protected void Swap(ref Texture value) { if (base.GetType() == typeof(Material)) { try { if (value == null) { if (this.overrideData.OriginalTexture2D != null) { Texture2DOverride.UnloadTexture2D(ref this.overrideData); } } else { Texture2D textured = value as Texture2D; if (textured != null) { if (this.overrideData.OriginalTexture2D != null) { int instanceID = textured.GetInstanceID(); if ((this.overrideData.InstanceID == instanceID) || (this.overrideData.OverrideID == instanceID)) { value = this.overrideData.OverrideTexture2D; return; } Texture2DOverride.UnloadTexture2D(ref this.overrideData); } Texture2DOverride.LoadTexture2D(((Material)this).name, textured, out this.overrideData); if (this.overrideData.OverrideTexture2D != null) { value = this.overrideData.OverrideTexture2D; } } } } catch (Exception exception) { IniSettings.Error("MaterialOverride:\n" + exception.ToString()); } } }
private void SetOurOverrideTexture(ref U::UnityEngine.Texture value) { if (base.GetType() == typeof(RawImage)) { try { if (value == null) { if (this.overrideData.OriginalTexture2D != null) { Texture2DOverride.UnloadTexture2D(ref this.overrideData); } } else { U::UnityEngine.Texture2D textured = value as U::UnityEngine.Texture2D; if (textured != null) { if (this.overrideData.OriginalTexture2D != null) { int instanceID = textured.GetInstanceID(); if ((this.overrideData.InstanceID == instanceID) || (this.overrideData.OverrideID == instanceID)) { value = this.overrideData.OverrideTexture2D; return; } Texture2DOverride.UnloadTexture2D(ref this.overrideData); } Texture2DOverride.LoadTexture2D(((RawImage)this).name, textured, out this.overrideData); if (this.overrideData.OverrideTexture2D != null) { value = this.overrideData.OverrideTexture2D; } } } } catch (Exception exception) { IniSettings.Error("RawImageOverride:\n" + exception.ToString()); } } }
protected static void Swap(ref Texture2D texture) { try { if (texture == null) { if (overrideData.OriginalTexture2D != null) { Texture2DOverride.UnloadTexture2D(ref overrideData); } } else { if (overrideData.OriginalTexture2D != null) { int instanceID = texture.GetInstanceID(); if (overrideData.InstanceID == instanceID) { texture = overrideData.OverrideTextureCache; return; } Texture2DOverride.UnloadTexture2D(ref overrideData); } Texture2DOverride.LoadTexture2D(texture.name, texture, out overrideData); if (overrideData.OverrideTexture2D != null) { if ((texture.width != overrideData.OverrideTexture2D.width) || (texture.height != overrideData.OverrideTexture2D.height)) { texture.Resize(overrideData.OverrideTexture2D.width, overrideData.OverrideTexture2D.height); } texture.SetPixels32(overrideData.OverrideTexture2D.GetPixels32()); texture.Apply(); overrideData.OverrideTextureCache = texture; } } } catch (Exception exception) { IniSettings.Error("CursorOverride:\n" + exception.ToString()); } }
public static bool LoadDXT(byte[] ddsBytes, out Texture2D texture) { try { if (ddsBytes[4] != 0x7c) { throw new Exception("Invalid DDS DXTn texture. Unable to read"); } TextureFormat format = (TextureFormat)0; if (((ddsBytes[0x54] == 0x44) && (ddsBytes[0x55] == 0x58)) && (ddsBytes[0x56] == 0x54)) { if (ddsBytes[0x57] == 0x31) { format = TextureFormat.DXT1; } else if (ddsBytes[0x57] == 0x35) { format = TextureFormat.DXT5; } } if ((format != TextureFormat.DXT1) && (format != TextureFormat.DXT5)) { throw new Exception("Invalid TextureFormat. Only DXT1 and DXT5 formats are supported by this method."); } int height = (ddsBytes[13] * 0x100) + ddsBytes[12]; int width = (ddsBytes[0x11] * 0x100) + ddsBytes[0x10]; byte[] dst = new byte[ddsBytes.Length - 0x80]; Buffer.BlockCopy(ddsBytes, 0x80, dst, 0, ddsBytes.Length - 0x80); texture = new Texture2D(width, height, format, false); texture.LoadRawTextureData(dst); texture.Apply(); return(true); } catch { texture = null; return(false); } }
public static bool LoadPSD(byte[] psdBytes, out Texture2D texture) { bool flag; try { byte[] buffer; int index = 0; if (psdBytes == null) { throw new ArgumentNullException("psdBytes"); } byte[] bytes = Encoding.UTF8.GetBytes("8BPS"); if (psdBytes.Length < bytes.Length) { throw new ArgumentOutOfRangeException(); } for (int i = 0; i < bytes.Length; i++) { if (psdBytes[i] != bytes[i]) { throw new FormatException(); } } index = Read(psdBytes, bytes.Length, 2, out buffer, true); if (BitConverter.ToInt16(buffer, 0) != 1) { throw new FormatException(); } index += 6; index = Read(psdBytes, index, 2, out buffer, true); short num2 = BitConverter.ToInt16(buffer, 0); if ((num2 != 3) && (num2 != 4)) { throw new NotSupportedException(); } index = Read(psdBytes, index, 4, out buffer, true); int height = BitConverter.ToInt32(buffer, 0); index = Read(psdBytes, index, 4, out buffer, true); int width = BitConverter.ToInt32(buffer, 0); index = Read(psdBytes, index, 2, out buffer, true); if (BitConverter.ToInt16(buffer, 0) != 8) { throw new NotSupportedException(); } index = Read(psdBytes, index, 2, out buffer, true); short num5 = BitConverter.ToInt16(buffer, 0); index = Read(psdBytes, index, 4, out buffer, true); int num6 = BitConverter.ToInt32(buffer, 0); index += num6; index = Read(psdBytes, index, 4, out buffer, true); int num7 = BitConverter.ToInt32(buffer, 0); index += num7; index = Read(psdBytes, index, 4, out buffer, true); int num8 = BitConverter.ToInt32(buffer, 0); index += num8; index = Read(psdBytes, index, 2, out buffer, true); short num9 = BitConverter.ToInt16(buffer, 0); TextureFormat format = (TextureFormat)0; switch (num5) { case 0: throw new NotSupportedException(); case 1: throw new NotSupportedException(); case 2: throw new NotSupportedException(); case 3: format = TextureFormat.RGBA32; break; case 4: throw new NotSupportedException(); case 7: throw new NotSupportedException(); case 8: throw new NotSupportedException(); case 9: throw new NotSupportedException(); default: throw new NotSupportedException(); } switch (num9) { case 0: throw new NotSupportedException(); case 1: { short[] numArray = new short[num2 * height]; for (int j = 0; j < numArray.Length; j++) { index = Read(psdBytes, index, 2, out buffer, true); numArray[j] = BitConverter.ToInt16(buffer, 0); } int num11 = 0; int num12 = 0; Color32[] colors = new Color32[width * height]; for (int k = 0; k < numArray.Length; k++) { if (num11 == 4) { throw new NotSupportedException(); } index = Read(psdBytes, index, numArray[k], out buffer, false); for (int m = 0; m < buffer.Length; m++) { sbyte num16 = (sbyte)buffer[m]; if (num16 != -128) { if (num16 < 0) { m++; int num17 = 1 - num16; for (int n = 0; n < num17; n++) { Color32 color = colors[num12]; switch (num11) { case 0: color.a = 0xff; color.r = buffer[m]; break; case 1: color.g = buffer[m]; break; case 2: color.b = buffer[m]; break; case 3: color.a = buffer[m]; break; } colors[num12++] = color; } } else { int num19 = 1 + num16; for (int num20 = 0; num20 < num19; num20++) { Color32 color2 = colors[num12]; switch (num11) { case 0: color2.a = 0xff; color2.r = buffer[++m]; break; case 1: color2.g = buffer[++m]; break; case 2: color2.b = buffer[++m]; break; case 3: color2.a = buffer[++m]; break; } colors[num12++] = color2; } } } } if (num12 == colors.Length) { num11++; num12 = 0; } } texture = new Texture2D(width, height, format, false); texture.SetPixels32(colors); texture.Apply(); return(true); } case 2: throw new NotSupportedException(); case 3: throw new NotSupportedException(); } throw new NotSupportedException(); } catch { texture = null; flag = false; } return(flag); }