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

Pages: 1 ... 4 5 [6] 7 8 ... 11
76
I put a yield return null after the if (mNextChar <= Time.time) {...} - it worked! - Thanks :)

77
Yes, I know that. That's what I'm doing inside GetObjectBounds:
  1.         public static Bounds GetObjectBounds(Transform t)
  2.         {
  3.                 var collider = t.collider;
  4.                 if (collider != null)
  5.                         return collider.bounds;
  6.  
  7.                 var renderer = t.renderer;
  8.                 if (renderer != null)
  9.                         return renderer.bounds;
  10.  
  11.                 return NGUIMath.CalculateAbsoluteWidgetBounds(t);
  12.         }
  13.  

I get the bounds and then subtract max-min, just like I showed in code.

78
Thanks for your reply. Yeah sure, I'll use a Coroutine. I just didn't find it nice to keep adding and destroying it as I will be using it a lot.

79
Hello,

I just hacked (modified) TypeWriterEffect to not destroy itself when it finishes. Instead, there's a boolean 'Begin' that you set to true each time you want the effect to occur.

First, I tried making a 'Begin' method, and forget about Update:
  1.         public void Begin()
  2.         {
  3.                 if (mLabel == null)
  4.                 {
  5.                         mLabel = GetComponent<UILabel>();
  6.                         mLabel.supportEncoding = false;
  7.                         mLabel.symbolStyle = UIFont.SymbolStyle.None;
  8.                         mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth / mLabel.cachedTransform.localScale.x,
  9.                         mLabel.maxLineCount, false, UIFont.SymbolStyle.None);
  10.                 }
  11.  
  12.                 while (mOffset < mText.Length)
  13.                 {
  14.                         if (mNextChar <= Time.time)
  15.                         {
  16.                                 charsPerSecond = Mathf.Max(1, charsPerSecond);
  17.  
  18.                                 // Periods and end-of-line characters should pause for a longer time.
  19.                                 float delay = 1f / charsPerSecond;
  20.                                 char c = mText[mOffset];
  21.                                 if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f;
  22.  
  23.                                 mNextChar = Time.time + delay;
  24.                                 mLabel.text = mText.Substring(0, ++mOffset);
  25.                         }
  26.                 }
  27.         }
  28.  

The problem with that, is that it gets stuck between the condition of the while and the if (infinite loop) because the method is not being called in Update, I guess...

So I thought I should use update, so I came up with this idea of using a boolean Begin, set it to true each time I want the effect to happen:

  1.         private bool begin;
  2.         public bool Begin {get {return begin;} set{begin = value; Reset();}}
  3.  
  4.         private void Reset()
  5.         {
  6.                 mOffset = 0;
  7.                 mNextChar = 0;
  8.                 if (mLabel != null)
  9.                         mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth / mLabel.cachedTransform.localScale.x,
  10.                                     mLabel.maxLineCount, false, UIFont.SymbolStyle.None);
  11.         }
  12.  
  13.         void Update()
  14.         {
  15.                 if (begin)
  16.                 {
  17.                         if (mLabel == null)
  18.                         {
  19.                                 mLabel = GetComponent<UILabel>();
  20.                                 mLabel.supportEncoding = false;
  21.                                 mLabel.symbolStyle = UIFont.SymbolStyle.None;
  22.                                 mText = mLabel.font.WrapText(mLabel.text, mLabel.lineWidth/mLabel.cachedTransform.localScale.x,
  23.                                             mLabel.maxLineCount, false, UIFont.SymbolStyle.None);
  24.                         }
  25.  
  26.                         if (mOffset < mText.Length)
  27.                         {
  28.                                 if (mNextChar <= Time.time)
  29.                                 {
  30.                                         charsPerSecond = Mathf.Max(1, charsPerSecond);
  31.  
  32.                                         // Periods and end-of-line characters should pause for a longer time.
  33.                                         float delay = 1f/charsPerSecond;
  34.                                         char c = mText[mOffset];
  35.                                         if (c == '.' || c == '\n' || c == '!' || c == '?') delay *= 4f;
  36.  
  37.                                         mNextChar = Time.time + delay;
  38.                                         mLabel.text = mText.Substring(0, ++mOffset);
  39.                                 }
  40.                         }
  41.                 }//             else Destroy(this);
  42.                 else begin = false;
  43.         }
  44.  

Is this good? is there a better way you might suggest? I would love to not use Update, and use a separate method like in my first try - Thanks.

80
Hello,

in my inventory system, I want to be able to determine the number of rows/columns I have based on the height/width on my inventory background and the slots size. (See attachment)

So like, if I had a 500x500 background, with a slot size of 50, I will have 10x10 2d inventory.

Problem is, I can't seem to do that the right way! Here's what I'm doing:

