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

Pages: [1] 2
1
NGUI 3 Support / Re: NGUI, 4.3 and new Sortyng Layers
« on: October 21, 2014, 08:28:37 PM »
Totally agree. Would be really nice to be able to use correctly and easily unity sorting layers.

Sorting layer is the game object's layer.

I think there is a misunderstanding here : layers and sorting layers are not the same thing.


I tried to put a uGUI canvas and a NGUI panel (rendered in the same camera, both are rendered correctly) on the same "Layer" (not sorting layer) and changing their order, and I never manage to get the NGUI object to be drawn up front.



(Parts in red are my sprite being drawn behind)

2
NGUI 3 Documentation / Re: UIScrollView
« on: September 24, 2014, 03:29:26 PM »
Thanks. I'll use "disable if fits" for now, but I think that this kind of behavior can be quite nice (considering it's a basic one on iOS and Android, and well known to the users) :)

3
NGUI 3 Documentation / Re: UIScrollView
« on: September 24, 2014, 10:45:19 AM »
Hi Aren,

I don't really get why my scrollview is not resetting its position when I'm dragging top. Here is a gif showing what happens :


I don't really get why the scrollview is not repositionning its content correctly (at its top). Note that this happens only if there is not enough elements to vertically fill the scrollview.

Another problem that I face is that my grid elements go out of the UIPanel/UIScrollview :

Edit : This problem has been solved with a "Soft Clip" panel ... Sorry ;)

Here is my set up :



"Restrict within panel" and "contraint within panel" are both checked.

4
NGUI 3 Support / Re: UIGrid with one element : avoid centering
« on: June 19, 2014, 04:31:40 AM »
Note that the centering actually depends on the scroll direction though. For example, if you're scrolling vertically and choose "Top Left" as the content origin, it's not going to move the content horizontally. Only vertically.

Horizontal position will remain in the same place, and you should be aware that the scroll view's position may not lie in the center of the scroll view. Switch to any tool other than a Move tool with the scroll view selected to see where it actually lies.

I just did a quick test on my end... Created a new scene, added a scroll view, placed a UIGrid underneath it and wrote a script to instantiate items under it. After instantiation I call Reposition() on the grid, and items show up in their expected position. If I add a scroll bar, then the scroll bar's value is used by the scroll view right away -- and with the provided controls that come with NGUI this means the scroll view is scrolled down beyond the halfway point. When I adjust the scroll bar's starting value to 0, it starts on top as expected. I even don't call ResetPosition() or anything else on the scroll view.

The only thing I see that may cause issues is that the scroll bar's size is not adjusted properly automatically. I've added some code to the UIPanel itself to do that that you will find in the next update.
  1. public class Test : MonoBehaviour
  2. {
  3.         public GameObject prefab;
  4.  
  5.         void Start ()
  6.         {
  7.                 for (int i = 0; i < 10; ++i)
  8.                 {
  9.                         NGUITools.AddChild(gameObject, prefab);
  10.                 }
  11.                 GetComponent<UIGrid>().Reposition();
  12.         }
  13. }

Interesting. I don't want a scrollbar, but I was wondering if I could do that (programmatically scroll my scrollview to the top).

I just realized something... I'm guessing your confusion lies in that you expect the content to show up in the top-left corner of the scroll view... but this will never happen because your scroll view is restricted to vertical movement. NGUI only adjusts the axis that it allows movement on.

No actually this behavior is what I want. My only problem is when my grid only have 1 element : the 2nd column is not created and not considered by the grid nor the scrollview, and so, logically, my only element is centered.



I guess the workaround is to reposition manually when I only have 1 element.

5
NGUI 3 Support / Re: UIGrid with one element : avoid centering
« on: June 18, 2014, 04:06:13 PM »
Well, first, thanks a lot for this detailled answer !

I for sure have some trouble with some basics features of Unity, like the instantiation of the prefab for example. I checked almost all the tutorial on their website but, heh, you gotta make some mistakes at one point. Thanks for this tip.

My Update() function is checking the screen size to resize my grid in case of a resolution change, because I realized that changing the screen sized at runtime did not resize my grid like I want (based on the screen width). It's a pretty basic thing, the "magic numbers" are simply the proportion I want my UI to have (as soon as you start to work with graphic artists and 2D drawing for the UI, you will never have plain simple values). For example, I want my grid cells to have a widht equals to the screen width divided by 2.2. I just need to round up the results to avoid floating point values.

The UI is pretty dynamic, and I prefer to separate all the dynamic parts into different UIPanel : The screen, the ressource bar on the top right (with dynamic values), the scrollview, and each "file" (my prefab).
Maybe it's not the right thing to do, but it seemed more natural to use the UIPanel as a container. Plus, I saw you writing somewhere that for dynamic elements UIPanel was useful : it would reload/refresh only its content, and not redraw the whole screen (as far as I understood it).

