private void UpdateMesh() { if (Builder == null || Filter == null || Renderer == null) { return; } Builder.Reset(); Rect internalRect = new Rect(0, 0, 1, 1); Builder.AddQuad(0, 0, 0, 480, 85); // int loc = RemapFromSpell(ActiveSpell); if (loc >= 0) { int spx = loc % 12; int spy = loc / 12; Rect irSpellBlock = Utils.DivRect(new Rect(5 + spx * 38, 5 + spy * 38, 37, 37), new Vector2(SpbFrame.width, SpbFrame.height)); Builder.AddQuad(0, 5 + spx * 38 + 1, 5 + spy * 38 + 1, 37, 37, irSpellBlock, new Color(0.5f, 0.5f, 0.5f, 1)); } for (int i = 0; i < 24; i++) { if ((SpellsMask & (1u << (int)RemapToSpell(i))) != 0) { continue; } int spx = i % 12; int spy = i / 12; Builder.AddQuad(1, 5 + spx * 38 + 1, 5 + spy * 38 + 1, 36, 36); } Builder.CurrentMesh = 1; Filter.mesh = Builder.ToMesh(MeshTopology.Quads, MeshTopology.Quads); }
public void UpdateMesh() { if (Filter.mesh != null && LastWidth == Width && LastHeight == Height && LastClicked == _Clicked && LastChecked == Checked) { return; } LastChecked = Checked; LastClicked = _Clicked; LastWidth = Width; LastHeight = Height; if (Builder == null) { Builder = new Utils.MeshBuilder(); } // Color col_inactive = new Color(1, 1, 1, 1); Color col_active = new Color(1, 1, 1, 0); if (_Clicked) { col_active = new Color(1, 1, 1, 0.5f); } else if (Checked) { col_active = new Color(1, 1, 1, 1); col_inactive = new Color(0, 0, 0, 1); } Builder.AddQuad(0, 0, 0, imgRadiob.Sprites[2].rect.width, imgRadiob.Sprites[2].rect.height, imgRadiob.AtlasRects[2], col_inactive); // disabled Builder.AddQuad(0, 0, 0, imgRadiob.Sprites[3].rect.width, imgRadiob.Sprites[3].rect.height, imgRadiob.AtlasRects[3], col_active); // disabled Filter.mesh = Builder.ToMesh(MeshTopology.Quads); }
public void SetTooltip(string text) { if (Tooltip == null) { TooltipRendererA = new AllodsTextRenderer(Fonts.Font2, Font.Align.Left, 0, 0, false, 12); Tooltip = Utils.CreateObject(); Tooltip.transform.parent = transform; TooltipRenderer = Tooltip.AddComponent <MeshRenderer>(); TooltipFilter = Tooltip.AddComponent <MeshFilter>(); TooltipBall = Images.LoadImage("graphics/interface/ball.bmp", 0, Images.ImageType.AllodsBMP); Material[] materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; materials[0].mainTexture = TooltipBall; TooltipRenderer.materials = materials; GameObject TooltipText = TooltipRendererA.GetNewGameObject(0.01f, Tooltip.transform, 100); TooltipRendererA.Material.color = new Color32(165, 121, 49, 255); TooltipText.transform.localPosition = new Vector3(6, 6, -0.02f); } Tooltip.SetActive(true); float topX = lastMouseX; float topY = lastMouseY; text = text.Replace('#', '\n').Replace("~", ""); TooltipRendererA.Text = text; // ideal position for the tooltip is top/right of the mouse. // but if it doesn't fit, should be moved around. topX = lastMouseX; topY = lastMouseY - TooltipRendererA.Height - 12; float fw = TooltipRendererA.ActualWidth + 12; float fh = TooltipRendererA.Height + 12; if (topX + fw > MainCamera.Width) { topX = MainCamera.Width - fw; } if (topY + fh > MainCamera.Height) { topY = MainCamera.Height - fh; } if (topX < 0) { topX = 0; } if (topY < 0) { topY = 0; } Tooltip.transform.localPosition = new Vector3(topX, topY, MainCamera.MouseZ + 0.01f); TooltipBuilder.Reset(); TooltipBuilder.AddQuad(0, 0, 0, 4, 4); TooltipBuilder.AddQuad(0, TooltipRendererA.ActualWidth + 8, 0, 4, 4); TooltipBuilder.AddQuad(0, TooltipRendererA.ActualWidth + 8, TooltipRendererA.Height + 6, 4, 4); TooltipBuilder.AddQuad(0, 0, TooltipRendererA.Height + 6, 4, 4); // now render border quads float bw = TooltipRendererA.ActualWidth + 6; float bh = TooltipRendererA.Height + 6 - 2; // 2 = difference between "LineHeight" and our custom LineHeight of 12 // top border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 1); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 1); TooltipBuilder.NextVertex(); // top border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 1 + 2); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 1 + 2); TooltipBuilder.NextVertex(); // bottom border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh); TooltipBuilder.NextVertex(); // bottom border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh + 2); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3, 3 + bh + 2); TooltipBuilder.NextVertex(); // left border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(1, 3); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(1, 3 + bh); TooltipBuilder.NextVertex(); // left border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(1 + 2, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(1 + 2, 3); TooltipBuilder.NextVertex(); // right border bright TooltipBuilder.CurrentMesh = 1; TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(165, 121, 49, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw, 3 + bh); TooltipBuilder.NextVertex(); // right border dark TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw + 2, 3 + bh); TooltipBuilder.NextVertex(); TooltipBuilder.CurrentColor = new Color32(82, 60, 24, 255); TooltipBuilder.CurrentPosition = new Vector3(3 + bw + 2, 3); TooltipBuilder.NextVertex(); // BACKGROUND QUAD TooltipBuilder.AddQuad(TooltipBuilder.CurrentMesh, 3, 3, bw, bh, new Color32(33, 44, 33, 255)); TooltipFilter.mesh = TooltipBuilder.ToMesh(MeshTopology.Quads, MeshTopology.Quads); }
public void Start() { UiManager.Instance.Subscribe(this); if (InvFrame == null) { InvFrame = Images.LoadImage("graphics/interface/invframe.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow1 == null) { InvArrow1 = Images.LoadImage("graphics/interface/invarrow1.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow2 == null) { InvArrow2 = Images.LoadImage("graphics/interface/invarrow2.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow3 == null) { InvArrow3 = Images.LoadImage("graphics/interface/invarrow3.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow4 == null) { InvArrow4 = Images.LoadImage("graphics/interface/invarrow4.bmp", 0, Images.ImageType.AllodsBMP); } // Renderer = gameObject.AddComponent <MeshRenderer>(); Filter = gameObject.AddComponent <MeshFilter>(); Renderer.materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; Renderer.materials[0].mainTexture = InvFrame; Renderer.materials[1].color = Renderer.materials[2].color = new Color(0, 0, 0, 0); // generate mesh. Utils.MeshBuilder mb = new Utils.MeshBuilder(); // 3 submeshes: left arrow, right arrow, and background. I'm NOT using the full original inventory view. for (int i = 0; i < View.InvWidth; i++) { int internalPosition; if (i == 0) { internalPosition = 0; } else if (i == View.InvWidth - 1) { internalPosition = 4; } else { internalPosition = (i % 3) + 1; } Rect internalRect = Utils.DivRect(new Rect(32 + internalPosition * 80, 0, 80, 90), new Vector2(InvFrame.width, InvFrame.height)); mb.AddQuad(0, 32 + i * 80, 0, 80, 90, internalRect); } // add two quads for unpressed buttons mb.AddQuad(0, 0, 0, 32, 90, Utils.DivRect(new Rect(0, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(0, 32 + View.InvWidth * 80, 0, 32, 90, Utils.DivRect(new Rect(432, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(1, 0, 2, 32, 88); mb.AddQuad(2, 32 + View.InvWidth * 80, 2, 32, 88); Filter.mesh = mb.ToMesh(MeshTopology.Quads, MeshTopology.Quads, MeshTopology.Quads); transform.localScale = new Vector3(1, 1, 0.01f); transform.localPosition = new Vector3((Screen.width - 176) / 2 - (View.InvWidth * 80 + 64) / 2, Screen.height - 90, MainCamera.InterfaceZ + 0.99f); // on this layer all map UI is drawn }
public void Start() { UiManager.Instance.Subscribe(this); if (CrystalL == null) { CrystalL = Images.LoadImage("graphics/interface/crystall.bmp", 0, Images.ImageType.AllodsBMP); } if (CrystalR == null) { CrystalR = Images.LoadImage("graphics/interface/crystalr.bmp", Images.ImageType.AllodsBMP); } transform.localScale = new Vector3(1, 1, 0.01f); transform.localPosition = new Vector3(MainCamera.Width - 176, 0, MainCamera.InterfaceZ + 0.99f); // on this layer all map UI is drawn CrystalLObject = Utils.CreatePrimitive(PrimitiveType.Quad); CrystalLRenderer = CrystalLObject.GetComponent <MeshRenderer>(); CrystalLObject.transform.parent = transform; CrystalLObject.transform.localScale = new Vector3(CrystalL.width, CrystalL.height, 1); CrystalLObject.transform.localPosition = new Vector3(CrystalL.width / 2, CrystalL.height / 2, 0); CrystalLRenderer.material = new Material(MainCamera.MainShader); CrystalLRenderer.material.mainTexture = CrystalL; CrystalRObject = Utils.CreatePrimitive(PrimitiveType.Quad); CrystalRRenderer = CrystalRObject.GetComponent <MeshRenderer>(); CrystalRObject.transform.parent = transform; CrystalRObject.transform.localScale = new Vector3(CrystalR.width, CrystalR.height, 1); CrystalRObject.transform.localPosition = new Vector3(CrystalL.width + CrystalR.width / 2, CrystalR.height / 2, 0); CrystalRRenderer.material = new Material(MainCamera.MainShader); CrystalRRenderer.material.mainTexture = CrystalR; TexObject = Utils.CreatePrimitive(PrimitiveType.Quad); TexRenderer = TexObject.GetComponent <MeshRenderer>(); TexObject.transform.parent = transform; TexObject.transform.localPosition = new Vector3(CrystalL.width + CrystalR.width / 2, CrystalR.height / 2, 0); TexRenderer.material = new Material(MainCamera.MainShader); TexRenderer.material.mainTexture = MapTexture; TexRenderer.enabled = false; if (MiniMapData == null) { Texture2D mmData = Images.LoadImage("graphics/interface/minimapdata.bmp", Images.ImageType.AllodsBMP); MiniMapData = mmData.GetPixels(); DestroyImmediate(mmData); } // update bounds object Utils.MeshBuilder mb = new Utils.MeshBuilder(); mb.CurrentPosition = new Vector2(-0.00390625f, 0); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(1, 0); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(1, 0); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(1, 1); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(1, 1); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(0, 1); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(0, 1); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); mb.CurrentPosition = new Vector2(0, -0.00390625f); mb.CurrentColor = new Color(1, 1, 1, 1); mb.NextVertex(); Mesh boundsMesh = mb.ToMesh(MeshTopology.Lines); BoundsObject = new GameObject(); BoundsObject.name = "ScreenBounds"; BoundsObject.transform.parent = transform; BoundsObject.transform.localPosition = new Vector3(0, 0, -2f); BoundsObject.transform.localScale = new Vector2(0, 0); MeshFilter boundsFilter = BoundsObject.AddComponent <MeshFilter>(); boundsFilter.mesh = boundsMesh; BoundsRenderer = BoundsObject.AddComponent <MeshRenderer>(); BoundsRenderer.material = new Material(MainCamera.MainShader); BoundsRenderer.enabled = false; }
public void Update() { // update text if (TextObjects.Count != InvWidth * InvHeight || TextRenderers.Count != InvWidth * InvHeight) { for (int i = 0; i < TextRenderers.Count; i++) { TextRenderers[i].DestroyImmediate(); } TextObjects.Clear(); TextRenderers.Clear(); for (int ly = 0; ly < InvHeight; ly++) { for (int lx = 0; lx < InvWidth; lx++) { AllodsTextRenderer atr = new AllodsTextRenderer(Fonts.Font2); atr.Text = ""; atr.Material.color = new Color32(0xBD, 0x9E, 0x4A, 0xFF); GameObject go = atr.GetNewGameObject(0.01f, transform, 100, 0.01f); TextObjects.Add(go); TextRenderers.Add(atr); go.transform.localPosition = new Vector3((lx * 80 + 6) * InvScale, (ly * 80 + 80 - 4) * InvScale - atr.Font.LineHeight, -0.2f); } } } // first submesh = quads, item background // second submesh = lines, item magic glow // third submesh = quads, item pictures if (Pack == null) { Filter.mesh.Clear(); return; } Builder.Reset(); int start = Math.Max(Math.Min(Scroll, Pack.Count - InvWidth * InvHeight), 0); int end = Math.Min(start + InvWidth * InvHeight, Pack.Count); int x = 0; int y = 0; for (int i = start; i < end; i++) { Builder.AddQuad(y * InvWidth + x, (x * 80) * InvScale, (y * 80) * InvScale, 80 * InvScale, 80 * InvScale, new Rect(0, 0, 1, 1)); // check texture. // for now, just put generic background Renderer.materials[y * InvWidth + x].mainTexture = img_BackInv; x++; if (x >= InvWidth) { x = 0; y++; } } for (int i = 0; i < TextObjects.Count; i++) { TextObjects[i].SetActive(false); } // now add magic glow where it should be x = 0; y = 0; UpdateMGlow(); // per-widget unique animation is used. int rnd = 0; for (int i = start; i < end; i++) { // check if item has special effects Item item = Pack[i]; if (item.MagicEffects.Count > 0) { float baseX = x * 80 * InvScale; float baseY = y * 80 * InvScale; Builder.CurrentMesh = InvWidth * InvHeight * 2; foreach (MGlowPart part in MGlowParts) { // draw all glow parts // left Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x - 2f * part.state, baseY + part.y); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // right Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x + 2f * part.state, baseY + part.y); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // top Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y - 2f * part.state); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); // bottom Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y); Builder.CurrentColor = new Color32(208, 0, 208, 255); Builder.NextVertex(); Builder.CurrentPosition = new Vector3(baseX + part.x, baseY + part.y + 2f * part.state); Builder.CurrentColor = new Color32(64, 0, 64, 255); Builder.NextVertex(); } } int dcount = item.Count; if (UiManager.Instance.DragItem == item) { dcount -= UiManager.Instance.DragItemCount; } if (dcount > 1) { TextRenderers[rnd].Text = dcount.ToString(); TextObjects[rnd].SetActive(true); } rnd++; x++; if (x >= InvWidth) { x = 0; y++; } } // add item pictures x = 0; y = 0; for (int i = start; i < end; i++) { Item item = Pack[i]; item.Class.File_Pack.UpdateSprite(); // check texture. // for now, just put generic background Renderer.materials[InvWidth * InvHeight + y * InvWidth + x].mainTexture = item.Class.File_Pack.File.Atlas; Renderer.materials[InvWidth * InvHeight + y * InvWidth + x].SetTexture("_Palette", item.Class.File_Pack.File.OwnPalette); Color color = new Color(1, 1, 1, (item == UiManager.Instance.DragItem) ? 0.25f : 1); // draw dragged items half transparent Builder.AddQuad(InvWidth * InvHeight + y * InvWidth + x, (x * 80) * InvScale, (y * 80) * InvScale, 80 * InvScale, 80 * InvScale, item.Class.File_Pack.File.AtlasRects[0], color); x++; if (x >= InvWidth) { x = 0; y++; } } MeshTopology[] topologies = new MeshTopology[InvWidth * InvHeight * 2 + 1]; for (int i = 0; i < InvWidth * InvHeight; i++) { topologies[i] = MeshTopology.Quads; topologies[InvWidth * InvHeight + i] = MeshTopology.Quads; } topologies[InvWidth * InvHeight * 2] = MeshTopology.Lines; Builder.CurrentMesh = topologies.Length - 1; Filter.mesh = Builder.ToMesh(topologies); }
public void Start() { ItemCount = (MainCamera.Width - 176 - 64) / 80; // each arrow is 32 in width View.InvScale = 1; View.InvWidth = (int)(ItemCount / View.InvScale); View.InvHeight = (int)(1 / View.InvScale); View.ShowMoney = true; if (InvFrame == null) { InvFrame = Images.LoadImage("graphics/interface/invframe.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow1 == null) { InvArrow1 = Images.LoadImage("graphics/interface/invarrow1.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow2 == null) { InvArrow2 = Images.LoadImage("graphics/interface/invarrow2.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow3 == null) { InvArrow3 = Images.LoadImage("graphics/interface/invarrow3.bmp", 0, Images.ImageType.AllodsBMP); } if (InvArrow4 == null) { InvArrow4 = Images.LoadImage("graphics/interface/invarrow4.bmp", 0, Images.ImageType.AllodsBMP); } // Renderer = gameObject.AddComponent <MeshRenderer>(); Filter = gameObject.AddComponent <MeshFilter>(); Renderer.materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; Renderer.materials[0].mainTexture = InvFrame; Renderer.materials[1].color = Renderer.materials[2].color = new Color(0, 0, 0, 0); // generate mesh. Utils.MeshBuilder mb = new Utils.MeshBuilder(); // 3 submeshes: left arrow, right arrow, and background. I'm NOT using the full original inventory view. for (int j = 1; j >= 0; j--) { for (int i = 0; i < View.InvWidth; i++) { int internalPosition; if (i == 0) { internalPosition = 0; } else if (i == View.InvWidth - 1) { internalPosition = 4; } else { internalPosition = (i % 3) + 1; } int yoffs = 0; if (View.InvScale < 1) { yoffs = (int)(1.5f / View.InvScale); } Rect internalRect = Utils.DivRect(new Rect(32 + internalPosition * 80, 0, 80, 90), new Vector2(InvFrame.width, InvFrame.height)); mb.AddQuad(0, 32 + i * 80 * View.InvScale, j * 80 * View.InvScale + yoffs, 80 * View.InvScale, 90 * View.InvScale, internalRect); } } // add two quads for unpressed buttons mb.AddQuad(0, 0, 0, 32, 90, Utils.DivRect(new Rect(0, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(0, 32 + View.InvWidth * 80 * View.InvScale, 0, 32, 90, Utils.DivRect(new Rect(432, 0, 32, 90), new Vector2(InvFrame.width, InvFrame.height))); mb.AddQuad(1, 0, 2, 32, 88); mb.AddQuad(2, 32 + View.InvWidth * 80 * View.InvScale, 2, 32, 88); Filter.mesh = mb.ToMesh(MeshTopology.Quads, MeshTopology.Quads, MeshTopology.Quads); transform.localScale = new Vector3(1, 1, 0.01f); transform.localPosition = new Vector3((MainCamera.Width - 176) / 2 - (View.InvWidth * 80 * View.InvScale + 64) / 2, MainCamera.Height - 90, MainCamera.InterfaceZ + 0.99f); // on this layer all map UI is drawn }
void SetMesh() { if (Filter.mesh) { Destroy(Filter.mesh); } List <Material> materials = new List <Material>(); List <MeshTopology> topos = new List <MeshTopology>(); materials.Add(new Material(MainCamera.MainShader)); // this is for outlines topos.Add(MeshTopology.Lines); //Renderer.materials = new Material[] { new Material(MainCamera.MainShader), new Material(MainCamera.MainShader) }; Utils.MeshBuilder mb = new Utils.MeshBuilder(); for (int i = 0; i < CurrentLevel.Sectors.Count; i++) { LevelSector sec = CurrentLevel.Sectors[i]; if (drawAfter >= 0 && i < drawAfter) { continue; } int planemesh = mb.CurrentMesh + 1; mb.CurrentMesh = 0; //if (sec.Walls.Count > 1) Debug.LogFormat("sector {0} has walls", i); for (int j = 0; j < sec.Walls.Count; j++) { LevelWall wall = sec.Walls[j]; //if (j != 0) continue; if (wall.V1.X < 0 || wall.V1.Y < 0 || wall.V2.X < 0 || wall.V2.Y < 0) { continue; } Color color = new Color(1, 0, 0, 1); if (wall.Back != null) { color.r = 0; color.g = 1f; } //if (i == 0) color.g = color.b = 0; //else if (i == 10) color.g = color.r = 0; // sector 0 = 0 // sector 10 = +8 (-8) floor height float TopFZ1 = wall.Front.Sector.Floor.ZatPoint(wall.V1.X, wall.V1.Y); if (wall.Back != null) { TopFZ1 = Mathf.Max(TopFZ1, wall.Back.Sector.Floor.ZatPoint(wall.V1.X, wall.V1.Y)); // top point at v1 } float BottomFZ1 = wall.Front.Sector.Floor.ZatPoint(wall.V1.X, wall.V1.Y); if (wall.Back != null) { BottomFZ1 = Mathf.Min(BottomFZ1, wall.Back.Sector.Floor.ZatPoint(wall.V1.X, wall.V1.Y)); } float TopFZ2 = wall.Front.Sector.Floor.ZatPoint(wall.V2.X, wall.V2.Y); if (wall.Back != null) { TopFZ2 = Mathf.Max(TopFZ2, wall.Back.Sector.Floor.ZatPoint(wall.V2.X, wall.V2.Y)); // top point at v2 } float BottomFZ2 = wall.Front.Sector.Floor.ZatPoint(wall.V2.X, wall.V2.Y); if (wall.Back != null) { BottomFZ2 = Mathf.Min(BottomFZ2, wall.Back.Sector.Floor.ZatPoint(wall.V2.X, wall.V2.Y)); } float TopCZ1 = wall.Front.Sector.Ceiling.ZatPoint(wall.V1.X, wall.V1.Y); if (wall.Back != null) { TopCZ1 = Mathf.Max(TopCZ1, wall.Back.Sector.Ceiling.ZatPoint(wall.V1.X, wall.V1.Y)); // top point at v1 } float BottomCZ1 = wall.Front.Sector.Ceiling.ZatPoint(wall.V1.X, wall.V1.Y); if (wall.Back != null) { BottomCZ1 = Mathf.Min(BottomCZ1, wall.Back.Sector.Ceiling.ZatPoint(wall.V1.X, wall.V1.Y)); } float TopCZ2 = wall.Front.Sector.Ceiling.ZatPoint(wall.V2.X, wall.V2.Y); if (wall.Back != null) { TopCZ2 = Mathf.Max(TopCZ2, wall.Back.Sector.Ceiling.ZatPoint(wall.V2.X, wall.V2.Y)); // top point at v2 } float BottomCZ2 = wall.Front.Sector.Ceiling.ZatPoint(wall.V2.X, wall.V2.Y); if (wall.Back != null) { BottomCZ2 = Mathf.Min(BottomCZ2, wall.Back.Sector.Ceiling.ZatPoint(wall.V2.X, wall.V2.Y)); } if (wall.Back != null) { mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopCZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, BottomFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, BottomFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, BottomCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, BottomCZ2); mb.NextVertex(); } else { mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopCZ2); mb.NextVertex(); } // vertical lines if (wall.Back != null) { mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, BottomFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, BottomFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, BottomCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopCZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, BottomCZ2); mb.NextVertex(); } else { mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, TopFZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V1.X, wall.V1.Y, BottomCZ1); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, TopFZ2); mb.NextVertex(); mb.CurrentColor = color; mb.CurrentPosition = new Vector3(wall.V2.X, wall.V2.Y, BottomCZ2); mb.NextVertex(); } } // draw floor Material texfloor = new Material(MainCamera.MainShader); RadixBitmap bitmapfloor = TextureManager.GetTextureById(sec.Floor.Texture); Vector2 texmul = new Vector2(bitmapfloor.Width, bitmapfloor.Height); if (bitmapfloor != null) { texfloor.mainTexture = bitmapfloor.Texture; } Material texceiling = new Material(MainCamera.MainShader); RadixBitmap bitmapceiling = TextureManager.GetTextureById(sec.Ceiling.Texture); Vector2 texmul2 = new Vector2(bitmapceiling.Width, bitmapceiling.Height); if (bitmapceiling != null) { texceiling.mainTexture = bitmapceiling.Texture; } materials.Add(texfloor); materials.Add(texceiling); topos.Add(MeshTopology.Triangles); topos.Add(MeshTopology.Triangles); for (int p = 0; p < 2; p++) { mb.CurrentMesh = planemesh + p; LevelSector.Plane plane = p == 0 ? sec.Floor : sec.Ceiling; for (int j = 0; j < sec.Triangles.Count; j++) { LevelSector.Triangle tri = sec.Triangles[j]; Color color = new Color(0.5f, 0.5f, 0.5f, 1); if (tri.Points.Count != 3) { // now, we know that this mesh is NOT actual triangle list, it consists of points around the sector. Vector2 center = tri.Center; for (int k = 0; k < tri.Points.Count; k++) { // add center point mb.CurrentColor = color; mb.CurrentPosition = new Vector3(center.x, center.y, plane.ZatPoint(center.x, center.y)); mb.CurrentUV1 = new Vector2(center.x / texmul.x, center.y / texmul.y); mb.NextVertex(); // add current point int cIndex = k % tri.Points.Count; mb.CurrentColor = color; mb.CurrentPosition = new Vector3(tri.Points[cIndex].x, tri.Points[cIndex].y, plane.ZatPoint(tri.Points[cIndex].x, tri.Points[cIndex].y)); mb.CurrentUV1 = new Vector2(tri.Points[cIndex].x / texmul.x, tri.Points[cIndex].y / texmul.y); mb.NextVertex(); // add next point int nIndex = (k + 1) % tri.Points.Count; mb.CurrentColor = color; mb.CurrentPosition = new Vector3(tri.Points[nIndex].x, tri.Points[nIndex].y, plane.ZatPoint(tri.Points[nIndex].x, tri.Points[nIndex].y)); mb.CurrentUV1 = new Vector2(tri.Points[nIndex].x / texmul.x, tri.Points[nIndex].y / texmul.y); mb.NextVertex(); } } else // it's a legit triangle, don't overcomplicate { for (int k = 0; k < 3; k++) { mb.CurrentColor = color; mb.CurrentPosition = new Vector3(tri.Points[k].x, tri.Points[k].y, plane.ZatPoint(tri.Points[k].x, tri.Points[k].y)); mb.CurrentUV1 = new Vector2(tri.Points[k].x / texmul.x, tri.Points[k].y / texmul.y); mb.NextVertex(); } } } } if (drawAfter >= 0 && i >= drawAfter && sec.Walls.Count > 0) { Debug.LogFormat("stopped rendering at {0}", i); break; } } Filter.mesh = mb.ToMesh(topos.ToArray()); Renderer.materials = materials.ToArray(); }