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

Pages: [1]
1
Thank you very much!

I looked into NGUI tools, but unfortunately miss this one.

2
Hello,

I have a Scrollview with a bunch of widgets inside. Each widget actually is a button which start associated game level.
I want to add visual effect when button clicked. E.g. moving and scaling its image and shadowing all other staff.

......
 |___ ShadowPanel (depth 1)
 |___ ScrollView panel (depth 0)
         |___ Grid
                   |_ Icon01
                    ......
                   |_ IconNN

So, I have to move IconXX from ScrollView to ShadowPanel (otherwise it will be shadowed, and dont be tweened properly), and when tween it somehow.
First, I did it in this way:

  1. IconTransform.SetParent(ShadowPanel.transform);
  2.  
  3. foreach (UIWidget widget in IconTransform.GetComponentsInChildren<UIWidget>())
  4. {
  5.    ShadowPanel.AddWidget(widget);
  6. }
  7.  

This one works almost fine for my needs - actually i see one icon staying at place and "new" instance doing tween things.
But if icon transform moves outside ScrollView rect (via scaling or changing position) - it "jump" back to scroll panel: i.e. become shadowed and affected by clipping.

Of course, I tried ScrollViewPanel.RemoveWidget, but in this case NGUI stop updating widget on screen.

I tried to use panel.Refresh, panel.RebuildDrawCalls and so on, but all this things doesnt matter at all.

So my question is simple - what I do wrong? :)

3
Hello,

I am trying to create chaining tweens attached to one gameobject:

TweenPosition -> TweenRotation from 0 to 90 -> TweenRotation from 90 to 180 (I have to separate rotation cause I need to do some things between)

When I did it via inspector all things work nice. But for some reasons it's better for me to create tweens in code.

I've tried it in this way:

  1. var rotate01 = TweenRotation.Begin (transform.gameObject, 0.3f, rotation90);
  2.  
  3. rotate01.delay = 0.99f;
  4. EventDelegate.Add (rotate01.onFinished, ReColor);
  5.  
  6. var rotate02 = TweenRotation.Begin (transform.gameObject, 0.3f, rotation180);
  7.  
  8. rotate02.from = new Vector3 (0, 90, 0);
  9. rotate02.delay = 1.29f;
  10.  

But it creates only one TweenRotation component.

So, is any way to attach more than one copy of tween component and setup them separately, or I have to do it in editor only?

4
NGUI 3 Support / Re: Convert screen position to local coords problem.
« on: January 17, 2016, 07:16:16 AM »
Thanks! It works now.

5
NGUI 3 Support / Convert screen position to local coords problem.
« on: January 14, 2016, 01:06:14 PM »
Hello, mates.

I try to make a very simple thing using NGUI - instantiate a label at the position of cursor after click.

Previously I did it using Unity UI without any problem, but now I have to switch to NGUI (due to very bad performance of native Unity scrollview).

So I found a few solution, included one from ArenMook:

  1. public Vector2 ScreenToParentPixels (Vector2 pos, Transform relativeTo)
  2.         {
  3.                 int layer = relativeTo.gameObject.layer;
  4.                 if (relativeTo.parent != null)
  5.                         relativeTo = relativeTo.parent;
  6.  
  7.                 Camera cam = Camera;
  8.  
  9.                 if (cam == null)
  10.                 {
  11.                         Debug.LogWarning("No camera found for layer " + layer);
  12.                         return pos;
  13.                 }
  14.  
  15.                 Vector3 wp = cam.ScreenToWorldPoint(pos);
  16.                 return (relativeTo != null) ? relativeTo.InverseTransformPoint(wp) : wp;
  17.         }

I use it in this way:

  1. public void OnMouseDown()
  2.         {
  3.  
  4.                 Vector2 mouseScreenPosition = Input.mousePosition;
  5.  
  6.                 GameObject floatText = NGUITools.AddChild (CanvasParent, FloatTextPrefab); // CanvasParent = UIRoot
  7.  
  8.                 floatText.transform.position = ScreenToParentPixels(mouseScreenPosition, floatText.transform.parent) / 360; // magic number to scale according UIRoot scale;
  9.  
  10.                 floatText.GetComponentInChildren<UILabel>().text = someText;
  11.  
  12.         }

But unfortunately it doesn't work as expected.

First, result does not count scale of UIRoot - so coords much bigger. You can see a "magic" number in my code (360) - it's for rescaling back.

But main problem is that coords are not correct. It works ok near the screen center, but the greater the distance from center, the greater the difference.

Anybody can help me with it please? Maybe I miss something or so on..

I also made a lot of tests with different UIRoot scaling styles and other solutions like using transform.worldToLocalMatrix.MultiplyPoint3x4(worldPos).. To be honest,  this issue ruined my day  ;D




6
FINAL UPDATE:

Yes, this issue was due to UIButton script.

