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

Pages: 1 ... 3 4 [5] 6
61
Hi,

I had an AhHa moment and I wanted to share this pattern. I think it could be formalized further as well, but it is working.

In one script's Awake() (any script really, it doesn't matter which object is set as the Generic Event Listener)...
  1. UICamera.genericEventHandler = this.gameObject

Now any script can subscribe to an event using UIEventListener with UICamera's static access to genericEventListener...
  1. UIEventListener.Get(UICamera.genericEventHandler).onClick += this.OnClick;

In one script I also do a GameObject comparison with thefall-through gameObject to determine if I am getting a UI event or a fall-through event (because the genericEventHandler gets all events, including the fall-through).

If this is a valid workflow, I would highly recommend rolling this in to the core of nGUI. If necessary, nGUI could create a hidden GameObject to send Messages through and provide a reference for users (in addition to the genericEventHandler). It would only take a few minutes to implement this way. Perhaps it could be another method in the UIEventListener, or even an overload of Get(), when there is no argument.

62
NGUI 3 Support / Re: How to detect if mouse is clicking on NGUI area?
« on: July 22, 2012, 02:05:33 PM »
"hover object is always the fall-through game object" that makes no sense to me. Did you mean that in reverse?

I mean that whatever GameObject is set to UICamera.fallThrough is always returned by UICamera.hoveredObject when an event "falls through". I was hoping that UICamera.hoveredObject would always be the collider (GameObject) under the mouse. UICamera.fallThrough is already recieving the events. Having UICamera.hoveredObject returning the same thing isn't helpful (maybe it is helpful to non-fall-through recievers, but I thought I read earlier in this thread that you recommended UICamera.hoveredObject for the situation I am working with?)

Generally when dragging you should disable the collider of whatever you started dragging, or it will be intercepting events.

I am not dragging an object, I am dragging the mouse. The me explain better.... The OnClick() event is getting sent On-mouse-up no matter what. If I click and let go, I get the object that was clicked as expected. if I click, then drag the mouse over another collider, then let go, the new collider is returned. A click event should be interrupted, and not sent, when a drag event occurs after mouse-down, right?


Also when you can always modify UICamera.currentTouch.pressed game object to be something else, and that something else will receive your OnClick instead.

Cool trick, thanks!

63
NGUI 3 Support / Re: Event listener not doing anything...
« on: July 22, 2012, 06:01:37 AM »
Well it works. There was null reference exception (needed to drag&drop an unrelated reference used in the same script) that was quietly breaking this. Once I fixed it the tap started flowing again!

64
NGUI 3 Support / Event listener not doing anything...
« on: July 22, 2012, 04:23:21 AM »
Hi,

I think I am setting this up correctly:

  1.    
  2.     // In the class
  3.     public UIImageButton playButton;        
  4.  
  5.     // in Start()
  6.     UIEventListener.Get(this.playButton.gameObject).onClick += this.OnPlay;
  7.  
  8.     // My func definition
  9.     public void OnPlay(GameObject obj)
  10.     {
  11.         Debug.Log("OnPlay");
  12.     }
  13.    

  • The log message never plays and there are no error messages.
  • I attached a test script and the button IS getting an OnClick event
  • When I play the game no UIEventListener component is added to the gameObject. I tried adding one manually and it didn't have any effect.

Any thoughts?

65
NGUI 3 Support / Re: How to detect if mouse is clicking on NGUI area?
« on: July 22, 2012, 03:10:04 AM »
...continuing from my last post, I have it nearly working. The issue I am having is that OnClick is being called 'on mouse up' no matter what. I can click anywhere, drag around and OnClick is called when I let go.

  1. public class UIGameCamera : MonoBehaviour
  2. {
  3.     public LayerMask layers;
  4.     public bool debug = false;
  5.  
  6.     private Camera gameCam;
  7.  
  8.     private void Start()
  9.     {
  10.         this.gameCam = this.GetComponent<Camera>();
  11.         UICamera.fallThrough = this.gameObject;
  12.     }
  13.  
  14.     private void OnClick()
  15.     {        
  16.         // Can't select anything when the game is paused
  17.         if (Time.timeScale == 0) return;
  18.  
  19.         Ray ray = this.gameCam.ScreenPointToRay(UICamera.currentTouch.pos);
  20.         RaycastHit hit;
  21.         if (!Physics.Raycast(ray, out hit, Mathf.Infinity, this.layers))
  22.         {
  23.             Debug.Log("Nothing Clicked");
  24.             return;
  25.         }
  26.  
  27.         // Cache the transform of the object hit
  28.         Transform hitXform = hit.collider.transform;
  29.  
  30.         Debug.Log("Clicked " + hitXform.name);
  31.     }
  32.  
  33.     private void OnDrag(Vector2 delta)
  34.     {
  35.         Debug.Log("Dragging Camera");
  36.     }
  37. }
  38.  

