Author Topic: Using UICamera.Raycast with current touch with Photon  (Read 5561 times)

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Using UICamera.Raycast with current touch with Photon
« on: September 01, 2014, 08:59:41 AM »
So i am using photon for a multiplayer game in conjunction with NGUI and i currently doing the following with a class that inherits from UIDragDropItem.

  1.         [RPC]
  2.         public void RPCDragDropRelease( Vector2 touchPos )
  3.         {
  4.                 Debug.Log("RPC DRAG RELEASED at" + touchPos);
  5.  
  6.                 RaycastHit lastHit;
  7.                 UICamera.Raycast(touchPos, out lastHit);
  8.        
  9.                 GameObject go = lastHit.transform.gameObject;
  10.  
  11.                 base.OnDragDropRelease (go);
  12.                
  13.                 count = 0;
  14.                 hasShrunkFlag = false;
  15.                 isDragging = false;
  16.                
  17.                 UIDragDropContainer container = UICamera.hoveredObject ? NGUITools.FindInParents<UIDragDropContainer>(go) : null;
  18.                
  19.                 if (container != null)
  20.                 {
  21.                         WCGrid grid = NGUITools.FindInParents<WCGrid>(transform);
  22.                        
  23.                         if(mGrid)
  24.                         {
  25.                                 WCCard card = gameObject.GetComponent<WCCard>();
  26.                                
  27.                                 //HACK
  28.                                 //                              if(NGUITools.FindInParents<GridSpace>(grid.gameObject) != null)
  29.                                 //                              {
  30.                                 //                                      card.gridNominatedID = NGUITools.FindInParents<GridSpace>(grid.gameObject).gridID;
  31.                                 //                              }
  32.                                
  33.                                 grid.CardDroppedIntoGrid(card);
  34.                         }
  35.                 }
  36.  
  37.                 //HACK HACK HACK
  38.                 WCStateManager.Instance.State().GetComponentInChildren<WCMessage>().gameObject.SetActive(true);
  39.         }
  40.  

i have tried sending it the uicamera.current touch and last touch and it does not seem to any object...it's null most the time. Am i using the Raycast the correct way?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #1 on: September 01, 2014, 02:27:47 PM »
UICamera.current is only valid during NGUI's event callbacks such as OnClick, OnPress, etc. You shouldn't send a Vector2 position via an RFC, as network states of each player's objects may differ quite a bit. Instead you should send the ID of the object.

With TNet it would be trivial. In OnClick you have UICamera.currentTouch.current to work with, on which you GetComponent<TNObject>(), and then just send its ID. In the RFC (what TNet calls RPCs) you just TNObject.Find(id) and do what you wish. With Photon... I'm not sure. However you identify things.

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #2 on: September 01, 2014, 10:02:14 PM »
This part of the game is partly turned based, one player is dragging an object around the screen and the other player is observing it...As far the object being dragged they sync up quite nicely, the issue is when i release it and where it reparents to a drag and drop container on the player who was moving the object correctly, it does not seem to do so for the person who receives the RPC in the original post. My line of thought was i could send the current touch of the player who released the object currently being show to move on both screens...Failing that could i use the object's center as the position? again i do not see why not as it's matched up on both screens, so i imagined i was using UICamera.Raycast incorrectly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #3 on: September 02, 2014, 12:13:46 PM »
I can't tell you why it's not working. I can only tell you how to do it properly, and it's to not send positions and instead send the result.

P.S. This is really not an NGUI question at all.

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #4 on: September 02, 2014, 09:59:39 PM »
Well it's sort of an amalgamation, my mine issue is/was with usage of UICamera.Raycast(touchPos, out lastHit); as that was not returning the object on the other client...for now i have circumvented it as luckily the objects i was trying to get have static constant Id's across all builds so i just send and RPC with the ID of the object to get it directly rather than via UICamera.RayCast();

I would like to say case closed, go home everyone. But I can't help but think what if i need for some odd reason to revisit using UICamera.Raycast sending coordinates across? From your prior responses i assume that you would say i need to restructure the code if i encounter this problem?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #5 on: September 03, 2014, 11:40:15 AM »
As I mentioned, UICamera's stuff is only valid during NGUI callbacks. You can get something in OnClick on one PC, but when the other PC gets the RPC, it won't be inside OnClick anymore, will it? So the UICamera's current values will not be valid.

Genhain

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 38
    • View Profile
Re: Using UICamera.Raycast with current touch with Photon
« Reply #6 on: September 03, 2014, 09:55:50 PM »
Okay i think i get the gist of it thanks aren