Author Topic: NGUI, 4.3 and new Sortyng Layers  (Read 19926 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #15 on: September 05, 2014, 09:29:37 AM »
Sorting layer is the game object's layer.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #16 on: September 14, 2014, 06:33:09 AM »
I also want NGUI can officially support Renderer.sortingLayerID

bogart

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #17 on: September 24, 2014, 02:51:39 PM »
Me too. I'm combining NGUI with some various GUI Labels. I currently have my belly button wrapped around my neck.

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #18 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)

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #19 on: April 09, 2015, 05:38:23 AM »
Yeah, I ended up having to roll my own solution (annoying when you are updating NGUI though) as setting the game layer made no difference. Seems like an important feature to have, but doesn't seem like many people have encountered this.

damelin

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #20 on: July 16, 2015, 10:03:00 PM »
+1 for supporting Sorting Layers in NGUI objects (panel/widgets)

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #21 on: November 25, 2015, 08:03:47 AM »
Is there any update on this? I think this is a very important feature and surprised it's not added yet. Even more so when it can be added relevantly quickly to support it at a Panel level (which I think is all that is required, as you would expect everything on a UIPanel to be drawn on the same layer.

I've edited NGUI's code to support it, but I just know someday I will forget to put the edits back in after an update. For those interested, this is my code to show a dropdown for sorting layers in UIPanel inspector (using the latest NGUI version).

In UIPanelInspector.cs, line 9 add:
  1. using UnityEditorInternal;
  2. using System.Reflection;
  3. using System;
  4.  

In UIPanelInspector.cs, line 458 add:
  1.         GUILayout.BeginHorizontal();
  2.         {
  3.             EditorGUILayout.PrefixLabel("Sorting Layer");
  4.  
  5.             // Get the names of the Sorting layers
  6.             System.Type internalEditorUtilityType = typeof(InternalEditorUtility);
  7.             PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
  8.             string[] names = (string[])sortingLayersProperty.GetValue(null, new object[0]);
  9.  
  10.             int index = 0;
  11.             if (!String.IsNullOrEmpty(mPanel.mSortingLayer))
  12.             {
  13.                 for (int i = 0; i < names.Length; i++)
  14.                 {
  15.                     if (mPanel.mSortingLayer == names[i])
  16.                     {
  17.                         index = i;
  18.                         break;
  19.                     }
  20.                 }
  21.             }
  22.  
  23.             // Get the selected index and update the panel sorting layer if it has changed
  24.             int selectedIndex = EditorGUILayout.Popup(index, names);
  25.             if (index != selectedIndex)
  26.             {
  27.                 mPanel.mSortingLayer = names[selectedIndex];
  28.                 EditorUtility.SetDirty(mPanel);
  29.             }
  30.         }
  31.         GUILayout.EndHorizontal();
  32.  

In UIDrawCall.cs, line 130 add:
  1.     public string sortingLayerName
  2.     {
  3.         get { return (mRenderer != null) ? mRenderer.sortingLayerName : ""; }
  4.         set { if (mRenderer != null && mRenderer.sortingLayerName != value) mRenderer.sortingLayerName = value; }
  5.     }
  6.  

In UIPanel.cs, line 97 add:
  1.     /// <summary>
  2.     /// The sorting layer for this panel, used to work with Unity 2D system
  3.     /// </summary>
  4.     public string mSortingLayer = "";
  5.  

In UIPanel.cs, line 263 add (this could potentially be optimised?):
  1. dc.sortingLayerName = mSortingLayer;
  2.  

Now you should have a dropdown for your UIPanels to select the sorting layer it should be drawn on.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #22 on: November 25, 2015, 06:06:54 PM »
Thanks! I've added it to my repository, so you will find it in the next version.

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: NGUI, 4.3 and new Sortyng Layers
« Reply #23 on: November 26, 2015, 04:37:32 AM »
Oh cool! Glad I could help :)