66
NGUI 3 Support / Re: How to detect if mouse is clicking on NGUI area?
« on: July 22, 2012, 02:33:50 AM »
The issue is that the hover object is always the fall-through game object, and not the gameObject that is visible under the mouse. It seems like I have a couple of choices:

1) Use UICamera on all cameras. In this case there is no fall-through, but the hover-object is always good, so I would have to check the hover object's layer against the 2D camera layer to see if it is a 2D GUI hit or a 3D game camera hit

2) I can use a UICamera on just the 2D camera. Fall-through now works, but the hover object is always this hidden fall-through gameObject, not any of my objects, so I would have to use the nGUI pos to do a ray cast and see what gets hit.

I'm going with #2 since I already have the code to do this from the old system. I am interested if I am missing something here though.

67
NGUI 3 Support / Re: How to detect if mouse is clicking on NGUI area?
« on: July 21, 2012, 06:14:18 PM »
I have been mocking up some ideas but I still feel like I am missing some information. I think I have boiled it down to a specific need...

* My GUI camera (2D) will see things that need to be drag-and-drop. It also needs to block all events to the game, so if I click or drag on a button, the game doesn't receive any fall-through input.

* My game camera (3D) is controlled by dragging anywhere in the game. There are a lot of 3D GUI elements that receive clicks, but all drags in-game are for the camera (Our camera script is a special behaviour, so I need my current script.)

I tried to set this up by setting the 3D camera mask to nothing, or deleting it, but in both cases the fall-through hover object is "FallThrough EventHandler". Here is my debug log for the click from the code below:
  1. Clicked FallThrough EventHandler (UnityEngine.GameObject)
  2. UnityEngine.Debug:Log(Object)
  3. UIGameCamera:OnClick() (at Assets/Scripts/UI/UIGameCamera.cs:17)
  4. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  5. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:517)
  6. UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:957)
  7. UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:761)
  8. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:623)
Here is the simple test class I am using to try this out:
  1. public class UIGameCamera : MonoBehaviour
  2. {
  3.     private void Start()
  4.     {
  5.         UICamera.fallThrough = this.gameObject;
  6.     }
  7.  
  8.     private void OnClick()
  9.     {
  10.         Debug.Log("Clicked " + UICamera.hoveredObject);
  11.     }
  12.  
  13.     private void OnDrag(Vector2 delta)
  14.     {
  15.         Debug.Log("Dragging Camera");
  16.     }
  17. }

If I could get the object that is clicked, this would be done. If I am not doing anything wrong, and I need to do a quick raycast, that is fine. I just want to know I am following nGUI methodology and not trying to fight it.

Thanks a lot!


P.S. I bought through the Unity store because I didn't have anything in our PayPal account and the current free version isn't the latest version. I would have liked to buy direct.

68
Thanks for the reply. I'm beginning to see how I can adapt what I have to nGUI. This other thread helped and this discussion continues there:
http://www.tasharen.com/forum/index.php?topic=138.0


69
NGUI 3 Support / Re: How to detect if mouse is clicking on NGUI area?
« on: July 21, 2012, 02:06:53 AM »
I also have a question as I attempt this. I have at least three scripts on different objects that need to handle events. Are there any delegates I can use? Otherwise it seems like I need a separate gameobject to use as the fall through receiver with a script that exposes static event delegates for my other scripts. WDYT?

70
I'm looking for this as well. UIForwardEvents doesn't make sense when you want to listen to events that could hit many other objects. I have a feeling it will involve the UICamera static eventHandler but I'm still searching for any examples or discussion.

71
NGUI 3 Support / UIImageButton Disabled Sprite Image?
« on: July 18, 2012, 06:56:20 PM »
Hi,

