Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - batman2142

Pages: [1]
1
NGUI 3 Support / Re: Poor Scrollview Performance
« on: November 29, 2017, 01:31:26 AM »
If the elements in the ScrollView are all of the same type, using a UIWrapContent with about 6-7 items (the minimum required to fill the screen + maybe a half visible element) will improve performance a ton. Use the OnInitializeItem callback to set the element's contents like sprites,labels,etc using the realIndex parameter.

2
NGUI 3 Support / Custom touch input for VR
« on: November 24, 2017, 03:31:34 AM »
I am trying to add support for VR controllers (using VRTK) by making a script similar to the TouchScript bridge script that you provided in this thread here: http://www.tasharen.com/forum/index.php?topic=4984.msg56678

My code:
  1.  
  2.     void OnPointerActivated(object sender, ControllerInteractionEventArgs e)
  3.     {
  4.         // Start tracking touches
  5.         UICamera.GetInputTouchCount = OnGetTouchCount;
  6.         UICamera.GetInputTouch = OnGetTouch;
  7.  
  8.         mTouches.Add(new UICamera.Touch()
  9.         {
  10.             phase = TouchPhase.Began,
  11.             fingerId = 0,
  12.             position = HoverPosition,
  13.             tapCount = 1
  14.         });
  15.     }
  16.  
  17.     void OnPointerHover(object sender, DestinationMarkerEventArgs e)
  18.     {
  19.         for (int index = 0; index < mTouches.size; ++index)
  20.         {
  21.             UICamera.Touch t = mTouches[index];
  22.  
  23.             if (t.fingerId == 0)
  24.             {
  25.                 var pointInScreenSpace = VRTK_DeviceFinder.HeadsetCamera().GetComponent<Camera>().WorldToScreenPoint(e.destinationPosition);
  26.                 t.position = new Vector2(pointInScreenSpace.x, pointInScreenSpace.y);
  27.                 t.phase = TouchPhase.Moved;
  28.                 HoverPosition = t.position;
  29.                 break;
  30.             }
  31.         }
  32.     }
  33.  
  34.     void OnPointerClicked()
  35.     {
  36.          for (int index = 0; index < mTouches.size; ++index)
  37.         {
  38.             UICamera.Touch t = mTouches[index];
  39.  
  40.             if (t.fingerId == 0)
  41.             {
  42.                 t.phase = TouchPhase.Ended;
  43.                 t.position = HoverPosition;
  44.                 break;
  45.             }
  46.         }
  47.     }
  48.  
  49.     void OnPointerDeactivated(object sender, ControllerInteractionEventArgs e)
  50.     {
  51.         // Stop tracking touches
  52.         mTouches.Clear();
  53.         UICamera.GetInputTouchCount = null;
  54.         UICamera.GetInputTouch = null;
  55.     }
  56.  
  57.     int OnGetTouchCount()
  58.     {
  59.         return mTouches.size;
  60.     }
  61.     UICamera.Touch OnGetTouch(int index)
  62.     {
  63.         return mTouches[index];
  64.     }
  65.  
  66.     void LateUpdate()
  67.     {
  68.         int index = 0;
  69.  
  70.         while (index < mTouches.size)
  71.         {
  72.             UICamera.Touch touch = mTouches[index];
  73.  
  74.             if (touch.phase == TouchPhase.Ended)
  75.             {
  76.                 mTouches.RemoveAt(index);
  77.             }
  78.             else
  79.             {
  80.                 touch.phase = TouchPhase.Moved;
  81.                 ++index;
  82.             }
  83.         }
  84.     }
  85.  

1. I have the touchPosition, that is a Camera.WorldToScreenPoint, and use it as touch.position when adding touches using UICamera.GetInputTouch and UICamera.GetInputTouchCount callbacks.
Could you tell me if there is something wrong in how I am adding the Touch events to mTouches and the reason why UICamera is not processing a touch once my TouchEnded touch has been added? Notice that I have changed fingerID of the touches to 0, since there is only 1 pointer I am using for now, would this be an issue?

2. I also tried making my own UICamera and replaced Input.mousePosition with HoverPosition and that did not work either.

3. There is OnCustomInput in UICamera but I could not find any resources on how to use it, could you please tell me how to go about it?

Pages: [1]