1- The slot size is set in the bag from the inspector (like 50 for example)
2- When I create the slot at run time, I have to figure out its right scale right?

This is what I'm doing for that (basically I'm following the formula: newScale = (newSize * currentScale) / currentSize):

  1. realPixelScale =  NGUITools.Get3dPixelScale(background.cachedTransform, new Vector2(SlotSize, SlotSize));
  2.  

Where (please don't get lost, it's simple):
  1.         public static Vector3 Get3dPixelScale(Transform trans, Vector3 newSize)
  2.         {
  3.                 var currentSize = GetObjectScreenDims(trans);
  4.                 return Get3dPixelScale(currentSize, new Vector2(newSize.x, newSize.y), trans.localScale);
  5.          }
  6.  
  7.         // Gets an object dimensions in screen coords
  8.         public static Vector3 GetObjectScreenDims(Transform t)
  9.         {
  10.                 var cam = FindCameraForLayer(t.gameObject.layer);
  11.                 var bounds = GetObjectBounds(t);
  12.                 var sMax = cam.WorldToScreenPoint(bounds.max);
  13.                 var sMin = cam.WorldToScreenPoint(bounds.min);
  14.                 return sMax - sMin;
  15.          }
  16.  
  17.         public static Vector3 Get3dPixelScale(Vector3 currentSize, Vector3 newSize, Vector3 currentScale)
  18.         {
  19.                 Vector3 newScale = Get2dPixelScale(currentSize, newSize, currentScale);
  20.                 newScale.z = (newSize.z * currentScale.z) / currentSize.z;
  21.                 newScale.z = Mathf.Clamp(newScale.z, 1, newScale.z);
  22.                 if (float.IsNaN(newScale.z))
  23.                         newScale.z = 1;
  24.                 return newScale;
  25.         }
  26.  
  27.         public static Vector2 Get2dPixelScale(Vector2 currentSize, Vector2 newSize, Vector2 currentScale)
  28.         {
  29.                 var newScale = new Vector3();
  30.                 newScale.x = (newSize.x * currentScale.x) / currentSize.x;
  31.                 newScale.x = Mathf.Clamp(newScale.x, 1, newScale.x);
  32.                 newScale.y = (newSize.y * currentScale.y) / currentSize.y;
  33.                 newScale.y = Mathf.Clamp(newScale.y, 1, newScale.y);
  34.                 return newScale;
  35.         }
  36.  


So now, I 'should' have the right scale for the slot, such that its height and width are 'SlotSize'

Now, in my bag:
  1. var dims = NGUITools.GetObjectScreenDims(background.cachedTransform);
  2. nMinCols  = (int)(dims.x / slotSize);
  3. nMinRows = (int)(dims.y / slotSize);
  4.  

It doesn't work :( - For some reason, I get more slots than I should (the slot is getting a higher scale than it should. ex: I give it a 60 size, I get a scale of (70, 70, 1) :( - I am 100% sure that for some reason, this script used to work just fine with me, but now it's not...

What is the right way to do what I want? what should I calculate, what should I divide?...  please any help would be appreciated - thanks a lot.

and please let me know if I'm doing something bad / the wrong way (bad habit - miss-use)

Note that I do get better results if I just say:
  1. realScale = new Vector3(slotSize, slotSize, 1); // instead of all that long calculations
  2.  
But sometimes this could cause problems in other places :/

81
Hello, I'm using Tween combinations to create animation effects (Like when you click on the popup list) - I want a good way to execute a method after the animation finishes.

I currently I'm doing something like this: (this is a snippet from my custom context menu, which is basically a popup list that appears on the mouse position)

  1. // show on mouse, and seek to animate
  2. if (show && hasFinshedAnimating) {
  3.         _transform.position = camera.ScreenToWorldPoint(Input.mousePosition);
  4.         if (isAnimated) {
  5.                 hasFinshedAnimating = false;
  6.                 for (int i = 0, len = entries.Count; i < len; ++i) {
  7.                         Animate(entries[i]);
  8.                 }
  9.         UIWidget.Animate(background, animSpeed);
  10.         StartCoroutine(WaitForAnim());
  11.         }
  12. }
  13.  
  14. IEnumerator WaitForAnim()
  15. {
  16.         yield return new WaitForSeconds(animSpeed + .15f);
  17.         hasFinshedAnimating = true;
  18.         if (Random.Range(0, 10) > 6)
  19.                 ResetEntriesDims();
  20. }
  21.  
  22. void Animate(Entry entry)
  23. {
  24.         UIWidget.Animate(entry.background, animSpeed);
  25.         UIWidget.Animate(entry.label, animSpeed);
  26. }
  27.  
  28. public static void Animate(UIWidget widget, float animSpeed)
  29. {
  30.         AnimateColor(widget, animSpeed);
  31.         AnimatePosition(widget, animSpeed);
  32.         AnimateScale(widget, animSpeed);
  33. }
  34.  
  35.  

