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

Pages: [1] 2
1
NGUI 3 Support / How to reset UIToggle to initial value
« on: February 06, 2014, 08:14:27 AM »
Hi there,

I have 3 UIToggle groups:

Group 1 Contains 2 tabs on the top of the screen
Group 2 is contained inside a transform that is being activated when tab 1 is clicked, and contains a set of 8 uitoggles, to change pages inside the tab content
Group 3 is contained inside a transform that is being activated when tab 2 is clicked, and contains a set of 8 uitoggles, to change pages inside the tab content

The scenario is:
1.- I am on first tab, and with first page actived
2.- I click on page 4, for instance, the content appears
3.- I click on tab 2
4.- I click on tab 1. Here i launch a "load page 1" method, which changes the content and activates the first Group 2 uitoggle (value = true).
The problem is that both page 4 and page 1 are now being highlighted.

Is there a way to "reset to initial state" the whole group?

Thanks!!

Oakshiro

2
Wonderful, thanks!

3
Hi there,

I have created a Scrollview, which has its "Scrollbar" value to a UIScrollbar parent, with this structure...
UIScrollbar (background)
   L... UIWidget (foreground)
   L... UISprite (Thumb)

If the contents of the ScrollView are big enough, the thumb goes correctly from top to bottom of the bar, but when it is not the thumb is not going correctly from top to bottom.
I realised the problem comes because the thumb is Anchored to the Foreground widget, and the widget is being scaled depending on the size of the contents of the scrollview, so it "hits" the boundaries of the background and doesn't allow the thumb to go further.

I also realised there is a UISlider component that could match better my needs, but Scrollview class doesn't allow to send a UISlider as the scrollbar parameter...

How could i fix this?

Thanks!
PS: i send a screenshot to better explain it

4
NGUI 3 Documentation / Re: UIScrollView
« on: January 10, 2014, 06:45:35 PM »
That could have worked indeed, but in the end I created my own PageScrollView class, based on UICenterOnChild. It might not be the best code in the world, but hey, it works!
Thanks for your help :)

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. /// <summary>
  5. /// Attach this script to the container that has the objects to allow paging
  6. /// </summary>
  7.  
  8. public class PageScrollView : MonoBehaviour {
  9.  
  10.         public float springStrength = 8.0f;
  11.  
  12.         private UIScrollView scrollView;
  13.         private int elementsPerPage;
  14.         private int currentScrolledElements;
  15.         private Vector3 startingScrollPosition;
  16.  
  17.         private UIGrid grid;
  18.  
  19.         // Use this for initialization
  20.         void Start ()
  21.         {
  22.                 if (scrollView == null)
  23.                 {
  24.                         scrollView = NGUITools.FindInParents<UIScrollView>(gameObject);
  25.                         if (scrollView == null)
  26.                         {
  27.                                 Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " object in order to work", this);
  28.                                 enabled = false;
  29.                                 return;
  30.                         }
  31.  
  32.                         grid = this.GetComponent<UIGrid>();
  33.                         elementsPerPage = (int) (scrollView.panel.clipRange.z / grid.cellWidth);
  34.                         currentScrolledElements = 0;
  35.                         startingScrollPosition = scrollView.panel.cachedTransform.localPosition;
  36.                 }      
  37.         }
  38.        
  39.         // Update is called once per frame
  40.         void Update () {
  41.        
  42.         }
  43.        
  44.  
  45.         /// <summary>
  46.         /// Scrolls until target position matches target panelAnchorPosition (may be the center of the panel, one of its sides, etc)
  47.         /// </summary> 
  48.         void MoveBy (Vector3 target)
  49.         {
  50.                 if (scrollView != null && scrollView.panel != null)
  51.                 {
  52.                         // Spring the panel to this calculated position
  53.                         SpringPanel.Begin(scrollView.panel.cachedGameObject, startingScrollPosition - target, springStrength);
  54.                 }
  55.         }
  56.  
  57.  
  58.         public void NextPage()
  59.         {
  60.                 if (scrollView != null && scrollView.panel != null)
  61.                 {
  62.                         currentScrolledElements += elementsPerPage;
  63.                         if (currentScrolledElements > (this.transform.childCount - elementsPerPage))
  64.                         {
  65.                                 currentScrolledElements = (this.transform.childCount - elementsPerPage);
  66.                         }
  67.                         float nextScroll = grid.cellWidth * currentScrolledElements;
  68.                         Vector3 target = new Vector3(nextScroll, 0.0f, 0.0f);                          
  69.                         MoveBy(target);
  70.                 }
  71.         }
  72.  
  73.         public void PreviousPage()
  74.         {
  75.                 if (scrollView != null && scrollView.panel != null)
  76.                 {
  77.                         currentScrolledElements -= elementsPerPage;
  78.                         if (currentScrolledElements < 0)
  79.                         {
  80.                                 currentScrolledElements = 0;
  81.                         }
  82.                         float nextScroll = grid.cellWidth * currentScrolledElements;
  83.                         Vector3 target = new Vector3(nextScroll, 0.0f, 0.0f);                          
  84.                         MoveBy(target);
  85.                 }
  86.         }
  87.  
  88. }
  89.  

