Search Unity

SharedComponentDataProxy does not render custom properties in Inspector

Discussion in 'Graphics for ECS' started by davenirline, Mar 18, 2019.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    987
    I have this script that used to work with SharedComponentDataWrapper.

    Code (CSharp):
    1. public class SpriteInstanceRendererComponent : SharedComponentDataProxy<RenderMesh> {
    2.     [SerializeField]
    3.     private Sprite sprite;
    4.  
    5.     [SerializeField]
    6.     private Material material;
    7.  
    8.     // The width of the sprite in world units
    9.     private float width;
    10.  
    11.     // The height of the sprite in world units
    12.     private float height;
    13.  
    14.     private void Awake() {
    15.         // Prepare the mesh
    16.         Mesh mesh = new Mesh();
    17.  
    18.         // Copy vertices
    19.         Vector3[] vertices = new Vector3[this.sprite.vertices.Length];
    20.         for(int i = 0; i < vertices.Length; ++i) {
    21.             vertices[i] = this.sprite.vertices[i];
    22.         }
    23.         mesh.vertices = vertices;
    24.        
    25.         // Compute width and height
    26.         this.width = Mathf.Abs(this.sprite.vertices[1].x - this.sprite.vertices[0].x);
    27.         this.height = Mathf.Abs(this.sprite.vertices[1].y - this.sprite.vertices[0].y);
    28.  
    29.         // Copy triangles
    30.         int[] triangles = new int[this.sprite.triangles.Length];
    31.         for(int i = 0; i < triangles.Length; ++i) {
    32.             triangles[i] = this.sprite.triangles[i];
    33.         }
    34.         mesh.triangles = triangles;
    35.  
    36.         // Copy UV
    37.         mesh.uv = this.sprite.uv;
    38.  
    39.         RenderMesh instance = new RenderMesh();
    40.         instance.mesh = mesh;
    41.         instance.material = this.material;
    42.         this.Value = instance;
    43.     }
    44.  
    45.     public float Height {
    46.         get {
    47.             return this.height;
    48.         }
    49.     }
    50.  
    51.     public float Width {
    52.         get {
    53.             return this.width;
    54.         }
    55.     }
    56. }
    What it does is it copies the mesh values from a sprite unto a RenderMesh. In preview.29, the Inspector no longer lets me assign the sprite variable.

    upload_2019-3-18_23-49-13.png

    Any workaround for this?
     
  2. Lurendium

    Lurendium

    Joined:
    Nov 25, 2016
    Posts:
    8
  3. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    DataWrappers are deprecated. You should use the new conversion workflow both described in the blog above and here in the forum.