(Notice I'm actually calling Animate methods, but they internally operate on Tween)

It works fine, serves the purpose. But I wonder if there's something built-in for that, something I'm missing perhaps, anything?

In general, can this be done in a better more elegant way?

Thanks!

82
NGUI 3 Support / Re: Zoomable clipped panel? (zoom in/out the contents)
« on: September 13, 2013, 09:11:10 AM »
Thanks for the reply. I haven't upgraded yet. So I guess, even scaling the root of my panel's content won't help right? cuz there are children under it... :/

83
NGUI 3 Support / Zoomable clipped panel? (zoom in/out the contents)
« on: September 13, 2013, 03:22:50 AM »
Hello,

I am looking for a way, if possible to zoom in/out to/of the clipped panel's contents.

Now I have done this before by using an external orthographic camera, changing its rect to the area I want to zoom in to, and then mess with its size to zoom in/out. (See attachment)

Now this is OK if I don't wanna interact with the object I'm zooming in/out to/from. Obviously for this to work, I had to make a separate panel for the object in question (the wooden sprite) - Got this info from UIWidget.cs:

  1.         public void CheckLayer ()
  2.         {
  3.                 if (mPanel != null && mPanel.gameObject.layer != gameObject.layer)
  4.                 {
  5.                         Debug.LogWarning("You can't place widgets on a layer different than the UIPanel that manages them.\n" +
  6.                                 "If you want to move widgets to a different layer, parent them to a new panel instead.", this);
  7.                         gameObject.layer = mPanel.gameObject.layer;
  8.                 }
  9.         }
  10.  

But then of course, when you mess around with layers (because I should remove the object I'm zooming in/out layer from my main gui cam culling mask, so that only my external cam sees the object - the wooden sprite), ray might not hit colliders, I had a lot of trouble getting the collider on the wooden sprite to detect mouse clicks, I rarely, in some very unique cases managed to, I was never able to get it work.

Anyway, that's not my question, I was just showing you my attempt to create a zoom in/out effect. I will post in much more detail about the problems I had there in another post.

But right now, since my way of doing it was very tedious, I thought well, NGUI must have something to achieve this, Aren wouldn't let something like this pass by now would he? ;-)

So, is there an NGUIsh way, an elegant way to achieve zooming in/out?

- Thanks all in advance.

EDIT: I have just noticed that messing around with the panel's scale (that has only the wooden sprite) could do the job for me, but of course, messing with a panel scale is a taboo in NGUI :(  (See other attachment)


84
I have asked the question here << http://answers.unity3d.com/questions/533602/best-waypattern-to-exchange-messages-between-gui-e.html >> I got an answer, but it wasn't that good. I can't send parameters to my functions with UIButtonMessage.

So, what do you think the best way to communicate with UI elements?

- Thanks.

85
Hello, with the current UIInput, you can click on a label and the caret will be at the last char and you can edit.

What I'm looking for to have:
1- Click anywhere within the label and have the caret be at that position.
2- I can select/highlight text.

Any ideas how I can achieve those two? I just wanna know where to start and how am I to go about doing this, especially the highlighting part.

This would also be a really nice feature to have in future NGUI releases.

Thanks.

86
NGUI 3 Support / Re: Mouseclick not working
« on: September 07, 2013, 10:28:30 AM »
Make sure you got your "EventRecieverMask" in your UICamera set to whatever layer your gui camera should see (your gui cam's culling mask).

87
I guess I was wrong with thinking I caught the problem :( - I just changed your setup to be just like mine, the example didn't get affected. I will keep looking.

88
But wait, if I did that, then how am I gonna drag the whole thing? - When that panel was there, I was able to easily drag it and have everything move with it. But now, if I move (Panel - 2D UI), then the clipping panel would be left behind! :( - How can I now move them both? - I could stick a UIDragObject on WindowRoot, but you recommended us to move the panel instead of moving a gameObject. Suggestions?

89
You are right!

Your setup:
  1. UIRoot
  2.    Camera
  3.        Anchor
  4.            WindowRoot // which is just a child empty game object
  5.                Panel - Clipping
  6.                Panel - 2D UI
  7.  

My setup:
  1. UIRoot
  2.    Camera
  3.        Anchor
  4.            Panel - FileManager // <---- My mistake, there shouldn't be a panel here.
  5.                WindowRoot
  6.                    Panel - Clipping
  7.                    Panel - 2D UI
  8.  

90
Please check my update, I've included a photo to my setup. My setup is almost the same as the one in the example, with the difference that I have more than one panel, and  UITable instead of UIGrid.

Pages: 1 ... 4 5 [6] 7 8 ... 11