Author Topic: NGUI local multiplayer (multiple UICamera.selectedObject)  (Read 3118 times)

tremor_al

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
NGUI local multiplayer (multiple UICamera.selectedObject)
« on: February 25, 2014, 02:20:49 PM »
hello, im working on a local multiplayer kart game, as input im using 4 360 controllers. everything worked fine until i got to the point of the "character selection screen" where im supposed to read the simultaneous inputs of the 4 pads.
first i already created my own version of the "uibutton keys" script to accommodate which player it is listening to.
however the big problem comes when determinating the current selection as the Camera script only supports one selected object at a time it overwrites the others making a mess

any idea of how to solve this?

btw Im using JISyed "Unity-XboxCtrlrInput" in case anyone wants to check it out
https://github.com/JISyed/Unity-XboxCtrlrInput

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI local multiplayer (multiple UICamera.selectedObject)
« Reply #1 on: February 25, 2014, 03:05:25 PM »
You'll need to modify the UICamera to support that. Either that, or don't let 4 different controls to occur at once. Treat all 4 as one controller when on your menu.

tremor_al

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: NGUI local multiplayer (multiple UICamera.selectedObject)
« Reply #2 on: February 26, 2014, 01:40:05 AM »
mmm ok i was afraid of that, any tips on how to achieve it?, i´ve been poking in the uicamera script changing almost everything that has to do with controller and mcurrenselection, mnextselection but it just wont work.

this is the juicy part of my uibuttonxbox script

 
  1. void GetInput()
  2.         {
  3.                 if (NGUITools.GetActive (this) && UICamera.selectedObject == this.gameObject) {
  4.                         //izquierda
  5.                         if(XCI.GetDPad(XboxDPad.Left, player) && !DPadLeft) {  //Si no se habia presionado previamente y el boton indica estar presionado == ButtonDown
  6.                                 DPadLeft = true;
  7.                         }
  8.                         if(!XCI.GetDPad(XboxDPad.Left, player) && DPadLeft) {  //Si se habia presionado previamente, pero ahora el boton no esta presionado == ButtonRelease
  9.                                 DPadLeft = false;
  10.                                 if (NGUITools.GetActive(selectOnLeft)) UICamera.selectedObject = selectOnLeft.gameObject;
  11.                         }
  12.                         //derecha
  13.                         if(XCI.GetDPad(XboxDPad.Right, player) && !DPadRight){
  14.                                 DPadRight = true;
  15.                         }
  16.                         if(!XCI.GetDPad(XboxDPad.Right,player) && DPadRight){
  17.                                 DPadRight = false;
  18.                                 if (NGUITools.GetActive(selectOnRight)) UICamera.selectedObject = selectOnRight.gameObject;
  19.                         }
  20.                         //arriba
  21.                         if(XCI.GetDPad(XboxDPad.Up, player) && !DPadUp){
  22.                                 DPadUp = true;
  23.                         }
  24.                         if(!XCI.GetDPad(XboxDPad.Up, player) && DPadUp){
  25.                                 DPadUp = false;
  26.                                 if (NGUITools.GetActive(selectOnUp)) UICamera.selectedObject = selectOnUp.gameObject;
  27.                         }
  28.                         //abajo
  29.                         if(XCI.GetDPad(XboxDPad.Down, player) && !DPadDown){
  30.                                 DPadDown = true;
  31.                         }
  32.                         if(!XCI.GetDPad(XboxDPad.Down,player) && DPadDown){
  33.                                 DPadDown = false;
  34.                                 if (NGUITools.GetActive(selectOnDown)) UICamera.selectedObject = this.selectOnDown.gameObject;
  35.                         }
  36.  
  37.                         //Boton A
  38.                         if(XCI.GetButton(XboxButton.A,player) && !ButtonA){
  39.                                 ButtonA=true;
  40.                         }
  41.                         if(!XCI.GetButton(XboxButton.A,player) && ButtonA){
  42.                                 ButtonA = false;
  43.                                 OnClick();
  44.                         }
  45.                 }
  46.         }

so i dont think i should tinker everything in the uicamera script, just the part about selectedobject, setselection and changeselection.... or should i?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI local multiplayer (multiple UICamera.selectedObject)
« Reply #3 on: February 26, 2014, 03:33:04 PM »
Easiest way to go would be not to use the UICamera.selectedObject at all. Instead have your own input manager that keeps track of 4 "selection" values. Also instead of UIButton that uses UICamera.selectedObject, write a component that will use the custom input manager's values you wrote.