BarcodeEncoder.cs 796 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. class BarcodeEncoder : MonoBehaviour
  5. {
  6. [SerializeField] int Row = 5;
  7. [SerializeField] int Column = 5;
  8. [SerializeField] Shader Shader;
  9. Material material_;
  10. public Material Material => material_;
  11. private void Awake()
  12. {
  13. if (Shader == null)
  14. throw new InvalidOperationException("Shader is null");
  15. if (Row * Column > 32)
  16. throw new InvalidOperationException("Not supported over 32bit numbers");
  17. material_ = new Material(Shader);
  18. GetComponent<RawImage>().material = material_;
  19. material_.SetInt("_Row", Row);
  20. material_.SetInt("_Column", Column);
  21. }
  22. public void SetValue(int value)
  23. {
  24. material_.SetInt("_Value", value);
  25. }
  26. }