// Use this for initialization void Start() { if (ToolHoverImages == null) { Debug.LogError("GateHoverImages is null"); } // Necessary for detecting mouse clicks Physics.queriesHitTriggers = true; // Get the level manager and gates _LevelManager = GameObject.FindObjectOfType <LevelManager>(); _Gates = GameObject.FindObjectOfType <Gates>(); // Set the current tool for now CurrentTool = PlayerTool.PlaceGate; SelectedGate = GateSelection.AND; // Setup UI styles InputButtonStyle = new GUIStyle(); InputButtonStyle.normal.background = InputButtonTex; OutputButtonStyle = new GUIStyle(); OutputButtonStyle.normal.background = OutputButtonTex; CrossButtonStyle = new GUIStyle(); CrossButtonStyle.normal.background = CrossButtonTex; ToolboxButtonStyle = new GUIStyle(); ToolboxButtonStyle.normal.background = ToolboxButtonImage; ToolMiscStyle = new GUIStyle(); // Create preview line. Points will be set in the Update and OnGUI methods PreviewLine = new GameObject().AddComponent <LineRenderer>(); PreviewLine.transform.position = Vector2.zero; PreviewLine.material = WireMaterial; PreviewLine.startWidth = PreviewLine.endWidth = 0.005f; PreviewLine.startColor = PreviewLine.endColor = GateBehaviour.UnpoweredColour; PreviewLine.gameObject.SetActive(false); }
/// <summary> /// Handles the buttons for toolbox elements /// </summary> void HandleToolClick(bool IsGate, string ToolName, float UIScale, float ToolBaseX, int Position, Texture2D ToolImage) { // Draw the glowy pad thing GUI.DrawTexture(new Rect(ToolBaseX + 240f * UIScale * Position, 30f * UIScale, 240f * UIScale, 240f * UIScale), ToolboxButtonImage); // Assign the tool misc style's texture to the logic gate ToolMiscStyle.normal.background = ToolImage; ToolMiscStyle.hover.background = ToolHoverImages[Position]; ToolMiscStyle.active.background = ToolImage; // Draw button if (GUI.Button(new Rect(ToolBaseX + 40f * UIScale + 240f * UIScale * Position, 70f * UIScale, 160f * UIScale, 160f * UIScale), "", ToolMiscStyle)) { // Play sound PickupSound.Play(); // If we're clicking a gate, select it if (IsGate) { SelectedGate = GateSelectionFromGateName(ToolName); CurrentTool = PlayerTool.PlaceGate; } else { // Otherwise select a tool if (ToolName == "Wire") { CurrentTool = PlayerTool.CreateWire; } // Return to ship if (ToolName == "Ship") { _LevelManager.ViewingPanel = false; } } } }