// Draws the GUI (Some processing done) void OnGUI() { // Wizard GUI.DrawTexture(UnityGUIExt.CreateRect(350.0f, -100.0f, 870.0f, 870.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE), m_Wizard); // Title (Background) GUI.DrawTexture(UnityGUIExt.CreateRect(0.0f, 10.0f, 815.0f, 753.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE), m_TitleTexture); // Name field ProcessNameFieldGUI(); m_rectNameField = UnityGUIExt.CreateRect(293.0f, 398.0f, 175.0f, 23.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE); if (m_bNameBoxSelected) { GUI.DrawTexture(m_rectNameField, m_tSelected); } GUI.Label(m_rectNameField, m_strPlayerName); ProcessServerListGUI(); m_oJoinButton.DoGUI(); m_oHostButton.DoGUI(); m_oQuitButton.DoGUI(); m_oScroller.DoGUI(); }
// Use this for initialization void Start() { // Add the scanner so we can immediately bring up a list of games gameObject.AddComponent(typeof(ServerScanner)); RefreshList(); // Load the players name or set it to a default value if (PlayerPrefs.HasKey("PlayerName")) { m_strPlayerName = PlayerPrefs.GetString("PlayerName"); } else { // Assign a random name SetName(""); } m_oJoinButton = UnityGUIExt.CreateButton(300.0f, 450.0f, 100.0f, 50.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE, "JOIN"); m_oHostButton = UnityGUIExt.CreateButton(300.0f, 525.0f, 100.0f, 50.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE, "HOST"); m_oQuitButton = UnityGUIExt.CreateButton(300.0f, 650.0f, 100.0f, 50.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE, "QUIT"); m_oScroller = new Scrollbar(); }
void UpdateBox(float _fX, float _fY, float _fWidth, float _fHeight, UnityGUIExt.GUI_ALLIGN _eScreenAllign, UnityGUIExt.GUI_ALLIGN _eAllign) { m_rectBox = UnityGUIExt.CreateRect(m_fX, m_fY, m_fWidth, m_fHeight, m_eAllignment, m_eScreenAllignment); m_rectText.x = m_rectBox.x + 1; m_rectText.y = m_rectBox.y + m_rectBox.height + 2; m_rectText.width = m_rectBox.width - 1; m_rectText.height = 25; }
// Initalises all rectangles. Recall if the screen resolution is changed. void ResetLayout() { // Title m_rectTitle = UnityGUIExt.CreateRect(0.0f, 0.0f, 762.0f, 676.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE); m_rectSpellEntry = new Rect(72.0f, 172.0f, 272.0f, 89.0f); m_rectSpellIcon = new Rect(80, 182, 69, 69); m_rectSpellTitle = new Rect(70, 140, 132, 25); m_rectSpellCost = new Rect(275, 140, 60, 33); m_rectOwnedCrystals = new Rect(621, 96, 54, 28); m_rectSpellDesc = new Rect(160, 180, 170, 70); }
void OnGUI() { GUI.DrawTexture(UnityGUIExt.CreateRect(0, 0, 512, 512, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT), m_tBotRight); if (Network.isServer) { m_oStartButton.DoGUI(); } m_oBackButton.DoGUI(); DrawGuiPlayerList(); m_oNormalButton.DoGUI(); m_oRandomButton.DoGUI(); m_oWTFButton.DoGUI(); if (m_iGameModeSelected == 0) { GUI.DrawTexture(m_oNormalButton.GetRect(), m_tSelected); } else if (m_iGameModeSelected == 1) { GUI.DrawTexture(m_oRandomButton.GetRect(), m_tSelected); } else if (m_iGameModeSelected == 2) { GUI.DrawTexture(m_oWTFButton.GetRect(), m_tSelected); } m_oRounds3.DoGUI(); m_oRounds6.DoGUI(); m_oRounds9.DoGUI(); if (m_iRoundsSelected == 3) { GUI.DrawTexture(m_oRounds3.GetRect(), m_tSelected); } else if (m_iRoundsSelected == 6) { GUI.DrawTexture(m_oRounds6.GetRect(), m_tSelected); } else if (m_iRoundsSelected == 9) { GUI.DrawTexture(m_oRounds9.GetRect(), m_tSelected); } //m_cChatBox.DoGUI(); }
// FIX ISSUES HERE with http://answers.unity3d.com/questions/13443/is-there-a-way-to-measure-the-pixel-withheight-of.html void DrawChatBox() { Rect rView = m_rectBox; rView.x = 0; rView.y = 0; rView.height = m_listChatEntries.Count * 30; Rect rBox = m_rectBox; rBox.width += 20; //GUI.BeginScrollView(rBox, m_v2ScrollPos, rView, false, false); //m_v2ScrollPos = new Vector2(m_v2ScrollPos.x, rView.height); if (m_listChatEntries.Count < 7) // quick fix for something frustating { m_v2ScrollPos.y = 0; } UnityGUIExt.BeginScrollView(rBox, m_v2ScrollPos, rView, false, false); m_oScrollbar.Initialise(m_rectBox, rView, m_rectBox.width + 5, 0, m_rectBox.height, (m_rectBox.height / rView.height) * m_rectBox.height, m_v2ScrollPos); m_v2ScrollPos = m_oScrollbar.DoUpdate(); if (m_rectBox.height / rView.height < 1.0f) { m_bDrawScroll = true; } else { m_bDrawScroll = false; } foreach (CChatEntry cEntry in m_listChatEntries) { if (cEntry.sName == "") { //Game message GUILayout.Label(cEntry.sMessage); } else { GUILayout.Label(cEntry.sName + ": " + cEntry.sMessage); } } //GUI.EndScrollView(); UnityGUIExt.EndScrollView(); }
//private CChatBox m_cChatBox; // Member Functions // Public: // Private: void Start() { //m_cChatBox = gameObject.AddComponent(typeof(CChatBox)) as CChatBox; //m_cChatBox.Initialise(UnityGUIExt.CreateRect(10,30,300,200, UnityGUIExt.GUI_ALLIGN.BOT_LEFT, UnityGUIExt.GUI_ALLIGN.BOT_LEFT), PlayerPrefs.GetString("PlayerName")); //m_cPlayerListTexture = Resources.Load("UI/Main_Serverlist", typeof(Texture)) as Texture; //m_cBottomBoxTexture = Resources.Load("UI/HUD_Bottom", typeof(Texture)) as Texture; ResetLayout(); //gameObject.AddComponent(typeof(Chat)); m_oStartButton = UnityGUIExt.CreateButton(33.0f, 90.0f, 100.0f, 50.0f, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "START"); m_oBackButton = UnityGUIExt.CreateButton(33.0f, 35.0f, 100.0f, 50.0f, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "EXIT"); float fButtonHeight = 35.0f; float fStartModes = 241.0f; float fStartRounds = 378.0f; m_oRounds3 = UnityGUIExt.CreateButton(33.0f, fStartRounds, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "3 Rounds"); m_oRounds6 = UnityGUIExt.CreateButton(33.0f, fStartRounds - fButtonHeight, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "6 Rounds"); m_oRounds9 = UnityGUIExt.CreateButton(33.0f, fStartRounds - fButtonHeight - fButtonHeight, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "9 Rounds"); m_oNormalButton = UnityGUIExt.CreateButton(33.0f, fStartModes, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "Normal"); m_oRandomButton = UnityGUIExt.CreateButton(33.0f, fStartModes - fButtonHeight, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "Random"); m_oWTFButton = UnityGUIExt.CreateButton(33.0f, fStartModes - fButtonHeight - fButtonHeight, 100.0f, fButtonHeight, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, "WTF"); }
void OnGUI() { int iY = m_iFontSize + 5; Rect rLabel = UnityGUIExt.CreateRect(0, iY, 0, 150, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE); foreach (CEventMessage tMsg in m_listMessages) { Color CColorOriginal = m_cFontStyle.normal.textColor; Color cColorTemp = m_cFontStyle.normal.textColor; if (tMsg.fTimeElapsed < m_fMessageLife - 1.0f) { cColorTemp.a = ((tMsg.fTimeElapsed) / (m_fMessageLife - 1.5f)) * m_cFontStyle.normal.textColor.a; } m_cFontStyle.normal.textColor = cColorTemp; GUI.Label(rLabel, tMsg.sMessage, m_cFontStyle); m_cFontStyle.normal.textColor = CColorOriginal; rLabel.y += iY; } }
public void DoGUI() { UpdateBox(m_fX, m_fY, m_fWidth, m_fHeight, m_eScreenAllignment, m_eAllignment); if (m_bSelected) { GUI.DrawTexture(UnityGUIExt.CreateRect(0, 0, 512, 512, UnityGUIExt.GUI_ALLIGN.BOT_LEFT, UnityGUIExt.GUI_ALLIGN.BOT_LEFT), m_tBackground); if (m_bDrawScroll) { m_oScrollbar.DoGUI(); } DrawTextBox(); } else { GUI.DrawTexture(UnityGUIExt.CreateRect(0, 0, 512, 512, UnityGUIExt.GUI_ALLIGN.BOT_LEFT, UnityGUIExt.GUI_ALLIGN.BOT_LEFT), m_tBackground2); } DrawChatBox(); }
void DrawGuiGameModes() { if (Network.isClient) { Server.EGameMode eGameMode = GameApp.GetInstance().GetServer().GetGameMode(); m_iGameModeSelected = (int)eGameMode; } int m_iCurrnetSelection = GUI.SelectionGrid(UnityGUIExt.CreateRect(120.0f, 10.0f, 100.0f, 100.0f, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT, UnityGUIExt.GUI_ALLIGN.BOT_RIGHT), m_iGameModeSelected, m_asGameModes, 1); if (Network.isServer && m_iCurrnetSelection != m_iGameModeSelected) { m_iGameModeSelected = m_iCurrnetSelection; GameApp.GetInstance().GetServer().SetGameMode(m_iGameModeSelected); } }
void OnGUI() { // Draw the back GUI.DrawTexture(UnityGUIExt.CreateRect(0, 0, 800, 188, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE), m_GameHUD); int iBorderWidth = 50; int iBorderHeight = 50; int iOffset = 2; int iIconStartX = -100; int iIconStartY = 57; // Draw the spells Rect rectSpellIcon = UnityGUIExt.CreateRect(iIconStartX, iIconStartY, iBorderWidth, iBorderHeight, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE); int iStartX = (int)rectSpellIcon.x; int iCol = 0; int iSpell = 0; CSpellData cData = GameApp.GetInstance().GetSpellDataComponent(); string[] asKeys = new string[(int)ESettings.SPELLS_MAX]; // asKeys[0] = "1"; // asKeys[1] = "2"; // asKeys[2] = "3"; // asKeys[3] = "4"; // asKeys[4] = "Q"; // asKeys[5] = "W"; // asKeys[6] = "E"; // asKeys[7] = "R"; asKeys[0] = " Q"; asKeys[1] = " W"; asKeys[2] = " E"; asKeys[3] = " R"; asKeys[4] = " A"; asKeys[5] = " S"; asKeys[6] = " D"; asKeys[7] = " F"; foreach (CSpell spell in m_acSpellBook) { if (spell == null) { continue; } if (spell.GetSpellType() == CSpell.EType.INVALID) { continue; } CSpellData.TSpellData tSpell = cData.GetSpellData(spell.GetSpellType()); string sSpellDesc = tSpell.sTitle + Environment.NewLine + "Level: " + GetSpell(spell.GetSpellType()).GetUpgradedLevel() + Environment.NewLine + tSpell.sDescription; GUI.DrawTexture(rectSpellIcon, cData.GetSpellData(spell.GetSpellType()).tTexture); if (rectSpellIcon.Contains(GameApp.GetInstance().GetCursor().GetScreenPosition())) { GUI.Label(UnityGUIExt.CreateRect(0, 50, 200, 200, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE), sSpellDesc); } // Draw Keys GUI.Label(rectSpellIcon, asKeys[iSpell]); Rect rectThisSpell = rectSpellIcon; if (spell.IsOnCooldown()) { GUI.DrawTexture(rectThisSpell, m_CooldownIconOverlay); rectThisSpell.y += rectThisSpell.height; rectThisSpell.height = rectSpellIcon.height * ((spell.GetCooldownTimer() - spell.GetCooldownLength()) / spell.GetCooldownLength()); if (rectThisSpell.height < 0.0f) { rectThisSpell.height *= -1.0f; } rectThisSpell.y -= rectThisSpell.height; GUI.DrawTexture(rectThisSpell, m_RefresherIconOverlay); } else if (m_bSpellSelected && iSpell == m_uiSelectedSpellId) { GUI.DrawTexture(rectThisSpell, m_SelectedIconOverlay); } rectSpellIcon.x += iOffset + iBorderWidth; ++iCol; if (iCol == 4) { rectSpellIcon.x = iStartX; rectSpellIcon.y += iOffset + iBorderHeight; } ++iSpell; } // Draw the borders over the spell Rect rectBorder = UnityGUIExt.CreateRect(iIconStartX, iIconStartY, iBorderWidth, iBorderHeight, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE, UnityGUIExt.GUI_ALLIGN.BOT_CENTRE); for (int i = 0; i < 2; ++i) { iStartX = (int)rectBorder.x; for (int j = 0; j < 4; ++j) { GUI.DrawTexture(rectBorder, m_SpellBorder); rectBorder.x += iOffset + iBorderWidth; } rectBorder.x = iStartX; rectBorder.y += iOffset + iBorderHeight; } // Draw the overlay // GUI.DrawTexture(UnityGUIExt.CreateRect(0, 0, 800, 188, // UnityGUIExt.GUI_ALLIGN.BOT_CENTRE, // UnityGUIExt.GUI_ALLIGN.BOT_CENTRE), m_GameHUDOverlay); }
void OnGUI() { if (m_eState == EState.ROUND_START_COUNTDOWN) { if (m_fCountdownTimer > 3.5f) { string sRoundText; if (m_uiRoundCount == GameApp.GetInstance().GetServer().GetNumberOfRounds()) { sRoundText = "Last Round!"; } else { sRoundText = "Round " + m_uiRoundCount; } GUIStyle cMyStyle = new GUIStyle(); cMyStyle.alignment = TextAnchor.MiddleCenter; cMyStyle.fontSize = 80; cMyStyle.normal.textColor = new Color(0.65f, 0.168f, 0.73f, 1.0f); float fBoxHeight = 40; float fBoxWidth = 10 * sRoundText.Length; float fPositionX = Screen.width / 2 - fBoxWidth / 2; float fPositionY = Screen.height / 2 - fBoxHeight / 2 - 100; GUI.TextField(new Rect(fPositionX, fPositionY, fBoxWidth, fBoxHeight), sRoundText, cMyStyle); } else if (m_fCountdownTimer > 2.5f) { GameApp.GetInstance().GetWarlock().GetComponent <CWarlockAnimator>().NotifyRevive(); GUI.DrawTexture(UnityGUIExt.CreateRect(0, -100, 256, 256, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE), m_tCountdown3); } else if (m_fCountdownTimer > 1.5f) { GUI.DrawTexture(UnityGUIExt.CreateRect(0, -100, 256, 256, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE), m_tCountdown2); } else if (m_fCountdownTimer > 0.5f) { GUI.DrawTexture(UnityGUIExt.CreateRect(0, -100, 256, 256, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE), m_tCountdown1); } else if (m_fCountdownTimer > 0.0f) { GUI.DrawTexture(UnityGUIExt.CreateRect(0, -100, 512, 512, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE_CENTRE), m_tCountdown0); } else { if (Network.isServer) { SetState(EState.FIGHTING); } } } m_cChat.DoGUI(); }
public void DoGUI() { DoGUI(UnityGUIExt.CreateRect(m_fX, m_fY, m_fWidth, m_fHeight, m_eScreenAllignment, m_eAllignment)); }
void ProcessServerListGUI() { ServerScanner.TServerInfo[] taOnlineServers = GetComponent <ServerScanner>().GetServerList(); if (taOnlineServers != null && taOnlineServers.Length > 0) { // This box contains the box that contains the server list. It acts as the parent to everything. m_rectServer = UnityGUIExt.CreateRect(-99.0f, 325.0f, 542.0f, 386.0f, UnityGUIExt.GUI_ALLIGN.TOP_CENTRE, UnityGUIExt.GUI_ALLIGN.CENTRE); Rect rectHostEntry = new Rect(0, 0, 543.0f, 95.0f); Rect rectHostName = new Rect(130, 11, 100.0f, 100.0f); Rect rectNumPlayers = new Rect(105, 53, 100.0f, 100.0f); // This box contains the list of servers // It is relatively positioned to the parent // The height is determined by the number of hosted games m_rectServersContainer = new Rect(0.0f, 0.0f, 525.0f, 0.0f); m_rectServersContainer.height = (taOnlineServers.Length * rectHostEntry.height); GUI.BeginScrollView(m_rectServer, m_v2ScrollPos, m_rectServersContainer); // Work out if a scroll bar is needed // If the box containing the server list is larger than the parent box then we need a scrollbar float fScrollbarSize = (m_rectServer.height / m_rectServersContainer.height); if (fScrollbarSize < 1.0f) { m_oScroller.Initialise(m_rectServer, m_rectServersContainer, m_rectServer.width - 15, 0, m_rectServer.height, fScrollbarSize * m_rectServer.height, m_v2ScrollPos); m_v2ScrollPos = m_oScroller.DoUpdate(); } // Grab the mouse pos and convert it into the parent box's space Vector2 vCursor = GameApp.GetInstance().GetCursor().GetScreenPosition(); vCursor.x -= m_rectServer.x; vCursor.y -= m_rectServer.y - m_v2ScrollPos.y; int i = 0; foreach (ServerScanner.TServerInfo tServerInfo in taOnlineServers) { // Draw the entry GUI.DrawTexture(rectHostEntry, m_HostEntry); GUI.Label(rectHostName, tServerInfo.sGameName); GUI.Label(rectNumPlayers, tServerInfo.uiNumConnectedPlayers + " / " + tServerInfo.uiPlayerLimit); // Check for selection if (rectHostEntry.Contains(vCursor)) { if (GameApp.GetInstance().GetCursor().IsMouseDown()) { m_iChosenServer = i; } // // Double click // // Does not function properly Event evMouse = Event.current; if (evMouse.isMouse && evMouse.clickCount == 2) { JoinGame(taOnlineServers[m_iChosenServer].saIp[0], m_strPlayerName); } } // Highlight the chosen server if (m_iChosenServer == i) { GUI.DrawTexture(rectHostEntry, m_tSelected); } // Increment to/for next entry rectHostEntry.y += rectHostEntry.height; rectHostName.y += rectHostEntry.height; rectNumPlayers.y += rectHostEntry.height; ++i; } // Store the IP of the chosen server if (m_iChosenServer != m_kiINVALID) { m_sChosenServer = taOnlineServers[m_iChosenServer].saIp[0]; } GUI.EndScrollView(); } }