SmoothCurveGraphTexture.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace VertexAnimationTools_30{
  5. public class SmoothCurveGraphTexture {
  6. Color32[] clearPixels;
  7. Color32[] pixels;
  8. Color32 redPixel = new Color32((byte)255, (byte)0, (byte)0, (byte)80);
  9. Color32 backgroundPixel = new Color32((byte)255, (byte)255, (byte)255, (byte)120);
  10. public Texture2D GraphTexture;
  11. public SmoothCurveGraphTexture(float minAmount, float maxAmount, float easeOffset, float easeLength, bool isDarkTheme){
  12. if (isDarkTheme) {
  13. redPixel = new Color32((byte)255, (byte)100, (byte)100, (byte)255);
  14. backgroundPixel = new Color32((byte)100, (byte)100, (byte)100, (byte)255);
  15. }
  16. GraphTexture = new Texture2D(200,100, TextureFormat.ARGB32, false);
  17. clearPixels = new Color32[20000];
  18. for(int i = 0; i<clearPixels.Length; i++){
  19. clearPixels[i] = backgroundPixel;
  20. }
  21. pixels = new Color32[20000];
  22. RepaintTexture(minAmount, maxAmount, easeOffset, easeLength);
  23. }
  24. public void RepaintTexture( float minAmount, float maxAmount, float easeOffset, float easeLength){
  25. clearPixels.CopyTo( pixels, 0);
  26. for(int x = 0; x<GraphTexture.width; x++){
  27. float fx = x*0.005f;
  28. float val = Extension.SmoothLoopCurve(fx, minAmount, maxAmount, easeOffset, easeLength);
  29. int columnHeight = (int)(val * 100f);
  30. columnHeight = Mathf.Clamp( columnHeight,0,99);
  31. for(int y = 0; y<columnHeight; y++){
  32. int pixelIdx = y*200+x;
  33. pixels[pixelIdx] = redPixel;
  34. }
  35. }
  36. GraphTexture.SetPixels32( pixels );
  37. GraphTexture.Apply();
  38. }
  39. }
  40. }