void BuildStatusBar() { Texture2D stbarTexture = new DoomGraphic(wad.GetLump("STBAR")).ToRenderMap(true); Sprite stbarSprite = Sprite.Create(stbarTexture, new Rect(0, 0, (float)stbarTexture.width, (float)stbarTexture.height), new Vector2(0.5f, 0f)); statusBarObj = new GameObject("STBAR"); statusBarObj.transform.parent = transform; statusBarObj.layer = 9; SpriteRenderer sbsr = statusBarObj.AddComponent <SpriteRenderer>(); sbsr.material = spriteMaterial; sbsr.sprite = stbarSprite; statusBarObj.transform.localPosition = new Vector3(0f, -1f, 0f); Texture2D starmsTexture = new DoomGraphic(wad.GetLump("STARMS")).ToRenderMap(true); Sprite starmsSprite = Sprite.Create(starmsTexture, new Rect(0, 0, (float)starmsTexture.width, (float)starmsTexture.height), new Vector2(0.5f, 0f)); weaponSlotsObj = new GameObject("STARMS"); weaponSlotsObj.transform.parent = transform; weaponSlotsObj.layer = 9; SpriteRenderer sasr = weaponSlotsObj.AddComponent <SpriteRenderer>(); sasr.material = spriteMaterial; sasr.sprite = starmsSprite; weaponSlotsObj.transform.localPosition = new Vector3(-0.36f, -1f, -0.1f); }
public static Texture2D BuildPatch(string name, WadFile wad, bool ignoreCache = false) { if (!wad.Contains(name.ToUpper())) { return(null); } if (patchCache == null) { patchCache = new Dictionary <string, Texture2D>(); } if (!ignoreCache) { if (patchCache.ContainsKey(name)) { return(patchCache[name]); } } Texture2D output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToRenderMap(); if (!ignoreCache) { patchCache.Add(name, output); } return(output); }
private Image AddPatch(int x, int y, string patchName, GameObject parent = null) { Sprite logo = DoomGraphic.BuildSprite(patchName, GameSetup.wad); GameObject newPatch = new GameObject(patchName); Image img = newPatch.AddComponent <Image>(); img.material = menuMaterial; img.sprite = logo; if (parent != null) { newPatch.transform.SetParent(parent.transform, false); } else { newPatch.transform.SetParent(gameObject.transform, false); } img.SetNativeSize(); img.rectTransform.anchorMin = new Vector2(0f, 1f); img.rectTransform.anchorMax = new Vector2(0f, 1f); img.rectTransform.anchoredPosition = new Vector2(x, -y); img.rectTransform.pivot = new Vector2(logo.pivot.x / Mathf.Pow(img.rectTransform.sizeDelta.x, 2), 1.0f - (logo.pivot.y / Mathf.Pow(img.rectTransform.sizeDelta.y, 2))); return(img); }
public void SetupMaterial(WadFile wad) { titleIsPNG = wad.DetectType("TITLEPIC") == DataType.PNG; if (titleIsPNG) { mr.material = new Material(Shader.Find("Doom/Unlit Truecolor Texture")); } else { mr.material = new Material(Shader.Find("Doom/Unlit Texture")); } if (titleIsPNG) { Texture2D image = new Texture2D(2, 2); ImageConversion.LoadImage(image, wad.GetLump("TITLEPIC")); mr.material.SetTexture("_MainTex", image); float ratio = (float)Screen.width / (float)Screen.height; transform.localScale = new Vector3(ratio * 2f, 2f); transform.localPosition = new Vector3(0f, 0f, 1f); } else { mr.material.SetTexture("_Palette", new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture()); mr.material.SetTexture("_Colormap", new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture()); mr.material.SetTexture("_MainTex", DoomGraphic.BuildPatch("TITLEPIC", wad, true)); float ratio = (float)Screen.width / (float)Screen.height; transform.localScale = new Vector3(ratio * 2f, -2f); transform.localPosition = new Vector3(0f, 0f, 1f); } }
public void Build(WadFile wad) { if (mr == null) { InitSelf(wad); } mr.material.SetTexture("_Palette", new Palette(wad.GetLump("PLAYPAL")).GetLookupTexture()); mr.material.SetTexture("_Colormap", new Colormap(wad.GetLump("COLORMAP")).GetLookupTexture()); mr.material.SetTexture("_MainTex", DoomGraphic.BuildPatch("TITLEPIC", wad, true)); }
Texture2D GetFlat(string name) { name = name.ToUpper(); if (flatCache == null) { flatCache = new Dictionary <string, Texture2D>(); } if (flatCache.ContainsKey(name)) { return(flatCache[name]); } DoomFlat flat; if (wad.Contains(name)) { Texture2D output; DataType type = wad.DetectType(name); if (type == DataType.DoomFlat) { flat = new DoomFlat(wad.GetLump(name)); output = flat.ToRenderMap(); lastTexturePNG = false; } else if (type == DataType.PNG) { output = new Texture2D(2, 2, TextureFormat.ARGB32, false); ImageConversion.LoadImage(output, wad.GetLump(name)); output.filterMode = FilterMode.Point; lastTexturePNG = true; } else { throw new Exception("Unknown flat type: " + name); } flatCache.Add(name, output); return(output); } else { if (textureTable.Contains(name)) { return(DoomGraphic.BuildTexture(name, wad, textureTable)); } } throw new Exception("Cannot find flat: " + name); }
public static Sprite BuildSprite(string name, WadFile wad) { if (spriteCache == null) { spriteCache = new Dictionary <string, Sprite>(); } if (spriteCache.ContainsKey(name)) { return(spriteCache[name]); } Sprite output = new DoomGraphic(wad.GetLump(name.ToUpper())).ToSprite(); spriteCache.Add(name, output); return(output); }
GameObject BuildSprite(string graphic, float x, float y) { float offset = 1.6f / aspectRatio; Vector3 position = new Vector3( ((x - 160f) / 160f) * 1.6f, (y / 100f) - offset, graphic == "STBAR"?0f:-0.1f ); Texture2D texture = new DoomGraphic(wad.GetLump(graphic)).ToRenderMap(true); Sprite sprite = Sprite.Create(texture, new Rect(0, 0, (float)texture.width, (float)texture.height), new Vector2(0f, 0f)); var newObject = new GameObject(graphic); newObject.transform.parent = transform; newObject.layer = LayerMask.NameToLayer("HUD"); SpriteRenderer sbsr = newObject.AddComponent <SpriteRenderer>(); sbsr.material = spriteMaterial; sbsr.sprite = sprite; newObject.transform.localPosition = position; return(newObject); }
Texture2D GetTexture(string name, bool tryUpper = true) { if (textureTable.Contains(name)) { lastTexturePNG = false; return(DoomGraphic.BuildTexture(name, wad, textureTable)); } else { if (wad.Contains(name)) { DataType type = wad.DetectType(name); if (type == DataType.DoomFlat) { lastTexturePNG = false; return(new DoomFlat(wad.GetLump(name)).ToRenderMap()); } else if (type == DataType.PNG) { Texture2D image = new Texture2D(2, 2, TextureFormat.ARGB32, false); ImageConversion.LoadImage(image, wad.GetLump(name)); image.filterMode = FilterMode.Point; lastTexturePNG = true; return(image); } else { throw new Exception("Unknown texture type: " + name); } } else { if (tryUpper) { return(GetTexture(name.ToUpper(), false)); } throw new Exception("Cannot find texture: " + name); } } }
private Texture2D GetChar(char c) { if (textCache == null) { textCache = new Dictionary <char, Texture2D>(); } if (textCache.ContainsKey(c)) { return(textCache[c]); } string lumpName = lumpIdent + (int)char.ToUpper(c); if (wad.Contains(lumpName)) { Texture2D output = new DoomGraphic(wad.GetLump(lumpName)).ToRenderMap(); textCache.Add(c, output); return(output); } return(null); }
Texture2D GetTexture(string name) { return(DoomGraphic.BuildTexture(name, wad, textureTable)); }
public static Texture2D BuildTexture(string name, WadFile wad, TextureTable textures) { if (textureCache == null) { textureCache = new Dictionary <string, Texture2D>(); } if (textureCache.ContainsKey(name)) { return(textureCache[name]); } PatchTable pnames = new PatchTable(wad.GetLump("PNAMES")); DoomTexture texture = textures.Get(name.ToUpper()); Texture2D output = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false, true); for (int i = 0; i < texture.patches.Count; i++) { DoomPatch p = texture.patches[i]; Texture2D patch2d = DoomGraphic.BuildPatch(p.patchIndex, pnames, wad); if (patch2d == null) { return(null); } int copyX = (p.originX < 0)?-p.originX:0; int copyY = (p.originY < 0)?-p.originY:0; int pasteX = (p.originX > 0)?p.originX:0; int pasteY = (p.originY > 0)?p.originY:0; int copyWidth = patch2d.width - copyX; if (copyWidth > output.width - pasteX) { copyWidth = output.width - pasteX; } int copyHeight = patch2d.height - copyY; if (copyHeight > output.height - pasteY) { copyHeight = output.height - pasteY; } for (int a = 0; a < copyWidth; a++) { for (int b = 0; b < copyHeight; b++) { Color col = patch2d.GetPixel(copyX + a, copyY + b); if (col.a != 0f) { output.SetPixel(pasteX + a, pasteY + b, col); } } } } output.Apply(); output.wrapMode = TextureWrapMode.Repeat; output.filterMode = FilterMode.Point; textureCache.Add(name, output); return(output); }
private void BuildCursor(GameObject parent) { cursorAnim1 = DoomGraphic.BuildSprite("M_SKULL1", GameSetup.wad); cursorAnim2 = DoomGraphic.BuildSprite("M_SKULL2", GameSetup.wad); cursorImage = AddPatch(65, 83, "M_SKULL1", parent); }