Author Topic: NGUI Rewired integration? (question from a non-coder...)  (Read 2808 times)

Alverik

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
NGUI Rewired integration? (question from a non-coder...)
« on: April 25, 2016, 12:06:44 AM »
Hi everyone! I've been checking NGUI and I really want to get it. I've watched the videos, and I can see it makes so many tasks so much easier, and it's so much more powerful than UGUI, but I'm not a coder and I notice there isn't an integration with rewired :-\.

In the current game I'm designing I'm going to be using Rewired + dialogue system + Adventure creator, and I wanted to use NGUI too (through the dialogue system), which takes me back to my issue... if so, how would I go about connecting NGUI to Rewired? I know theres a topic which shows code to use NGUI with the Incontrol Plugin (http://www.tasharen.com/forum/index.php?topic=13047.0). I have read it, but I'm sorry to admit that's just way too advanced for me. I barely understand what's going on in the code :'(...

So, I wanted to know if there's a better example for the integration, or one with little code to change... (I've used rewired's player.GetAxis/get buttons but that doesn't seem like it's going to work for this)... anyway, I'm sorry, I know I'm being a bit spoiled, but the main reason I've chosen to use plugins IS that I don't want to program more than what's really necessary, cause I'm not much of a coder...

Again, sorry for the trouble, and thanks in advance for any advice on this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Rewired integration? (question from a non-coder...)
« Reply #1 on: April 25, 2016, 12:57:18 PM »
NGUI's input is completely customizeable. As shown in the post you linked, NGUI uses delegates for events that you can overwrite from anywhere. This code in OnEnable for example:
  1. UICamera.GetKey = GetKey;
  2. UICamera.GetKeyDown = GetKeyDown;
  3. UICamera.GetKeyUp = GetKeyUp;
  4. UICamera.GetAxis = GetAxis;
...simply means that instead of the default GetKey / GetKeyDown / GetKeyUp / GetAxis functions, use custom ones. Since you can do whatever you want in those custom functions, what happens is ultimately up to you. In the script in that post, I simply redirected input to query InControl's states instead of using Unity's Input.GetXXX functions.

You can probably contact Rewired's devs and point them to that same topic you linked and they should be able to create a similar script that redirects input to their own code easily.

diederik

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 31
    • View Profile
Re: NGUI Rewired integration? (question from a non-coder...)
« Reply #2 on: September 06, 2016, 06:49:17 AM »
Hi all,

Just wanted to let you know that I have managed to get Rewired working with NGUI.
Using Unity 5.4, NGUI 3.10.0 and Rewired 1.0.0.97

Below you find the code I'm using. I removed some stuff, since I'm primarily using it for menu navigation.
* You need to set up the actions for the system player in the Rewired Input Manager.
* You need to set up a joystick map, to create elements (buttons) and map them to the actions.
* You need to set up a keyboard map in a similar way.
* You need to make sure the system player has these maps assigned and enabled.
* The system player of course needs to have a active controller assigned, otherwise it won't work!
* I created a UIControl behavior with high Digital Sensitivity and Gravity (10000), which I'm using for the actions.
* You need to have this script running on a gameobject.
* You DO need to have Horizontal and Vertical axes defined in the Unity input manager, and have them set in UICamera script on the UI Camera.
* Some other weird stuff I forgot :(.
Diederik / Xform

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class RewiredNGUI : MonoBehaviour
  5. {
  6.         // Rewired Button Actions
  7.         private static string _actionBottomRow1 = "UISubmit";
  8.         private static string _actionBottomRow2 = "UICancel";
  9.  
  10.         // Rewired Axis Actions
  11.         private static string _leftStickX = "Horizontal";
  12.         private static string _leftStickY = "Vertical";
  13.  
  14.         private static string _dPadX = "UIHorizontal";
  15.         private static string _dPadY = "UIVertical";
  16.  
  17.  
  18.         void Start ()
  19.         {
  20.                 UICamera.GetKey = GetKey;
  21.                 UICamera.GetKeyDown = GetKeyDown;
  22.                 UICamera.GetKeyUp = GetKeyUp;
  23.                 UICamera.GetAxis = GetAxis;
  24.         }
  25.  
  26.         static bool GetKeyDown (KeyCode key)
  27.         {
  28.                 if (key >= KeyCode.JoystickButton0)
  29.                 {
  30.                         Rewired.Player rewiredSystemPlayer = Rewired.ReInput.players.GetSystemPlayer(); // Done every time this is called???
  31.  
  32.                         switch (key)
  33.                         {
  34.                         case KeyCode.JoystickButton0: return rewiredSystemPlayer.GetButtonDown(_actionBottomRow1);        // Action bottom row 1 (Xbox "A" button, for instance)
  35.                         case KeyCode.JoystickButton1: return rewiredSystemPlayer.GetButtonDown(_actionBottomRow2);        // Action bottom row 2 (Xbox "B" button, for instance)
  36.                         }
  37.                 }
  38.                 return false;
  39.         }
  40.  
  41.         static bool GetKey (KeyCode key)
  42.         {
  43.                 if (key >= KeyCode.JoystickButton0)
  44.                 {
  45.                         Rewired.Player rewiredSystemPlayer = Rewired.ReInput.players.GetSystemPlayer(); // Done every time this is called???
  46.  
  47.                         switch (key)
  48.                         {
  49.                         case KeyCode.JoystickButton0: return rewiredSystemPlayer.GetButton(_actionBottomRow1);        // Action bottom row 1 (Xbox "A" button, for instance)
  50.                         case KeyCode.JoystickButton1: return rewiredSystemPlayer.GetButton(_actionBottomRow2);        // Action bottom row 2 (Xbox "B" button, for instance)
  51.                         }
  52.                 }
  53.                 return false;
  54.         }
  55.  
  56.         static bool GetKeyUp (KeyCode key)
  57.         {
  58.                 if (key >= KeyCode.JoystickButton0)
  59.                 {
  60.                         Rewired.Player rewiredSystemPlayer = Rewired.ReInput.players.GetSystemPlayer(); // Done every time this is called???
  61.  
  62.                         switch (key)
  63.                         {
  64.                         case KeyCode.JoystickButton0: return rewiredSystemPlayer.GetButtonUp(_actionBottomRow1);        // Action bottom row 1 (Xbox "A" button, for instance)
  65.                         case KeyCode.JoystickButton1: return rewiredSystemPlayer.GetButtonUp(_actionBottomRow2);        // Action bottom row 2 (Xbox "B" button, for instance)
  66.                         }
  67.                 }
  68.                 return false;
  69.         }
  70.  
  71.         static float GetAxis (string name)
  72.         {
  73.                 Rewired.Player rewiredSystemPlayer = Rewired.ReInput.players.GetSystemPlayer(); // Done every time this is called???
  74.  
  75.                 switch (name)
  76.                 {
  77.                 case "Horizontal": return rewiredSystemPlayer.GetAxis(_leftStickX) + rewiredSystemPlayer.GetAxis(_dPadX);
  78.                 case "Vertical": return rewiredSystemPlayer.GetAxis(_leftStickY) + rewiredSystemPlayer.GetAxis(_dPadY);
  79.                 }
  80.                 return 0;
  81.         }
  82.  
  83. }
  84.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Rewired integration? (question from a non-coder...)
« Reply #3 on: September 06, 2016, 10:32:05 AM »
Instead of using "Horizontal" and "Vertical" you should probably use UICamera.eventHandler.horizontalAxisName and UICamera.eventHandler.verticalAxisName. Other than that, thanks for sharing!