TestLineRegression.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using o0;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class TestLineRegression : MonoBehaviour
  7. {
  8. List<Vector2> coordsCS = new List<Vector2>();
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. var scale = 2;
  13. for (int i = 0; i < 1; i++)
  14. {
  15. for (int j = 0; j < 100; j+= scale)
  16. {
  17. var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  18. cube.transform.SetParent(transform, false);
  19. cube.transform.localScale = Vector3.one / 20;
  20. cube.transform.localPosition = new Vector3(i, j, 0);
  21. coordsCS.Add(Camera.main.WorldToScreenPoint(cube.transform.position));
  22. }
  23. }
  24. Debug.Log(coordsCS.Last());
  25. (double[], double[]) dataX;
  26. (double[], double[]) dataY;
  27. var index = new double[coordsCS.Count];
  28. var x = new double[coordsCS.Count];
  29. var y = new double[coordsCS.Count];
  30. for (int i = 0; i < coordsCS.Count; i++)
  31. {
  32. index[i] = i * scale;
  33. x[i] = coordsCS[i].x;
  34. y[i] = coordsCS[i].y;
  35. }
  36. dataX = (index, x);
  37. dataY = (index, y);
  38. "dataX.js".FileWriteString(dataX.ToJson(true));
  39. "dataY.js".FileWriteString(dataY.ToJson(true));
  40. }
  41. // Update is called once per frame
  42. void Update()
  43. {
  44. if (Input.GetButtonDown("Fire1"))
  45. {
  46. Vector3 mousePos = Input.mousePosition;
  47. {
  48. Debug.Log(mousePos);
  49. }
  50. }
  51. }
  52. }