I fix it by adding OnInit call to OnEnable method:
  1. protected override void OnEnable ()
  2.         {
  3. #if UNITY_EDITOR
  4.                 if (!Application.isPlaying)
  5.                 {
  6.                         mInitDone = false;
  7.                         return;
  8.                 }
  9. #endif
  10.                 OnInit (); // <---
  11.  
  12.                 if (isEnabled)
  13.                 {
  14.                         if (mInitDone)
  15.                         {
  16.  

7
NGUI 3 Support / UI2DSprite: Changing sprite2d property works only once
« on: October 10, 2014, 08:31:29 AM »
Hello,

I've found a strange issue with UI2DSprite in latest version of NGUI with latest version of Unity3D Pro.

I have a few icons which can be active or locked. So I manage it with code below:
  1.         public UnityEngine.Sprite Active;
  2.         public UnityEngine.Sprite Locked;
  3.  
  4. void OnEnable ()
  5.         {
  6.  
  7.                 var key = "Lesson"+LessonNumber;
  8.  
  9.                 if (!PlayerPrefs.HasKey (key))
  10.                 {
  11.  
  12.                         if ( LessonNumber == 1 ) PlayerPrefs.SetString (key, "active");
  13.                          else
  14.                           PlayerPrefs.SetString (key, "locked");
  15.  
  16.                         PlayerPrefs.Save ();
  17.        
  18.                 }
  19.  
  20.                 LessonState = PlayerPrefs.GetString (key);
  21.  
  22.                 switch (LessonState)
  23.                 {
  24.        
  25.                         case "active":
  26.  
  27.                                 GetComponent<UI2DSprite> ().sprite2D = Active;
  28.                                 Debug.Log ("Sprite is "+GetComponent<UI2DSprite> ().sprite2D);
  29.                                 break;
  30.  
  31.                         case "locked":
  32.                        
  33.                                 GetComponent<UI2DSprite> ().sprite2D = Locked;
  34.  
  35.                         break;
  36.  
  37.                        
  38.                 }
  39.        
  40.         }
  41.  
  42.  

It worked fine before I've update NGUI for latest version.
Now it works in this manner:

Application starts.

All sprites set up in right way.

When state of some icons changed Debug.log shows me that sprite2D component changes to right value, but nothing happens on scene and also inspector still shows old value in UI2DSprite component.

Can you help me with this issue or give me some advice?

UPDATE:

Looks like the problem is in the UIButton script which attached to my icons.
Logs from UI2Dsprite constructor:

// Set sprite2d to proper value after call from my script:

SET sprite2D to Lesson_2 (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
UI2DSprite:set_sprite2D(Sprite) (at Assets/NGUI/Scripts/UI/UI2DSprite.cs:49)
LessonIcon_Control:OnEnable() (at Assets/Scripts/LessonIcon_Control.cs:44)
UnityEngine.GameObject:SetActive(Boolean)

//debug.log from my script, shows right value for sprite2d

Sprite is Lesson_2 (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
LessonIcon_Control:OnEnable() (at Assets/Scripts/LessonIcon_Control.cs:47)

//OOPS! UIButton revert sprite2d value to previos :

SET sprite2D to Lesson_2_locked (UnityEngine.Sprite)
UnityEngine.Debug:Log(Object)
UI2DSprite:set_sprite2D(Sprite) (at Assets/NGUI/Scripts/UI/UI2DSprite.cs:49)
UIButton:SetSprite(Sprite) (at Assets/NGUI/Scripts/Interaction/UIButton.cs:304)
UIButton:SetState(State, Boolean) (at Assets/NGUI/Scripts/Interaction/UIButton.cs:275)
UIButton:OnEnable() (at Assets/NGUI/Scripts/Interaction/UIButton.cs:213)

Removing UIButton component helps. Now I will try to investigate what wrong wuth UIButton cause I would like to continue using it.

8
Heh, problem was not in unity sprites - I've tried to change it to ngui sprites but result was the same.
It was an issue with box collider on Grid component. After disabling it all started work as intend.

9
Yes, I did it.
But unfortunately it also stopped work after re-activate panel

10
Hello,

I have a ScrollView panel with buttons in the Grid inside. It is main screen of my education app, where user choose lesson.
Each button is 2D Sprite with attached scrollview script, and my own control script, which handle OnClick event and OnEnable event:
  1. void OnEnable ()
  2. {
  3.        if (Lesson.GetComponent<LessonControl> ().IsReached)
  4.                         {
  5.                             GetComponent<UI2DSprite>().sprite2D = Active;
  6.                         }
  7.                 else
  8.                         {
  9.                             GetComponent<UI2DSprite>().sprite2D = Locked;      
  10.                         }
  11. }
  12.  
  13. void OnClick ()
  14.         {
  15.                 Debug.Log ("CLICKED!");
  16.                 if (Lesson.GetComponent<LessonControl> ().IsReached) {
  17.                                                 GameObject.Find("MainControl").SendMessage ("StartLesson");
  18.                                                 Lesson.SetActive (true); }      
  19.         }

When some button have been clicked, I deactivate this panel and switch to main camera:
  1.         void StartLesson ()
  2.         {
  3.                 NGUITools.SetActive (MainScreen, false);
  4.                 MainCamera.active = true;
  5.         }
  6.  

After lesson is finished, I activate panel back in the same way:
  1. MainCamera.active = false;
  2. NGUITools.SetActive (MainScreen, true);

But after that the only one button stays clickable, all others stop to catch OnClick (and other mouse events - i tried to attach UIButton script to check it) event. I double check Z coord, widget depth, box colliders - all looks fine, and no visible difference between buttons.
Also, when I test it with two buttons - the first one stay working, when I added two more - the 3rd one...

Pages: [1]