Author Topic: Easy Platform Detection?  (Read 3381 times)

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Easy Platform Detection?
« on: March 14, 2013, 03:45:59 PM »
Is there any built in platform detection in NGUI I can make use of? I've found that using Input.GetMouseDown(0) actually seems very slow in my custom ray casting so I've tried to switch completely to NGUI's system but am having a few problems.  The game is iOS and PC, so I am trying to get this to work on both platforms without actually processing the GetMouseDown ... I'm not sure if currentTouchID == -1 is just as slow or not, perhaps.

Should I be using Unity's Application.platform and writing 2 input methods independently?

  1.        
  2. //ensure game isnt paused before allowing clicking on the screen colliders
  3. if(!areaTimer.gamePaused) {
  4.         if(UICamera.currentTouchID == -1 || UICamera.currentTouch.touchBegan) {
  5.                 if(UICamera.hoveredObject) {
  6.                         hitObject = UICamera.hoveredObject.gameObject;
  7.                         string goTag = hitObject.tag;
  8.                                        
  9.                         //get the items clicked function depending on the tag and process the clicked method on the game object
  10.                         switch(goTag) {
  11.                                 case "Treasure":
  12.                                         hitObject.GetComponent<TreasureItem>().Clicked();
  13.                                         break;
  14.                                 case "Enemy":
  15.                                         hitObject.GetComponent<EnemyItem>().Clicked();
  16.                                         break;
  17.                                 case "EnemyProjectile":
  18.                                         //hitObject.GetComponent<EnemyProjectile>().Clicked();
  19.                                         break;                                         
  20.                                 default:
  21.                                         break;
  22.                         }
  23.                 }
  24.         }
  25. }
  26.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Easy Platform Detection?
« Reply #1 on: March 14, 2013, 04:09:13 PM »
You should not be mixing Input with NGUI's events. NGUI already does all the raycasts and input processing for you for basic events (mouse movement, presses, etc) -- so just use that. Look into UICamera.fallThrough and UICamera.genericEventHandler as well.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Easy Platform Detection?
« Reply #2 on: March 14, 2013, 04:14:05 PM »
I am using NGUIs UICamera input detection, but how would you detect if an object is swiped over on iOS without getting UICamera.hoveredObject or something similar?  Are you suggesting to use IsHovered() or something on the game objects themselves that need to respond to the touch hovering on top of the object on the screen?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Easy Platform Detection?
« Reply #3 on: March 14, 2013, 04:18:36 PM »
UICamera.genericEventHandler will receive OnDrag events that will let you determine when something is being swiped. I'm not an expert in this however -- and using FingerGestures might be a better option as it plays well with NGUI as far as I know.