private void Awake() { gui = FindObjectOfType <GUIOverlay>(); buttonFunctionUI = FindObjectOfType <UIButtonFunctions>(); inst = this; TurretTemplate.amplitude = 3; gameStateS = GameStates.started; gameState = gameStateS; currentMana = startingMana; gridSystem = GetComponent <GridSystem> (); waveSystem = GetComponent <WaveSystem>(); eventsManager = GetComponent <EventsManager>(); audioLibrary = GetComponent <AudioManager>(); worldSpaceCanvas = GameObject.Find("World Space Canvas").transform; townHall = GameObject.Find("Townhall").transform; projector = FindObjectOfType <OwnProjector>(); if (SceneManager.GetActiveScene().name == "Level 1") { tutorial = FindObjectOfType <TutorialManager>(); tutorialCanvasRC = tutorial.GetComponentInParent <GraphicRaycaster>(); } else { tutorial = null; tutorialCanvasRC = null; } }
// Base constructor for button using an solid rectangle with text and an outline, derived from above constructor public Button(UIButtonFunctions function, bool interact, bool visible, int startingX, int startingY, int width, int height, Brush backColor, string text, Font font, Brush textColor, StringFormat format, Brush lineColor, float lineWidth, Brush hoverColor) : this(function, interact, visible, startingX, startingY, width, height, backColor, text, font, textColor, format, hoverColor) { // Already documented previously OutlinePen = new Pen(lineColor, lineWidth); }
// Base constructor for button using an solid rectangle with text, uses constructor from base class with same purpose public Button(UIButtonFunctions function, bool interact, bool visible, int startingX, int startingY, int width, int height, Brush backColor, string text, Font font, Brush textColor, StringFormat format, Brush hoverColor) : base(interact, visible, startingX, startingY, width, height, backColor, text, font, textColor, format) { // Already documented previously ButtonFunction = function; AllowHover = (hoverColor == null) ? true : false; HoverColor = hoverColor; }
// Base constructor for button using an image, uses constructor from base class with same purpose. Constructor parameters have already been documented in the Widget parent class. public Button(UIButtonFunctions function, bool interact, bool visible, int startingX, int startingY, int width, int height, Image image, Brush hoverColor) : base(interact, visible, startingX, startingY, width, height, image) { // Set button function ButtonFunction = function; // Set the allow hover boolean to whether or not the hoverColor provided was null. If not null, true, if null, false AllowHover = (hoverColor != null) ? true : false; HoverColor = hoverColor; }
void Start() { cam = GetComponent <Camera> (); manaSys = GetComponent <ManaSystem> (); myRay = ManaSystem.inst.gui.GetComponent <GraphicRaycaster>(); uiButton = manaSys.buttonFunctionUI; if (SceneManager.GetActiveScene().name == "Level 1") { tut = manaSys.tutorial; } rocketLock = SceneManager.GetActiveScene().name == "Level 1" ? true : false; buildLock = SceneManager.GetActiveScene().name == "Level 1" ? true : false; buildMode = false; buildIndex = 0; }
// Constructor for button using an image with text and an outline, derived from above constructor. Has additional parameters for drawing an outline around the button. // Parameters include outline color of type Brush and outline width of type float. public Button(UIButtonFunctions function, bool interact, bool visible, int startingX, int startingY, int width, int height, Image image, string text, Font font, Brush textColor, StringFormat format, Brush lineColor, float lineWidth, Brush hoverColor) : this(function, interact, visible, startingX, startingY, width, height, image, text, font, textColor, format, hoverColor) { // Instantiate the button's outline pen to the provided outline color and outline width. OutlinePen = new Pen(lineColor, lineWidth); }
// Determines the current function of the button that was pressed. No return, takes in the function of a button of type UIButtonFunctions void ButtonFunctions(UIButtonFunctions btnFunction) { // Switch statement for determining actions for a given button function e.g. StartGame (case statements are self explanatory) switch (btnFunction) { case UIButtonFunctions.StartGame: // Initialize the UI's game menu InitializeUI(UIState.Game); // Set the game as started GameStart = true; break; case UIButtonFunctions.ViewTowers: // Hide first layer buttons gameWidgets[UIGameWidgets.VIEW_TOWERS].Visible = false; gameWidgets[UIGameWidgets.VIEW_TOWERS].Interactable = false; gameWidgets[UIGameWidgets.PAUSE].Visible = false; gameWidgets[UIGameWidgets.PAUSE].Interactable = false; gameWidgets[UIGameWidgets.SETTINGS].Visible = false; gameWidgets[UIGameWidgets.SETTINGS].Interactable = false; // Show second layer place tower buttons gameWidgets[UIGameWidgets.TOWER_1].Visible = true; gameWidgets[UIGameWidgets.TOWER_1].Interactable = true; gameWidgets[UIGameWidgets.TOWER_2].Visible = true; gameWidgets[UIGameWidgets.TOWER_2].Interactable = true; gameWidgets[UIGameWidgets.TOWER_3].Visible = true; gameWidgets[UIGameWidgets.TOWER_3].Interactable = true; // Show and instantiate close button for closing the tower select bar gameWidgets[UIGameWidgets.CLOSE_BARS].BoundingBox = new Rectangle(gameWidgets[UIGameWidgets.TOOL_BAR].BoundingBox.Location, gameWidgets[UIGameWidgets.CLOSE_BARS].BoundingBox.Size); gameWidgets[UIGameWidgets.CLOSE_BARS].Visible = true; gameWidgets[UIGameWidgets.CLOSE_BARS].Interactable = true; break; case UIButtonFunctions.Pause: break; case UIButtonFunctions.CloseBars: // Show first layer buttons gameWidgets[UIGameWidgets.VIEW_TOWERS].Visible = true; gameWidgets[UIGameWidgets.VIEW_TOWERS].Interactable = true; gameWidgets[UIGameWidgets.PAUSE].Visible = true; gameWidgets[UIGameWidgets.PAUSE].Interactable = true; gameWidgets[UIGameWidgets.SETTINGS].Visible = true; gameWidgets[UIGameWidgets.SETTINGS].Interactable = true; // Hide tower placement buttons gameWidgets[UIGameWidgets.TOWER_1].Visible = false; gameWidgets[UIGameWidgets.TOWER_1].Interactable = false; gameWidgets[UIGameWidgets.TOWER_2].Visible = false; gameWidgets[UIGameWidgets.TOWER_2].Interactable = false; gameWidgets[UIGameWidgets.TOWER_3].Visible = false; gameWidgets[UIGameWidgets.TOWER_3].Interactable = false; gameWidgets[UIGameWidgets.CLOSE_BARS].Visible = false; gameWidgets[UIGameWidgets.CLOSE_BARS].Interactable = false; break; case UIButtonFunctions.Settings: break; case UIButtonFunctions.Tower1: // Create new instance of placement using the current bounding box of the tower button and the size of a background tile placeTower = new Placement(gameWidgets[UIGameWidgets.TOWER_1].BoundingBox, background.tileSize); // Set the current tower being placed as the function of the tower button just clicked, allows UI to keep track of the current tower being placed currentTowerPlacement = (gameWidgets[UIGameWidgets.TOWER_1] as Button).ButtonFunction; break; case UIButtonFunctions.Tower2: // Same as tower 1, but for tower 2 placeTower = new Placement(gameWidgets[UIGameWidgets.TOWER_2].BoundingBox, background.tileSize); currentTowerPlacement = (gameWidgets[UIGameWidgets.TOWER_2] as Button).ButtonFunction; break; case UIButtonFunctions.Tower3: // Same as tower 1, but for tower 3 placeTower = new Placement(gameWidgets[UIGameWidgets.TOWER_3].BoundingBox, background.tileSize); currentTowerPlacement = (gameWidgets[UIGameWidgets.TOWER_3] as Button).ButtonFunction; break; case UIButtonFunctions.Restart: // Call the restart method from the Main class to restart the game Main.Restart(); break; default: break; } }