Author Topic: show panel with tween when the mouse over a 3d object  (Read 12085 times)

deckard

  • Guest
show panel with tween when the mouse over a 3d object
« 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) ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #1 on: November 16, 2012, 05:27:21 PM »
SpringPosition to a position you calculate by transforming a 3D position to on-screen position.

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #2 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #3 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.

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #4 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. }

« Last Edit: November 19, 2012, 01:43:47 PM by deckard »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #5 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.

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #6 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 ?

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #7 on: November 20, 2012, 12:30:36 PM »
Always the same error message.
I tried with both cameras to calculate WorldToScreenPoint :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #8 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);

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #9 on: November 20, 2012, 04:16:16 PM »
Sorry, same problem :(



A problem in the hierarchy?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #10 on: November 20, 2012, 04:23:51 PM »
What does this have to do with mouse events?

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #11 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: show panel with tween when the mouse over a 3d object
« Reply #12 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).

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #13 on: November 20, 2012, 06:01:46 PM »
Ok!
Sorry I did not understand before!
I test and I'll let you know!

deckard

  • Guest
Re: show panel with tween when the mouse over a 3d object
« Reply #14 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)