Is there a way to display an image when the button is in a disabled state? I see:
normalSprite
hoverSprite
pressedSprite

I was hoping for
disabledSprite


Also, did I read correctly that the way to disable a button (still visible but no longer accepting input) is to disable the collider component?

Cheers,

72
NGUI 3 Support / Re: A better way than multiple cameras
« on: July 18, 2012, 06:43:10 PM »
Trust me when I say that multiple cameras is the best way. I've done it the other way and it isn't as fun to maintain.
  • More organized
  • The GUI doesn't fly around the scene parented to the main camera so it is easier to debug (lol)

Besides, wouldn't it help limit overdraw with transparent GUI elements? (Not sure, but seems logical to me).

73
NGUI 3 Support / Re: New User Install Notes
« on: July 18, 2012, 06:39:12 PM »
Your approach does not address the need to have the Editor folder outside the Plugins folder in order for it to work.
It is a sibling folder. The project hierarchy view would look like this when you submit to the AssetStore and choose "Assets":

(Assets)
 - AssetStoreTools     <-- Removed by Unity on submission
 - Plugins
 - - Tasharen
 - - - nGUI     <-- All non-editor files can go in here
 - Editor
 - - Tasharen
 - - - nGUI
 - nGUIExampleFiles     <-- easy to delete, optional to load (easy to find in load window). Not core files


Using our plugins as an example. If a user were to import PoolManager and TargetPRO (which includes UnityConstraints), they would get this (I'll assume they didn't import the example files to keep this shorter):

 - Plugins
 - - Pathological
 - - - PoolManager
 - - - TargetPRO
 - - - UnityConstraints
 - Editor
 - - Pathological
 - - - Common
 - - - PoolManager
 - - - TargetPRO
 - - - UnityConstraints


Another benefit I just remembered is that when the project is synced with an IDE like Visual Studio, it puts the files in the right assemblies for easy access.

FWIW I have actually seen other developers alter their projects to use this structure. They generally push up a half or full version though, since users need to take a manual step before upgrading (move the files to match, then import the new files, so Unity keeps track of the change and doesn't dump components on prefabs etc.)

74
NGUI 3 Support / Re: New User Install Notes
« on: July 18, 2012, 01:52:44 PM »
Just for completeness... It works fine with the AssetStore. In our plugin/middleware projects we just select the Assets folder and they automatically remove the AssetStoreTools folder. I've been doing it this way with all of our plugins for quite some time. It installs as expected and is very clean, works for JavaScript and C# and is really designed to be this way, so things run in the right order (Plugins first, etc). I have told the AssetStore guys to make this clear so many times but they haven't done so.

What is really nice, is that if you release a second plugin or extension, and have common code, you can put it in a folder and it will merge on import automatically. What I mean is, if you have these two pacakges to import:
- Assets
--- Plugins
----- Tasharen
------- Common
--------- SomeLib.cs
------- NGUI
--------- ...

and

- Assets
--- Plugins
----- Tasharen
------- Common
--------- SomeLib.cs
------- OtherPlugin
--------- ...

You end up with:
- Assets
--- Plugins
----- Tasharen
------- Common
--------- SomeLib.cs
------- NGUI
--------- ...
------- OtherPlugin
--------- ...

From a user standpoint it is more clear too, since all my plugins are in the plugins folder and their editors are in the same folder but under Editors.

The other nice thing is that you don't have to ask people to move files around, which makes installing updates kind of confusing.

I know this would be a big change. I am just sharing for information's sake. I learned this stuff over the last year+ as we released our three packages.

P.S. I know nGUI is not meant to be used side by side with EZGUI, but I needed both in my project as I switch over. I bet there aren't many users that would switch at such a late stage in their game, but it would have been nice to have a warning anyway. I didn't expect you to actually change your code. I simply refactored all the EZGUI types to have "EZ" before their names, then imported nGUI without issue.

Thanks again for nGUI. It is fabulous.

75
NGUI 3 Support / Re: eventReceiver For All Controls?
« on: July 18, 2012, 01:10:09 AM »
And then I find UIEventListener: http://www.tasharen.com/ngui/docs/class_u_i_event_listener.html
        UIEventListener.Get(this.playButton.gameObject).onClick += this.PlayButtonOnClick;

Awesome.

Pages: 1 ... 3 4 [5] 6