Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class setupcInput : MonoBehaviour {
- public GUISkin guiSkin;
- public Color menuColor;
- public bool MenuIsOpen;
- public static bool guiPanelOpen;
- Rect windowRect;
- float _wHeight = 5000;
- float _wWidth = 5000;
- bool showPopUp;
- private Vector2 _scrollPosition;
- private float _clickDelay = 0f;
- private string label2, box2, popwindow, smallbutton;
- void Awake() {
- // cInput setup
- // initialize cInput
- cInput.Init();
- // cInput default keys
- cInput.SetKey ("Interact", Keys.E);
- cInput.SetKey("Move Left", Keys.A, Keys.LeftArrow);
- cInput.SetKey("Move Right", Keys.D, Keys.RightArrow);
- cInput.SetKey("Move Forward", Keys.W, Keys.UpArrow);
- cInput.SetKey("Move Back", Keys.S, Keys.DownArrow);
- cInput.SetKey("Look Left", Keys.MouseLeft, Keys.Keypad4);
- cInput.SetKey("Look Right", Keys.MouseRight, Keys.Keypad6);
- cInput.SetKey("Look Up", Keys.MouseUp, Keys.Keypad8);
- cInput.SetKey("Look Down", Keys.MouseDown, Keys.Keypad2);
- cInput.SetKey("Attack", Keys.Mouse0, Keys.None);
- cInput.SetKey("Next Weapon", Keys.E, Keys.None);
- cInput.SetKey("Previous Weapon", Keys.Q, Keys.None);
- cInput.SetKey("Clear Weapon", Keys.Backspace, Keys.None);
- cInput.SetKey("Zoom", Keys.Mouse1, Keys.None);
- cInput.SetKey("Reload", Keys.R, Keys.None);
- cInput.SetKey("Jump", Keys.Space, Keys.None);
- cInput.SetKey("Crouch", Keys.C, Keys.None);
- cInput.SetKey("Run", Keys.LeftShift, Keys.RightShift);
- cInput.SetKey("Accept 1", Keys.Return, Keys.None);
- cInput.SetKey("Accept 2", Keys.KeypadEnter, Keys.None);
- cInput.SetKey("Pause", Keys.P, Keys.None);
- cInput.SetKey("Menu", Keys.Escape, Keys.None);
- cInput.SetKey("Toggle3rdPerson", Keys.V, Keys.None);
- // comment these out (or remove them) if you don't want these to show
- cInput.SetKey("Weapon 1", Keys.Alpha1, Keys.None);
- cInput.SetKey("Weapon 2", Keys.Alpha2, Keys.None);
- cInput.SetKey("Weapon 3", Keys.Alpha3, Keys.None);
- cInput.SetKey("Weapon 4", Keys.Alpha4, Keys.None);
- cInput.SetKey("Weapon 5", Keys.Alpha5, Keys.None);
- cInput.SetKey("Weapon 6", Keys.Alpha6, Keys.None);
- cInput.SetKey("Weapon 7", Keys.Alpha7, Keys.None);
- cInput.SetKey("Weapon 8", Keys.Alpha8, Keys.None);
- cInput.SetKey("Weapon 9", Keys.Alpha9, Keys.None);
- cInput.SetKey("Weapon 0", Keys.Alpha0, Keys.None);
- // here we make the horizontal and vertical axis out of the
- // "Move Left"/"Move Right" inputs and the "Move Back"/"Move Forward" inputs
- cInput.SetAxis("Horizontal", "Move Left", "Move Right");
- cInput.SetAxis("Vertical", "Move Back", "Move Forward");
- // and here we make the look axis
- cInput.SetAxis("HorizontalLook", "Look Left", "Look Right");
- cInput.SetAxis("VerticalLook", "Look Down", "Look Up");
- }
- void Update() {
- // show menu with escape
- if (Input.GetKeyDown(KeyCode.I) && !cInput.scanning) {
- MenuIsOpen = !MenuIsOpen;
- setupcInput.guiPanelOpen = MenuIsOpen;
- }
- }
- void OnGUI() {
- if (MenuIsOpen) {
- if (cInput.scanning) {
- _clickDelay = Time.realtimeSinceStartup + 0.15f;
- }
- GUI.skin = guiSkin;
- UpdateGUIColors();
- if (Screen.height - cGUI.windowMaxSize.y < 0) { _wHeight = Screen.height; } else { _wHeight = cGUI.windowMaxSize.y; }
- if (Screen.width - cGUI.windowMaxSize.x < 0) { _wWidth = Screen.width; } else { _wWidth = cGUI.windowMaxSize.x; }
- windowRect = new Rect((Screen.width - _wWidth) / 2, (Screen.height - _wHeight) / 2, _wWidth, _wHeight);
- //windowRect = GUILayout.Window(0, windowRect, MenuWindow, "");
- GUI.Window(0, windowRect, MenuWindow, "");
- if (showPopUp) {
- GUI.Window(1, new Rect((Screen.width - 512) / 2, (Screen.height - 350) / 2, 512, 350), popUp, "", popwindow);
- GUI.BringWindowToFront(1);
- GUI.FocusWindow(1);
- }
- }
- }
- void popUp(int windowID) {
- GUI.FocusWindow(1);
- GUI.TextField(new Rect(40, 100, 450, 95), "Please leave all analog inputs in their neutral positions.\n\nClick on OK when ready.");
- Rect _buttonRect = new Rect(150, 284, 200, 35);
- GUI.Button(_buttonRect, "OK", smallbutton);
- if (_buttonRect.Contains(Event.current.mousePosition) && Input.GetMouseButtonUp(0) && showPopUp) {
- cInput.Calibrate();
- showPopUp = false;
- }
- }
- void MenuWindow(int windowID) {
- if (!showPopUp) { GUI.FocusWindow(0); }
- GUI.backgroundColor = menuColor;
- #region left menu ---------------------------------------------
- float _buttonWidth = 128;
- float _buttonHeight = 35;
- float _lbuttonStartH = _wWidth / 26.5f;
- int _strvert = 7;
- if (cGUI.cSkin && cGUI.cSkin.name == "cGUISkin Dark") { _strvert = 6; }
- float _lbuttonStartV = _wHeight / _strvert;
- float _lbuttonEnd = _wHeight - (_wHeight / 6);
- float _lbuttonSpace = 50;
- int _showInt = 0;
- GUI.SetNextControlName("textarea"); // set button to active mode
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonStartV + (_lbuttonSpace * _showInt++), _buttonWidth, _buttonHeight), " INPUTS")) {
- // don't actually do anything because this one is already activated
- }
- GUI.FocusControl("textarea");
- if (cGUI.cAudioExists) {
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonStartV + (_lbuttonSpace * _showInt++), _buttonWidth, _buttonHeight), " AUDIO")) {
- cGUI.ShowAudioGUI();
- }
- }
- if (cGUI.cVideoExists) {
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonStartV + (_lbuttonSpace * _showInt++), _buttonWidth, _buttonHeight), " VIDEO")) {
- cGUI.ShowVideoGUI();
- }
- }
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonEnd - (_lbuttonSpace * 2), _buttonWidth, _buttonHeight), " CALIBRATE")) {
- showPopUp = true;
- }
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonEnd - (_lbuttonSpace), _buttonWidth, _buttonHeight), " DEFAULTS")) {
- cInput.ResetInputs(); // reset cInput to defaults
- }
- if (GUI.Button(new Rect(_lbuttonStartH, _lbuttonEnd, _buttonWidth, _buttonHeight), " EXIT")) {
- MenuIsOpen = !MenuIsOpen;
- setupcInput.guiPanelOpen = MenuIsOpen;
- }
- #endregion // left menu ---------------------------------------
- #region right menu (cInput) -----------------------------------
- float v_widthStartH1 = windowRect.width / 3;
- float v_widthStartH3 = windowRect.width / 1.8f;
- float v_widthStartV2 = windowRect.height / 9f;
- float v_space = 60;
- if (cGUI.cSkin) {
- label2 = "label";
- box2 = "box2";
- popwindow = "popwindow";
- smallbutton = "smallbutton";
- }
- else {
- label2 = "label";
- box2 = "box";
- popwindow = "window";
- smallbutton = "button";
- }
- Rect rightSideRect = new Rect(windowRect.width / 3.6f, v_widthStartV2 * 2.2f, windowRect.width * 0.67f, windowRect.height);
- // input settings
- GUI.Label(new Rect(rightSideRect.x + (rightSideRect.width / 2) - (_buttonWidth / 2), windowRect.height / 6.5f, _buttonWidth, _buttonHeight), "INPUT SETTINGS", label2);
- // GUI.Label(new Rect(windowRect.width * 0.57f, v_widthStartV1, _buttonWidth, _buttonHeight), "INPUT SETTINGS", label2);
- GUI.Label(new Rect(rightSideRect.x + (rightSideRect.width * 0.2f) - (_buttonWidth * 1.2f / 2), rightSideRect.y, _buttonWidth * 1.2f, _buttonHeight), "ACTION", label2);
- GUI.Label(new Rect(rightSideRect.x + (rightSideRect.width * 0.5f) - (_buttonWidth * 1.2f / 2), rightSideRect.y, _buttonWidth * 1.2f, _buttonHeight), "PRIMARY", label2);
- GUI.Label(new Rect(rightSideRect.x + (rightSideRect.width * 0.8f) - (_buttonWidth * 1.2f / 2), rightSideRect.y, _buttonWidth * 1.2f, _buttonHeight), "SECONDARY", label2);
- // scroll
- _scrollPosition = GUI.BeginScrollView(new Rect(v_widthStartH1, v_widthStartV2 * 3.0f, v_widthStartH3 * 1.1f, windowRect.height * 0.58f), _scrollPosition, new Rect(v_widthStartH1, 0, v_widthStartH3, v_space * (cInput.length - 13)));
- for (int n = 0; n < cInput.length; n++) {
- GUI.Label(new Rect(rightSideRect.x + (rightSideRect.width * 0.2f) - (_buttonWidth * 1.2f / 2), 0 + (_buttonHeight * n), _buttonWidth * 1.2f, _buttonHeight), cInput.GetText(n, 0), "label"); // name of input
- if (GUI.Button(new Rect(rightSideRect.x + (rightSideRect.width * 0.5f) - (_buttonWidth * 1.2f / 2), 0 + (_buttonHeight * n), _buttonWidth * 1.2f, _buttonHeight), cInput.GetText(n, 1), box2) && Input.GetMouseButtonUp(0)) {
- if (Time.realtimeSinceStartup > _clickDelay) {
- // only allow mouse axis on look axis
- if (n < 4 || n > 7) {
- cInput.ChangeKey(n, 1, false, true, true, true);
- }
- else { cInput.ChangeKey(n, 1, true, true, true, true, true); }
- print(cInput.GetText(n));
- }
- }
- if (GUI.Button(new Rect(rightSideRect.x + (rightSideRect.width * 0.8f) - (_buttonWidth * 1.2f / 2), 0 + (_buttonHeight * n), _buttonWidth * 1.2f, _buttonHeight), cInput.GetText(n, 2), box2)) {
- if (Time.realtimeSinceStartup > _clickDelay) {
- // only allow mouse axis on look axis
- if (n < 4 || n > 7) {
- cInput.ChangeKey(n, 2, false, true, true, true);
- }
- else { cInput.ChangeKey(n, 2, true, true, true, true, true); }
- print(cInput.GetText(n));
- }
- }
- }
- GUI.EndScrollView();
- #endregion //right menu ---------------------------------------
- }
- public void UpdateGUIColors() {
- GUI.backgroundColor = menuColor;
- Color _c = menuColor * 0.75f;
- if (guiSkin) {
- guiSkin.button.normal.textColor = _c;
- guiSkin.label.normal.textColor = _c;
- guiSkin.textField.normal.textColor = _c;
- guiSkin.textArea.normal.textColor = _c;
- for (int n = 0; n < 6; n++) { guiSkin.customStyles[n].normal.textColor = _c; }
- guiSkin.customStyles[1].normal.textColor = Color.white;
- guiSkin.customStyles[7].normal.textColor = Color.white;
- guiSkin.customStyles[6].normal.textColor = Color.white;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement