void drawP4Slot() { if (GUI.Button(P4SlotRect, ControllerSlotTexture, "")) { if (errorState == ErrorState.None) // if it's not in an error state { // Toggle selecting for the slot if (CurrentlySelecting == SelectingState.None) { if (Slot4Selection == ControllerSelectionState.None) { CurrentlySelecting = SelectingState.P4; // toggle } else { Slot4Selection = ControllerSelectionState.None; // reset slot } } else if (CurrentlySelecting == SelectingState.P4) { CurrentlySelecting = SelectingState.None; } } } }
void drawC4Icon() { if (Slot1Selection == ControllerSelectionState.C4) { GUI.DrawTexture(P1SlotRect, C4Texture); } else if (Slot2Selection == ControllerSelectionState.C4) { GUI.DrawTexture(P2SlotRect, C4Texture); } else if (Slot3Selection == ControllerSelectionState.C4) { GUI.DrawTexture(P3SlotRect, C4Texture); } else if (Slot4Selection == ControllerSelectionState.C4) { GUI.DrawTexture(P4SlotRect, C4Texture); } else // Draw it as a button if there's enough controllers, otherwise draw it as a texture { if (numOfControllers >= 4) { if (GUI.Button(C4SlotRect, C4Texture, "")) { if (errorState == ErrorState.None) // if it's not in an error state { if (CurrentlySelecting == SelectingState.P1) { Slot1Selection = ControllerSelectionState.C4; } else if (CurrentlySelecting == SelectingState.P2) { Slot2Selection = ControllerSelectionState.C4; } else if (CurrentlySelecting == SelectingState.P3) { Slot3Selection = ControllerSelectionState.C4; } else if (CurrentlySelecting == SelectingState.P4) { Slot4Selection = ControllerSelectionState.C4; } if (CurrentlySelecting != SelectingState.None) { CurrentlySelecting = SelectingState.None; } } } } else { GUI.DrawTexture(C4SlotRect, C4DarkTexture); } } }
/*******\ * START * \*******/ void Start() { int buttonHeight = (int)(Screen.height * 0.15); int buttonWidth = (int)((float)ControllerSlotTexture.width * ((float)buttonHeight / (float)ControllerSlotTexture.height)); // Set the width based on the height ratio int vertSpacing = (int)(Screen.height * 0.08); int horzSpacing = (int)((Screen.width - (buttonWidth * 4)) / 6); //Initialize the rect positions P1LabelRect = new Rect(horzSpacing, vertSpacing, buttonWidth, buttonHeight); P2LabelRect = new Rect(horzSpacing, vertSpacing * 2 + buttonHeight, buttonWidth, buttonHeight); P3LabelRect = new Rect(horzSpacing, vertSpacing * 3 + buttonHeight * 2, buttonWidth, buttonHeight); P4LabelRect = new Rect(horzSpacing, vertSpacing * 4 + buttonHeight * 3, buttonWidth, buttonHeight); P1SlotRect = new Rect(horzSpacing * 2 + buttonWidth, vertSpacing, buttonWidth, buttonHeight); P2SlotRect = new Rect(horzSpacing * 2 + buttonWidth, vertSpacing * 2 + buttonHeight, buttonWidth, buttonHeight); P3SlotRect = new Rect(horzSpacing * 2 + buttonWidth, vertSpacing * 3 + buttonHeight * 2, buttonWidth, buttonHeight); P4SlotRect = new Rect(horzSpacing * 2 + buttonWidth, vertSpacing * 4 + buttonHeight * 3, buttonWidth, buttonHeight); KB1SlotRect = new Rect(horzSpacing * 4 + buttonWidth * 2, vertSpacing, buttonWidth, buttonHeight); C1SlotRect = new Rect(horzSpacing * 4 + buttonWidth * 2, vertSpacing * 2 + buttonHeight, buttonWidth, buttonHeight); C3SlotRect = new Rect(horzSpacing * 4 + buttonWidth * 2, vertSpacing * 3 + buttonHeight * 2, buttonWidth, buttonHeight); SaveButtonRect = new Rect(horzSpacing * 4 + buttonWidth * 2, vertSpacing * 4 + buttonHeight * 3, buttonWidth, buttonHeight); KB2SlotRect = new Rect(horzSpacing * 5 + buttonWidth * 3, vertSpacing, buttonWidth, buttonHeight); C2SlotRect = new Rect(horzSpacing * 5 + buttonWidth * 3, vertSpacing * 2 + buttonHeight, buttonWidth, buttonHeight); C4SlotRect = new Rect(horzSpacing * 5 + buttonWidth * 3, vertSpacing * 3 + buttonHeight * 2, buttonWidth, buttonHeight); CancelButtonRect = new Rect(horzSpacing * 5 + buttonWidth * 3, vertSpacing * 4 + buttonHeight * 3, buttonWidth, buttonHeight); int errorHeight = Screen.height / 2; int errorWidth = (int)((float)Error1.width * ((float)errorHeight / (float)Error1.height)); ErrorRect = new Rect((Screen.width - errorWidth) / 2, (Screen.height - errorHeight) / 2, errorWidth, errorHeight); // Initialize the slot states by getting the storage object InitializeStorage storage = (InitializeStorage)GameObject.Find("VariableStorage").GetComponent(typeof(InitializeStorage)); InitializeStorage.ControllerSelection storedP1Controller = storage.P1Controller; InitializeStorage.ControllerSelection storedP2Controller = storage.P2Controller; InitializeStorage.ControllerSelection storedP3Controller = storage.P3Controller; InitializeStorage.ControllerSelection storedP4Controller = storage.P4Controller; Slot1Selection = (ControllerSelectionState)((int)storedP1Controller); Slot2Selection = (ControllerSelectionState)((int)storedP2Controller); Slot3Selection = (ControllerSelectionState)((int)storedP3Controller); Slot4Selection = (ControllerSelectionState)((int)storedP4Controller); numOfControllers = storage.numOfControllers; // Initialize the what the player is currently selecting CurrentlySelecting = SelectingState.None; errorState = ErrorState.None; }
void drawKB2Icon() { if (Slot1Selection == ControllerSelectionState.KB2) { GUI.DrawTexture(P1SlotRect, KB2Texture); } else if (Slot2Selection == ControllerSelectionState.KB2) { GUI.DrawTexture(P2SlotRect, KB2Texture); } else if (Slot3Selection == ControllerSelectionState.KB2) { GUI.DrawTexture(P3SlotRect, KB2Texture); } else if (Slot4Selection == ControllerSelectionState.KB2) { GUI.DrawTexture(P4SlotRect, KB2Texture); } else // Draw it as a button { if (GUI.Button(KB2SlotRect, KB2Texture, "")) { if (errorState == ErrorState.None) // if it's not in an error state { if (CurrentlySelecting == SelectingState.P1) { Slot1Selection = ControllerSelectionState.KB2; } else if (CurrentlySelecting == SelectingState.P2) { Slot2Selection = ControllerSelectionState.KB2; } else if (CurrentlySelecting == SelectingState.P3) { Slot3Selection = ControllerSelectionState.KB2; } else if (CurrentlySelecting == SelectingState.P4) { Slot4Selection = ControllerSelectionState.KB2; } if (CurrentlySelecting != SelectingState.None) { CurrentlySelecting = SelectingState.None; } } } } }