Advertisement
apieceoffruit

SetAPropertyBlockColor

May 20th, 2021
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1.     public class PropertyBlockColorable : IColorable
  2.     {
  3.         public PropertyBlockColorable(Renderer renderer,string colorProperty = COLOR)
  4.         {
  5.             _block = new MaterialPropertyBlock();
  6.             _renderer = renderer;
  7.             _id = Shader.PropertyToID(colorProperty);
  8.         }
  9.  
  10.         public Color Color
  11.         {
  12.             get => _block.GetColor(_id);
  13.             set
  14.             {
  15.                 _block.SetColor(_id,value);
  16.                 _renderer.SetPropertyBlock(_block);
  17.             }
  18.         }
  19.  
  20.         readonly Renderer _renderer;
  21.         readonly MaterialPropertyBlock _block;
  22.         readonly int _id;
  23.         const string COLOR = "_Color";
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement