void DrawBar(GUIBarOptions guiBar, Side side, float currentValue, float totalValue, bool topGUI) { // A custom method to create the draining bar Rect backRect = SetResolution(guiBar.backgroundRect); Rect fillRect = SetResolution(guiBar.fillRect); Rect remainFill; float newWidth = (currentValue / totalValue) * fillRect.width; float leftAdjustment = fillRect.width - newWidth; if (side == Side.Right) { backRect.x = Screen.width - backRect.width - backRect.x; remainFill = new Rect(fillRect.x, fillRect.y, newWidth, fillRect.height); } else { float newXPos = fillRect.x + (fillRect.width - newWidth); remainFill = new Rect(newXPos, fillRect.y, (currentValue / totalValue) * fillRect.width, fillRect.height); } if (!topGUI) { backRect.y = Screen.height - backRect.height - backRect.y; } GUI.DrawTexture(backRect, guiBar.backgroundImage); GUI.BeginGroup(backRect); { GUI.BeginGroup(remainFill); { if (side == Side.Right) { GUI.DrawTexture(new Rect(0, 0, fillRect.width, fillRect.height), guiBar.fillImage, ScaleMode.ScaleAndCrop); } else { GUI.DrawTexture(new Rect(-leftAdjustment, 0, fillRect.width, fillRect.height), guiBar.fillImage, ScaleMode.ScaleAndCrop); } } GUI.EndGroup(); } GUI.EndGroup(); }
void DrawBar(GUIBarOptions guiBar, Side side, float currentValue, float totalValue, bool topGUI) { // A custom method to create the draining bar Rect backRect = SetResolution(guiBar.backgroundRect); Rect fillRect = SetResolution(guiBar.fillRect); Rect remainFill; float newWidth = (currentValue/totalValue) * fillRect.width; float leftAdjustment = fillRect.width - newWidth; if (side == Side.Right){ backRect.x = Screen.width - backRect.width - backRect.x; if (topGUI){ remainFill = new Rect(fillRect.x, fillRect.y, newWidth, fillRect.height); }else{ remainFill = new Rect(fillRect.x, backRect.height - fillRect.height - fillRect.y, newWidth, fillRect.height); } }else{ float newXPos = fillRect.x + (fillRect.width - newWidth); if (topGUI){ remainFill = new Rect(newXPos, fillRect.y, (currentValue/totalValue) * fillRect.width, fillRect.height); }else{ remainFill = new Rect(newXPos, backRect.height - fillRect.height - fillRect.y, (currentValue/totalValue) * fillRect.width, fillRect.height); } } if (!topGUI) backRect.y = Screen.height - backRect.height - backRect.y; if (side == Side.Left){ GUI.DrawTexture(backRect, guiBar.backgroundImage); }else{ //GUI.DrawTextureWithTexCoords(backRect, guiBar.backgroundImage, new Rect(0, 0, -1, 1)); GUI.DrawTexture(new Rect(backRect.x + backRect.width, backRect.y, -backRect.width, backRect.height), guiBar.backgroundImage); } GUI.BeginGroup(backRect);{ GUI.BeginGroup(remainFill);{ if (side == Side.Right){ GUI.DrawTexture(new Rect(0, 0, fillRect.width, fillRect.height), guiBar.fillImage, ScaleMode.ScaleAndCrop); }else{ GUI.DrawTexture(new Rect(-leftAdjustment, 0, fillRect.width, fillRect.height), guiBar.fillImage, ScaleMode.ScaleAndCrop); } }GUI.EndGroup(); }GUI.EndGroup(); }