5
NGUI 3 Documentation / Re: UIScrollView
« on: January 10, 2014, 10:42:16 AM »
Hmmm, I can't see how UICenterOnChild could work for that... It just centers my first grid element on the center of the screen, and I only can change its spring strength...

What I intend to do is to have one button on each side of the scrollview and move one page left or right when I click on them, but keeping the content inside the bounds.


EDIT:
Ok, i see there is a CenterOn(Transform t) to center it on an object. The problem is my pages have 6 elements, so I should center it between two elements...

6
NGUI 3 Documentation / Re: UIScrollView
« on: January 10, 2014, 07:40:41 AM »
Is there any easy way to make the UIScrollView go "page by page"?

I am trying to put a "next page" button, and everything goes ok until i reach the extens of the scroll, am I going ok doing this?


  1.         Vector3 targetPosition = scrollView.transform.localPosition;
  2.                 targetPosition.x += moveBy;
  3.  
  4.                 if (targetPosition.x < -scrollView.bounds.extents.x)
  5.                 {
  6.                         targetPosition.x = -scrollView.bounds.extents.x;
  7.                 }
  8.  
  9.                 SpringPanel.Begin (scrollView.gameObject, targetPosition, 13f);

THANKS!


It is NGUI 3, btw

7
NGUI 3 Support / Re: UITexture blend looks messy
« on: August 23, 2013, 07:06:55 AM »
Ok, then I'll search for a suitable shader on the internet.
thanks!

8
NGUI 3 Support / Re: UITexture blend looks messy
« on: August 21, 2013, 06:20:55 AM »
Ok, I'll try to deactivate depth pass.. but I have no idea of how to properly create a shader...
Maybe I am trying to do something strange, but the idea is to load a image from the internet and put it as a sprite, behind the round one.

If you could point me out how to do it in one way or another it would save my day!
thanks

Oakshiro

9
NGUI 3 Support / UITexture blend looks messy
« on: August 05, 2013, 05:59:52 AM »
Hi there,

I have a UITexture which is being downloaded from internet (Facebook picture), and should be displayed behind a round "hole" in a png sprite.
I activated the "Depth pass" option, and the UITexture has a Unlit/transparent colored material, but semitransparent pixels look quite messy...



I understand you cannot load a url inside a sprite so UITexture should be the correct way to do it, but how should I manage the alpha blend to make it look right?

Thanks!
Oakshiro

10
NGUI 3 Support / Re: Setting focus on input widget in code
« on: July 30, 2013, 03:27:57 AM »
It seems that when we change the input.selected value the camera restores the input immediately after we change it. I found a workaround to make this work.

I use a UIInput reference to detect if we should change focus, and when we launch the "field Changed" method, we set it. Later on, on the update, we force set it until the UICamera.selectedObject equals the desired UIInput.

Here is the code:


  1.  
  2. private UIInput selectedInput = null;
  3. ..
  4. ..
  5. ..
  6.  
  7. public void OnNameChange()
  8. {
  9.         UICamera.selectedObject = passInput.gameObject;
  10.         selectedInput = passInput;
  11. }
  12.  
  13.  
  14. void Update ()
  15. {                                                      
  16.         if (UICamera.selectedObject != null && selectedInput != null)
  17.         {
  18.                  if (UICamera.selectedObject != selectedInput.gameObject)
  19.                  {
  20.                         selectedInput.text = ""; //avoid showing the caret
  21.                         selectedInput.selected = true;
  22.                  }
  23.         }
  24. }
  25.  

11
NGUI 3 Support / Re: Setting focus on input widget in code
« on: July 30, 2013, 03:15:47 AM »
I have exactly the same error. When I hit on enter on the Name field it calls a method that should activate the next field (email), but it only prints a pipe on the email field and when you continue typing you do it on the Name field instead!

How can we do this? 

