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

Pages: [1]
1
NGUI 3 Support / Re: NGUI, 4.3 and new Sortyng Layers
« on: January 07, 2014, 10:59:38 AM »
We have to combine SkinnedMeshRenderer with NGUI UIPanels in  Unity 4.3.x. In this case we have to handle the sorting layers in NGUI. Is the following code a correct way to do this?
I used the SortingLayerExposed-Script (https://gist.github.com/nickgravelyn/7460288) to set the SortingLayer for the SkinnedMashRenderer. In NGUI I did the following patch:

In UIPanel.cs I added:

  1. 67      public int sortingOrder = 0;
  2. 68      public int sortingLayerID = 0;
  3.  
In UIDrawCall GetDrawCall (int index, Material mat) I added after:

  1. 397       // Create the draw call
  2. 398      UIDrawCall drawCall = go.AddComponent<UIDrawCall>();
  3. 399      drawCall.baseMaterial = mat;
  4. 400      drawCall.renderQueue = UIDrawCall.list.size;
  5. 401      drawCall.panel = this;
  6.  
the lines

  1. 402       drawCall.sortingLayerID = sortingLayerID;
  2. 403           drawCall.sortingOrder = sortingOrder;
  3.  

In UIDrawCall.cs I added:

  1. 43   public int sortingLayerID
  2. 44   {
  3. 45      get
  4. 46      {
  5. 47         return mSortingLayerID;
  6. 48      }
  7. 49      set
  8. 50      {
  9. 51         if (mSortingLayerID != value)
  10. 52         {
  11. 53            mSortingLayerID = value;
  12. 54            
  13. 55            if (mRen != null)
  14. 56            {
  15. 57               mRen.sortingLayerID = mSortingLayerID;
  16. 58               UnityEditor.EditorUtility.SetDirty(gameObject);
  17. 59            }
  18. 60         }
  19. 61      }
  20. 62   }
  21. 63   int mSortingLayerID;
  22. 64
  23. 65   public int sortingOrder
  24. 66   {
  25. 67      get
  26. 68      {
  27. 69         return mSortingOrder;
  28. 70      }
  29. 71      set
  30. 72      {
  31. 73         if (mSortingOrder != value)
  32. 74         {
  33. 75            mSortingOrder = value;
  34. 76            
  35. 77            if (mRen != null)
  36. 78            {
  37. 79               mRen.sortingOrder = mSortingOrder;
  38. 80               UnityEditor.EditorUtility.SetDirty(gameObject);
  39. 81            }
  40. 82         }
  41. 83      }
  42. 84   }
  43. 85   int mSortingOrder;

In public void Set (BetterList<Vector3> verts, BetterList<Vector3> norms, BetterList<Vector4> tans, BetterList<Vector2> uvs, BetterList<Color32> cols) I added after:

  1. 363         if (mRen == null)
  2. 364         {
  3. 365            mRen = gameObject.GetComponent<MeshRenderer>();
  4. 366         }
  5.  
the lines:

  1. 368         if (mRen != null)
  2. 369         {
  3. 370            mRen.sortingLayerID = sortingLayerID;
  4. 371            mRen.sortingOrder = sortingOrder;
  5. 372         }

And after:

  1. 374         if (mRen == null)
  2. 375         {
  3. 376            mRen = gameObject.AddComponent<MeshRenderer>();
  4.  

the lines:

  1. 377            mRen.sortingLayerID = sortingLayerID;
  2. 378            mRen.sortingOrder = sortingOrder;
  3.  

Finally I added in UIPanelInspector.cs after:

  1. 211      if (clipping != UIDrawCall.Clipping.None && !NGUIEditorTools.IsUniform(panel.transform.lossyScale))
  2. 212      {
  3. 213         EditorGUILayout.HelpBox("Clipped panels must have a uniform scale, or clipping won't work properly!", MessageType.Error);
  4. 214        
  5. 215         if (GUILayout.Button("Auto-fix"))
  6. 216         {
  7. 217            NGUIEditorTools.FixUniform(panel.gameObject);
  8. 218         }
  9. 219      }
  10.  

the lines:

  1. 221   int newSortingLayerId = EditorGUILayout.IntField("SOL ID", panel.sortingLayerID);
  2. 222   if (newSortingLayerId != panel.sortingLayerID)
  3. 223    {
  4. 224         panel.sortingLayerID = newSortingLayerId;
  5. 225         UnityEditor.EditorUtility.SetDirty(panel);
  6. 226   }
  7. 227
  8. 228   int newSortingLayerOrder = EditorGUILayout.IntField("SOL Order", panel.sortingOrder);
  9. 229    if (newSortingLayerOrder != panel.sortingOrder)
  10. 230   {
  11. 231         panel.sortingOrder = newSortingLayerOrder;
  12. 232         UnityEditor.EditorUtility.SetDirty(panel);
  13. 233    }
  14.  
  15.  

Pages: [1]