Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

UI BaseVertexEffect Change to BaseMeshEffect

Discussion in '5.2 Beta' started by amit1532, Jul 4, 2015.

  1. amit1532

    amit1532

    Joined:
    Jul 19, 2010
    Posts:
    305
    Hello,
    BaseVertexEffect had a virtual method that gets a list of UIVertex
    which i used to add vertices and reorder the existing ones...
    Now I get a mesh and tried to add vertices and colors but it just causes the text to disappear
    I have also tried adding indices but it doesnt work either..
    And I cannot go back to BaseVertexEffect because it is forcing me to use BaseMeshEffect by an error.

    The code i used to have in 5.0: http://pastebin.com/9Z1D130h
     
  2. fpuig

    fpuig

    Joined:
    Dec 26, 2012
    Posts:
    18
    Hi,
    I had your same issue. To solved it, I just followed the same approach the new Shadow effect does.

    Code (csharp):
    1.  
    2.     #if UNITY_5_2
    3.     public partial class MyEffect : BaseMeshEffect
    4.     #else
    5.     public partial class MyEffect : BaseVertexEffect
    6.     #endif
    7.     {
    8.         #if UNITY_5_2
    9.         public override void ModifyMesh (Mesh mesh)
    10.         {
    11.             if (!this.IsActive())
    12.                 return;
    13.  
    14.             List<UIVertex> list = new List<UIVertex>();
    15.             using (VertexHelper vertexHelper = new VertexHelper(mesh))
    16.             {
    17.                 vertexHelper.GetUIVertexStream(list);
    18.             }
    19.  
    20.             ModifyVertices(list);  // calls the old ModifyVertices which was used on pre 5.2
    21.  
    22.             using (VertexHelper vertexHelper2 = new VertexHelper())
    23.             {
    24.                 vertexHelper2.AddUIVertexTriangleStream(list);
    25.                 vertexHelper2.FillMesh(mesh);
    26.             }
    27.         }
    28.         #endif
    29.  
    30.         public void ModifyVertices(List<UIVertex> verts)
    31.         {
    32.                 // you code goes here
    33.         }
    34.  

    Notice that my declaration uses BaseMeshEffect when 5.2 and BaseVertexEffect otherwise.

    Also notice, that the list vertices now has triangles instead of quads.
     
  3. amit1532

    amit1532

    Joined:
    Jul 19, 2010
    Posts:
    305
    Thanks! Didnt notice they updated the code for the shadow effect.
    Ill check that out as soon as I can
     
  4. Iron27

    Iron27

    Joined:
    May 5, 2014
    Posts:
    10
    Thanks for the example fpuig. Is this UI source for 5.2 beta available yet thought? The latest update I see on the Bitbucket repo is from April...

    Edit: Decompiling seems to be good enough for now.
     
    Last edited: Jul 7, 2015
  5. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Thank you so much for sharing the solution! Works great!