12
NGUI 3 Support / Re: Expand Sprite to available space?
« on: July 29, 2013, 03:30:39 AM »
I finally managed to make it work, although only vertically (It doesn't work if Screen width is higher than Screen height), because it uses the UIRootAdjustment script combined with the UIRoot default one.

Here is the code for the grid:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [RequireComponent (typeof(UIGrid))]
  5. public class ExpandGridToFit : MonoBehaviour {
  6.        
  7.        
  8.         //WARNING: THIS COMPONENT WILL ONLY WORK ON PORTRAIT SCREENS
  9.         public float marginHeight;
  10.         private UIGrid grid =null;     
  11.         private UIRoot root;
  12.  
  13.         // Use this for initialization
  14.         void Start ()
  15.         {
  16.                 root = GameObject.FindObjectOfType(typeof(UIRoot)) as UIRoot;
  17.                 grid = this.gameObject.GetComponent<UIGrid>();
  18.         }
  19.        
  20.         // Update is called once per frame
  21.         void Update ()
  22.         {      
  23.                                                                        
  24.                 //get available height         
  25.                 int rows = (int)Mathf.Round(((float)grid.transform.childCount / (float)grid.maxPerLine));                      
  26.                 float availableHeight = ((float)root.manualHeight - marginHeight) / rows;                                                      
  27.                
  28.                 if (grid.cellHeight != availableHeight)
  29.                 {                                              
  30.                         //set cellHeight       
  31.                         grid.cellHeight = availableHeight;
  32.                        
  33.                         //refresh!
  34.                         grid.Reposition();
  35.                        
  36.                         //refresh childrens if I should
  37.                         foreach (Transform t in transform)
  38.                         {
  39.                                 ExpandToCellSize etcs = t.GetComponent<ExpandToCellSize>();
  40.                                 if (etcs != null)
  41.                                 {
  42.                                         etcs.resizeNow = true;
  43.                                 }
  44.                         }
  45.                 }
  46.         }
  47. }
  48.  


And Here is the code for the containing Sprites:
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ExpandToCellSize : MonoBehaviour {
  5.        
  6.         public bool expandHeight = false;
  7.         public bool expandWidth = false;       
  8.         public bool resizeNow = false;
  9.        
  10.         private UIGrid parentGrid = null;
  11.        
  12.         void Awake()
  13.         {
  14.                 parentGrid = transform.parent.GetComponent<UIGrid>();
  15.         }
  16.        
  17.         // Use this for initialization
  18.         void Start ()
  19.         {
  20.                 resizeNow = true;
  21.         }
  22.        
  23.         // Update is called once per frame
  24.         void Update ()
  25.         {              
  26.                 if (parentGrid == null || (!expandWidth && !expandHeight))
  27.                         return;
  28.                
  29.                 if (resizeNow)
  30.                 {
  31.                         Vector3 newScale = this.transform.localScale;
  32.                        
  33.                         if (expandWidth)
  34.                         {
  35.                                 newScale.x = parentGrid.cellWidth;
  36.                         }
  37.                        
  38.                         if (expandHeight)
  39.                         {
  40.                                 newScale.y = parentGrid.cellHeight;
  41.                         }
  42.                        
  43.                         this.transform.localScale = newScale;
  44.                        
  45.                         resizeNow = false;
  46.                 }
  47.         }
  48. }
  49.  

13
NGUI 3 Support / Re: Expand Sprite to available space?
« on: July 29, 2013, 02:45:14 AM »
But, does UIStretch allow you to set a vertical and horizontal margin? I don't think so....

14
NGUI 3 Support / Expand Sprite to available space?
« on: July 26, 2013, 07:51:38 AM »
Hi there,
I have two sprites, one anchored on the top of the screen and the other one to the bottom.
I need a center sprite which expands to the screen available space. But I cannot achieve it, i suppose i am missing some concept about NGUI.

Here is my code so far, without luck:

  1.         //get available height         
  2.         float availableHeight = (float)Screen.height;                          
  3.         foreach (Transform t in delimiters)
  4.         {
  5.                 availableHeight -= (t.localScale.y);
  6.         }                              
  7.        
  8.         //set new height
  9.         Vector3 newHeight = transform.localScale;
  10.         newHeight.y = availableHeight;
  11.         transform.localScale = newHeight;
  12.  
  13.  

15
NGUI 3 Support / Re: UIRoot: Why target Height?
« on: May 17, 2013, 03:01:04 AM »
I saw that post previously, but it uses the "targetHeight" to calculate the size, therefore I supposed it was not Width based.
Is it that the targetHeight is being "hacked" to be used as Width ?

Pages: [1] 2