What I don't really understand is the Grid pivot thing. as you said, the Top option should put half the content on the left, and half on the right. Combined with a "Top" content origin on my Scrollview, I don't really undestand why I don't have a perfectly centered grid automatically. I guess I'll have to reposition everything by my self then, but it seemed pretty overkill for something like this.

I'm still a bit troubled about the 1 element case. I understand that the grid is only positionning stuff, so in that case I just need to reposition the element by myself but, well, if in the end I need to reposition so many things by hand, I'm going to end up doing the same thing I was doing with GameClosure : everything by hand. I guess I was expecting a bit too much from Unity in term of simplicity (WYSIWYG and all that stuff).

Thanks a lot for your answer, it really helps Unity beginners like me.

Edit : Don't take me wrong, I think that NGUI is a wonderful tool, especially compared to what is done about GUI in Unity for the moment. But I was not expecting small problems like those one to slow me down so much : my goal was to re-implement the UI of the game as fast as possible, and then focus on more important things. And those small problems, when you are not used to Unity nor NGUI, can take a tremendous amount of time, just to figure out what's going wrong (i.e, the ResetPosition() of my scrollview not working correctly).

6
NGUI 3 Support / Re: UIGrid with one element : avoid centering
« on: June 17, 2014, 02:28:26 PM »
No change :

With a Top Left GridPivot :


With a Top Left GridPivot and Top Left Scrollview content origin, same thing.

Actually, with only one element, the GridPivot is absolutly useless (I tried all the Pivot). The problem seems linked to the grid size.

Frankly, I'm amazed to realize how hard it is to implement a simple scrollable grid, populated on the fly. Here is my exact setup (I can share the project with you by private message if you want, it may be easier this way, but I would like to avoid this as much as possible);

My hierachy :



PlaceList :



Grid :



The script attached to this "Screen" (root UIPanel). This script takes a JSON containing a list of places, and instantiate a prefab for each place (filling some TextField).
It also manages the resizing of the Grid cell width and height, and the grid elements, in case of resolution change, as I want my grid cell to take a certain amount of space of any resolution (i.e my cell width is the screen width divided by 2.2).

  1. using UnityEngine;
  2. using System.Collections;
  3. using Newtonsoft.Json;
  4. using System.Collections.Generic;
  5.  
  6. public class PlacesScreen : MonoBehaviour
  7. {
  8.     // Used to check if the screen resolution changed
  9.     // TODO : Find a better solution than this one
  10.     public float ScreenStartWidth;
  11.     public float ScreenStartHeight;
  12.  
  13.     List<Place> places;
  14.     UIScrollView PlacesList;
  15.     UIGrid PlacesGrid;
  16.     GameObject FileList;
  17.  
  18.     // Hardcoded for testing purposes only
  19.     string json = @"[]";
  20.  
  21.     // Use this for initialization
  22.     void Start()
  23.     {
  24.         places = JsonConvert.DeserializeObject<List<Place>>(json);
  25.         PlacesList = gameObject.GetComponentInChildren<UIScrollView>() as UIScrollView;
  26.         PlacesGrid = gameObject.GetComponentInChildren<UIGrid>() as UIGrid;
  27.         FileList = GameObject.Find("Grid");
  28.  
  29.         ScreenStartHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  30.         ScreenStartWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  31.  
  32.         ResizeGrid();
  33.  
  34.         if (PlacesGrid != null && FileList != null && PlacesList != null)
  35.         {
  36.             BetterList<Transform> childList = PlacesGrid.GetChildList();
  37.  
  38.             // Addind the places from the json to the graphic list
  39.             foreach (Place place in places)
  40.             {
  41.                 Debug.Log("Adding a place");
  42.                 GameObject placeFile = Resources.Load("prefabs/File") as GameObject;
  43.                 placeFile.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  44.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("PlaceName").gameObject.GetComponent<UILabel>().text = place.Name;
  45.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("CityName").gameObject.GetComponent<UILabel>().text = place.City;
  46.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("TypeName").gameObject.GetComponent<UILabel>().text = place.Type;
  47.                 NGUITools.AddChild(FileList, placeFile);
  48.                 childList.Add(placeFile.transform);
  49.             }
  50.  
  51.             // Small hack to get a nicely presented Grid even with only 1 element
  52.             // TODO : Redo this ...
  53.             if (childList.size == 1)
  54.             {
  55.             }
  56.         }
  57.     }
  58.  
  59.     // Update is called once per frame
  60.     void Update()
  61.     {
  62.         if (ScreenStartHeight != PlacesList.gameObject.GetComponent<UIPanel>().height || ScreenStartWidth != PlacesList.gameObject.GetComponent<UIPanel>().width)
  63.         {
  64.             // PlacesLisit UIPanel size is changing when the List is dragged, but in this case we don't want to call a Resize()
  65.             if(!PlacesList.isDragging)
  66.             {
  67.                 ResizeGrid();
  68.                 ScreenStartHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  69.                 ScreenStartWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  70.             }
  71.         }
  72.     }
  73.  
  74.     /// <summary>
  75.     /// Resize the grid considering the screen width
  76.     /// </summary>
  77.     void ResizeGrid()
  78.     {
  79.         Debug.Log("ResizeGrid Called");
  80.         // Resizing the Grid cells' size.
  81.         PlacesGrid.cellWidth = (float)(PlacesList.gameObject.GetComponent<UIPanel>().width / 2.2);
  82.         PlacesGrid.cellHeight = (float)(PlacesGrid.cellWidth / 1.244);
  83.         foreach (Transform place in PlacesGrid.GetChildList())
  84.         {
  85.             place.gameObject.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  86.         }
  87.         PlacesGrid.Reposition();
  88.         PlacesList.ResetPosition();
  89.     }
  90. }
  91.  

