Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: deckard on November 16, 2012, 07:14:39 AM

Title: show panel with tween when the mouse over a 3d object
Post by: deckard on November 16, 2012, 07:14:39 AM
Hi,

What the method for showing a panel with tween (position & alpha) when the mouse cursor over a 3d object (target) ?
(http://img15.hostingpics.net/pics/989935tipTween.png)
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 16, 2012, 05:27:21 PM
SpringPosition to a position you calculate by transforming a 3D position to on-screen position.
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 18, 2012, 01:57:58 PM
Thank Aren !!!

How to hide the default panel? I disable with setactiverecursively() or other method ?
What is the method for display panel with animation ?
For show the panel when cursor over the 3d object, i use this script for example :
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class HoverObject : MonoBehaviour {
  5.  
  6.         void OnMouseOver() {
  7.                 Vector3 screenPos = cam.WorldToScreenPoint(this.transform.position);
  8.                 ??
  9.     }
  10. }
  11.  
  12.  


Thank you for your help, Ngui helps me a lot but I do not yet understand all the associated components
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 18, 2012, 04:15:01 PM
No need to convert to screen coordinates. SpringPosition works with world coordinates.
  1. SpringPosition.Begin(gameObjectToTween, targetWorldPos, strength);
...where 'strength' is how quickly it will spring into place. '1' means very slowly, '10' means pretty quickly, for example. '1000' would be instant.

Use NGUITools.SetActive() to enable/disable things.
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 19, 2012, 01:20:47 PM
Thank you  ;)
SpringPosition  gives a great animation!
I hide my tip and displays perfectly.
But the tip is moving in the same place (And not on the position of the cube)
Fault has the anchor?


  1. public class HoverObject : MonoBehaviour {
  2.         public ProductNGUITip tip;
  3.        
  4.         void OnMouseOver() {
  5.         tip.show(this.transform);
  6.     }
  7.        
  8.        
  9.  
  10. }

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ProductNGUITip : MonoBehaviour {
  5.        
  6.  
  7.         public GameObject mainPanel;
  8.        
  9.         public UILabel UI_name;
  10.         public UILabel UI_short_description;
  11.         public UILabel UI_description;
  12.         public UILabel UI_price;
  13.        
  14.  
  15.         [Range (0.2F, 3F)]
  16.         public float animDuration;
  17.         [Range (0F, 100F)]
  18.         public float animLenght;
  19.        
  20.         private bool isShow = false;
  21.        
  22.         void Start(){
  23.                 NGUITools.SetActive(mainPanel, false);
  24.         }
  25.  
  26.         public void show(Transform t){
  27.                
  28.                 if(isShow == false){
  29.                         isShow = true;
  30.                         NGUITools.SetActive(mainPanel, true);
  31.                         SpringPosition.Begin(mainPanel, t.position, 10F);
  32.                 }
  33.         }
  34.  
  35. }

