Search Unity

  1. The 2021.2 beta is now available. To find out what's new, have a look at our 2021.2 beta blog post.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

Change Material Texture

Discussion in 'Project Tiny' started by YoungDeveloper, Apr 8, 2021.

  1. YoungDeveloper

    YoungDeveloper

    Joined:
    Jun 28, 2013
    Posts:
    52
    Hi, I want to create texture2D animation for MeshRenderer material, how should I do it?
    Problem is that I have Texture2D but it required Entity.

    Check line 19. in TextureAnimationSystem


    Code (CSharp):
    1.  
    2. using Unity.Entities;
    3. using UnityEngine;
    4.  
    5. [GenerateAuthoringComponent]
    6. public struct TextureAnimationComponent : IComponentData
    7. {
    8.     public int index;
    9.     public Texture2D[] textures;
    10. }
    Code (CSharp):
    1.  
    2. using Unity.Entities;
    3. using Unity.Tiny.Rendering;
    4. using UnityEngine;
    5.  
    6. public class TextureAnimationSystem : SystemBase
    7. {
    8.     protected override void OnUpdate()
    9.     {
    10.         Entities.ForEach((TextureAnimationComponent component, ref Unity.Tiny.Rendering.MeshRenderer meshRenderer) =>
    11.         {
    12.             Entity materialEntity = meshRenderer.material;
    13.             LitMaterial material = EntityManager.GetComponentData<LitMaterial>(materialEntity);
    14.  
    15.             component.index = (component.index + 1) % component.textures.Length;
    16.             Texture2D tex = component.textures[component.index];
    17.  
    18.             // PROBLEM
    19.             material.texNormal = tex; // requires Entity not Texture2D
    20.  
    21.         }).WithoutBurst().Run();
    22.     }
    23. }
     
    Last edited: Apr 8, 2021
unityunity