As I said here I have another problem. The ResetPosition() function of the Scrollview is not working if called right after the grid resizing. If I "Reset clipping position" in the editor while in play mode, it's working perfectly (and putting the ResetPosition() in the Update() is working too. I'm not the only one having this problem).

Any help is appreciated, because I really start to get crazy : those are minor bugs, but still.

7
NGUI 3 Support / Re: UIGrid with one element : avoid centering
« on: June 16, 2014, 03:19:05 PM »
Well, the floating point values are coming from calculation (automatic resizing in code). They are so weird because I was in "free mode", but you're right I need to check that.

Well, as I explained, my problem here is that I don't want my grid to look like this when i only have one element (the only element being centered). When there is only one element the grid contains only one column, and does not consider the second one (which is empty). I find this behavior pretty weird.

I was wondering if the only solution in this case was to populate the grid with an invisible element ...


8
NGUI 3 Support / UIGrid with one element : avoid centering
« on: June 16, 2014, 08:45:31 AM »
I'm adding prefabs to my Grid (by code). The data are coming from the server. Problem is, when I only have 1 element in my grid, this is happening :



I'm trying to add an invisible element to my grid to solve this, but I'm not sure it's the best way to do.

With several elements it's working perfectly :


9
NGUI 3 Documentation / Re: UIScrollView
« on: June 16, 2014, 08:40:22 AM »
Well, here is my code.

I'm actually not doing anything fancy.

  1. public class PlacesScreen : MonoBehaviour
  2. {
  3.     // Used to check if the screen resolution changed
  4.     // TODO : Find a better solution than this one
  5.     public float startWidth;
  6.     public float startHeight;
  7.  
  8.     List<Place> places;
  9.     UIScrollView PlacesList;
  10.     UIGrid PlacesGrid;
  11.     GameObject FileList;
  12.  
  13.     // Hardcoded for testing purposes only
  14.     string json = @"[{ blabla
  15. }]";
  16.  
  17.     // Use this for initialization
  18.     void Start()
  19.     {
  20.         places = JsonConvert.DeserializeObject<List<Place>>(json);
  21.         PlacesList = gameObject.GetComponentInChildren<UIScrollView>() as UIScrollView;
  22.         PlacesGrid = gameObject.GetComponentInChildren<UIGrid>() as UIGrid;
  23.         FileList = GameObject.Find("Grid");
  24.  
  25.         startHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  26.         startWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  27.  
  28.         if (PlacesGrid != null && FileList != null && PlacesList != null)
  29.         {
  30.             BetterList<Transform> childList = PlacesGrid.GetChildList();
  31.  
  32.             // Addind the places from the json to the graphic list
  33.             foreach (Place place in places)
  34.             {
  35.                 Debug.Log("Adding a place");
  36.                 GameObject placeFile = Resources.Load("prefabs/File") as GameObject;
  37.                 placeFile.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  38.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("PlaceName").gameObject.GetComponent<UILabel>().text = place.Name;
  39.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("CityName").gameObject.GetComponent<UILabel>().text = place.City;
  40.                 placeFile.transform.Find("ContentPanel").gameObject.transform.Find("TypeName").gameObject.GetComponent<UILabel>().text = place.Type;
  41.                 NGUITools.AddChild(FileList, placeFile);
  42.                 childList.Add(placeFile.transform);
  43.             }
  44.  
  45.             // Small hack to get a nicely presented Grid even with only 1 element
  46.             // TODO : Redo this ...
  47.             if (childList.size == 1)
  48.             {
  49.                 Debug.Log("One place only, we have to had a invisible file to avoid center");
  50.                 GameObject invisibleFile = Resources.Load("prefabs/File") as GameObject;
  51.                 NGUITools.AddChild(FileList, invisibleFile);
  52.                 childList.Add(invisibleFile.transform);
  53.             }
  54.             ResizeGrid();
  55.         }
  56.     }
  57.  
  58.     // Update is called once per frame
  59.     void Update()
  60.     {
  61.         if (startHeight != PlacesList.gameObject.GetComponent<UIPanel>().height || startWidth != PlacesList.gameObject.GetComponent<UIPanel>().width)
  62.         {
  63.             ResizeGrid();
  64.             startHeight = PlacesList.gameObject.GetComponent<UIPanel>().height;
  65.             startWidth = PlacesList.gameObject.GetComponent<UIPanel>().width;
  66.         }
  67.     }
  68.  
  69.     /// <summary>
  70.     /// Resize the grid considering the screen width
  71.     /// </summary>
  72.     void ResizeGrid()
  73.     {
  74.         Debug.Log("ResizeGrid Called");
  75.         // Resizing the Grid cells' size.
  76.         PlacesGrid.cellWidth = (float)(PlacesList.gameObject.GetComponent<UIPanel>().width / 2.2);
  77.         PlacesGrid.cellHeight = (float)(PlacesGrid.cellWidth / 1.244);
  78.         foreach (Transform place in PlacesGrid.GetChildList())
  79.         {
  80.             place.gameObject.GetComponent<UISprite>().width = (int)PlacesGrid.cellWidth;
  81.         }
  82.         PlacesGrid.Reposition();
  83.         PlacesList.ResetPosition();
  84.     }
  85. }

