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 - BIS

Pages: [1]
1
NGUI 3 Support / Re: Prevent Click Through
« on: November 03, 2014, 03:47:54 AM »
Hello everyone !
Recently encountered with the similar problem, two cameras (main camera and camera for UI) and UI is transparent for all mouse events.
Here is my solution:

Basic Ideas
1. Use static field with name hoveredObject from class UICamera.
When this field is not null it means that cursor is located over some NGUI object (NGUI object should have a collider of course), so check it and you can block all input processing in you scripts.
This approach works well for stand alone or web applications, but unfortunately when I  used it on mobile device with touch screen first touch never can be blocked. Another disadvantage of this method, you should add a special script for every object on you main scene to block the touches for this object over NGUI elements.
 
2. To solve issue for touch screens can be used other method: it is possible to write a special script attached to the NGUI object  that adds collider right front of the Main Camera scaled and positioned in space  by such way that this collider always covers NGUI object (actually rendered by the second NGUI camera).

Here is the demo with implementation of this ideas:
https://sites.google.com/site/bis153site/home/files/NGUIInputBlockingDemo_2014.11.03.zip

1. Scripts
Scripts/GUI/NGUIScriptBlocker.cs - implementetion of the first idea, scripts checks state of the field UICamera.hoveredObject and when it is not null disables all other scripts attached to the object.

Scripts/GUI/NGUIRayCastingBlocker.cs  - implementation of the second idea, script should be added to NGUI object, names for main and NGUI cameras can be set up in this script as parameters but when its empty scripts tries to find cameras automatically.

2. Demo description and instructions.
There are 2 scenes:
Scenes/Scene1 - base 3D scene
Scenes/Scene_GUI2 - 2D GUI

Open and run Scene1,  Scene_GUI2 will be downloaded and added by the MainProgram script.
There are color bars in the center, if you click on them then material becomes transparent. You can press left button of the mouse and orbit around the scene.
Scrip NGUIScriptBlocker.cs is attached to the Main Camera, in result when you try to press mouse button over the NGUI panel script CameraOrbitAndPinch.cs will be disabled and you can not orbit camera.
Script  NGUIRayCastingBlocker.cs is attached to the objects Sphere (orange dragable sphere in the left bottom cornert) and PanelBG (background for the right NGUI panel) on scene  Scene_GUI2.
Script adds  colliers visible for the Main Camera in Scene1 and this colliders always located in the same position (from the main camera point o view) as origibnal NGUI objects, so if you click on bar located under the right panel then this click will be blocked. Inspect objects with name "NGUIRayCastingBlocker for ..." to check this idea.

Demo works with free NGUI 2.7, if you are going to use this scripts it with NGUI 3.x then uncomment the first line in the scrip NGUIRayCastingBlocker.cs:
//#define NGUI_v3

Pages: [1]