(http://img2.uplood.fr/free/ow4r_2012-11-19_191950.png)
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 19, 2012, 05:04:56 PM
First of all, OnMouseOver is not a valid NGUI event. Use OnHover(bool isOver) instead.

Second, you need to pass UI's world coordinates. You currently use the object's world coordinates, which is wrong.

Convert from world space to screen space, set Z to 0, then convert back to world space to get the UI coordinate.
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 20, 2012, 04:38:30 AM
Hi Aren,

Sorry because I do not understand :(
It is better but I have a error message :
Screen position out of view frustrum

  1.         public void show(Transform target){
  2.                
  3.                 if(isShow == false){
  4.                         isShow = true;
  5.                         NGUITools.SetActive(mainPanel, true);
  6.                         Vector3 screenPos = camera.WorldToScreenPoint(target.position);
  7.                         screenPos.y = Screen.height-screenPos.y;
  8.                         screenPos.z = 0;
  9.                         SpringPosition.Begin(mainPanel, screenPos, 10F);
  10.                 }
  11.         }

for "camera.WorldToScreenPoint", the camera is the one that belongs UI root or main scene ?
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 20, 2012, 12:30:36 PM
Always the same error message.
I tried with both cameras to calculate WorldToScreenPoint :(
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 20, 2012, 03:28:41 PM
  1. Vector3 pos = gameCamera.WorldToScreenPoint(target.position);
  2. pos.z = 0f;
  3. pos = uiCamera.ScreenToWorldPoint(pos);
  4. SpringPosition.Begin(mainPanel, pos, 10f);
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 20, 2012, 04:16:16 PM
Sorry, same problem :(

(http://data.imagup.com/12/1168111911.jpg)

A problem in the hierarchy?
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 20, 2012, 04:23:51 PM
What does this have to do with mouse events?
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 20, 2012, 05:45:09 PM
This is when I'm over the cube to display the panel

You say :
"First of all, OnMouseOver is not a valid NGUI event. Use OnHover(bool isOver) instead."

But the event is on a gameobject that has nothing to do with the UI Root.
It is a cube.

  1. void OnMouseOver() {
  2.         tip.show(this.transform);
  3. }

I can not use NGUI event on elements which is not NGUI object?
Title: Re: show panel with tween when the mouse over a 3d object
Post by: ArenMook on November 20, 2012, 05:59:22 PM
NGUI event system can be used with anything. As long as the camera that sees the object has a UICamera script on it, that object will receive events (assuming it has a collider).
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 20, 2012, 06:01:46 PM
Ok!
Sorry I did not understand before!
I test and I'll let you know!
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 21, 2012, 05:03:05 AM
Hi !

I did work the NGUIevents.
I had to add a UICamera script on my main camera.

  1. void OnHover(bool b) {
  2.         if(b==true)tip.show(this.transform);
  3.     }

  1.         public void show(Transform target){
  2.                
  3.                 if(isShow == false){
  4.                         isShow = true;
  5.                         NGUITools.SetActive(mainPanel, true);
  6.  
  7.                         Vector3 pos = World_camera.WorldToScreenPoint(target.position);
  8.                         pos.z = 0f;
  9.                         pos = UI_camera.ScreenToWorldPoint(pos);
  10.                         SpringPosition.Begin(mainPanel, pos, 10f);
  11.                 }
  12.                
  13.         }
but still this error message :

Screen position out of view frustum (screen pos 60.000000, 501.000000) (Camera rect 0 0 991 591)
UnityEngine.Camera:INTERNAL_CALL_ScreenPointToRay(Camera, Vector3&)
UnityEngine.Camera:ScreenPointToRay(Vector3) (at C:\BuildAgent\work\812c4f5049264fad\Runtime\ExportGenerated\Editor\UnityEngineCamera.cs:291)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32) (at C:\BuildAgent\work\812c4f5049264fad\Runtime\Export\MouseEvents.cs:71)

Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 21, 2012, 05:38:20 AM
If I disables this code :
  1. NGUITools.SetActive(mainPanel, true);
  2.  
  3.             Vector3 pos = World_camera.WorldToScreenPoint(target.position);
  4.             pos.z = 0f;
  5.             pos = UI_camera.ScreenToWorldPoint(pos);
  6.             SpringPosition.Begin(mainPanel, pos, 10f);

The error is still there!
It happens when the mouse enters the Game window
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on November 21, 2012, 09:00:39 AM
It Works :D

We must change the SpringPosition.worldSpace  to true !

  1. Vector3 pos = World_camera.WorldToScreenPoint(target.position);
  2.                         pos.z = 0f;
  3.                         pos = UI_camera.ScreenToWorldPoint(pos);
  4.                         SpringPosition sp = SpringPosition.Begin(mainPanel, pos, 10f);
  5.                         sp.worldSpace = true;


I'm happy, thank you for your help and your responsiveness!
Title: Re: show panel with tween when the mouse over a 3d object
Post by: lime-green.at on December 04, 2012, 06:18:55 AM
Im currently working on the exact same thing, would you mind uploading your demo project with the working solution?
regards
Title: Re: show panel with tween when the mouse over a 3d object
Post by: lime-green.at on December 05, 2012, 01:32:00 AM
Hey,

i managed to get the script running, my result now looks like: (http://s3.imgimg.de/uploads/Capture9c077cb1PNG.png)
My sprite got its pivot top-left, the only thing i need to solve is how to get the window not to clip to the center but to the top right point of the cube, got any suggestions for me?

Regards
Title: Re: show panel with tween when the mouse over a 3d object
Post by: deckard on December 05, 2012, 05:17:40 AM
Hi!

Sorry I did not see your message.
When I have time I'll make you a small example!