The Resize() method is working perfectly well, resizing my elements. But when I'm coming from a wider resolution, here is what happen :




10
NGUI 3 Documentation / Re: UIScrollView
« on: June 12, 2014, 05:52:08 PM »
I'm trying to reset the scroll view to the upper left corner after populating it. Calling ResetPosition() before and after I add elements doesn't seem to work.

As a test, I added ResetPosition to the Update() function, and that got it to reset correctly, but obviously I don't want to call it there.

[...]


I have the exact same problem with a scrollview containing a UIGrid. When the resolution of the screen changes, I resize my grid, and then i call ResetPosition(). It's working well if I go from a 4/3 resolution to a 16/10, but in the opposite case I have a gap between the top of my grid and the top of my scrollview.
If I put ResetPosition() in the Update() method, it's working perfectly. But, to quote justkevin, "I don't want to do that"

11
NGUI 3 Documentation / Re: UIGrid
« on: June 12, 2014, 10:55:08 AM »
Okay, thank you for your answer.

I have another weird behavior. I don't know if it's due to my wrong understanding of the "pivot" settings :



I would think that a Top-Right Pivot would make the grid start in the Top right corner of its parent. (The parent scrollview has a "Top" content origin setting).

I must admit that the Grid was kind of hard to settle correctly. Right now I still have some troubles finding the right parameters to get what I want...

For example, I don't quite understand that my centers are not similar (on the y axis) :



The centers should be on the same vertical line, right ? (with a "top" pivot parameter, which is "top center").

12
NGUI 3 Documentation / Re: UIGrid
« on: June 10, 2014, 06:18:45 AM »
Hi,

Just to clarify something: can the UIGrid AddChild(Transform) method be used to dynamically add children to a Grid (and display them automatically) ? I tried to use this method (or GetChildList() and then add children to the list), and the size of the method is changing correctly, but the new elements are not displayed.

For the moment I still get the GameObject containing the UIGrid script, and then use NGUI.addChild(T) , but I'm wondering why the other method is not working.


13
NGUI 3 Support / Re: Black textures on Android *SOLVED*
« on: June 05, 2014, 07:11:16 AM »
I would like to use this topic (instead of creating a new one). I have a black texture problem, because of their size. It's only for the background textures which are really big (to allow support for retina/uHD resolutions).

I'm trying to play with the Texture Quality settings, thinking that Unity will resize them at runtime, but is it the good solution ? Here is the question i created on Unity Answer. I'll update it and update this answer too.

Tks !

14
NGUI 3 Support / Re: Atlas Maker error in Unity 4.5
« on: May 31, 2014, 06:10:41 AM »
Same error here. Latest version of NGUI and Unity.

15
NGUI 3 Support / Re: Relative Anchors - Positionning Problems
« on: May 30, 2014, 12:07:32 PM »
Eureka.

I had to set both the Left and Right anchor to specific values :



Left : 1 and Right : 0 <<<< Middle of the screen
Left : 1 and Right : 0.44 <<< 0.72 of the screen, 72% !

I watched all the tutorials and read the documentations, this behavior is not quite obvious and deserves (in my opinion) a better description !


Pages: [1] 2