FoldLinesGeneratorNew.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using JTSystems;
  6. public class FoldLinesGeneratorNew : MonoBehaviour
  7. {
  8. [Header(" Components ")]
  9. [SerializeField] private LineRenderer linePrefab;
  10. private Paper currentPaper;
  11. private void Awake()
  12. {
  13. // LevelManager.onPaperInstantiated += DrawFoldingLines;
  14. // UIManager.onLevelCompleteSet += ClearPaperDelegates;
  15. }
  16. private void OnDestroy()
  17. {
  18. }
  19. private void ClearPaperDelegates(int none)
  20. {
  21. currentPaper.onPaperStateChanged -= UpdateFoldingLines;
  22. currentPaper = null;
  23. UpdateFoldingLines();
  24. }
  25. public void DrawFoldingLines(Paper paper)
  26. {
  27. Debug.Log("DrawFoldingLines");
  28. currentPaper = paper;
  29. currentPaper.onPaperStateChanged += UpdateFoldingLines;
  30. UpdateFoldingLines();
  31. }
  32. private void UpdateFoldingLines()
  33. {
  34. transform.Clear();
  35. if (currentPaper == null) return;
  36. Folding[] foldings = currentPaper.GetFoldings(false);
  37. foreach (Folding folding in foldings)
  38. if (!folding.IsFolded())
  39. DrawFolding(folding);
  40. }
  41. private void DrawFolding(Folding folding)
  42. {
  43. LineRenderer line = Instantiate(linePrefab, transform);
  44. Vector3[] foldingDirection = folding.GetRotationAxis().AsLine();
  45. Vector3 p0 = foldingDirection[0].With(y: currentPaper.transform.position.y + -0.05f);
  46. Vector3 p1 = foldingDirection[1].With(y: currentPaper.transform.position.y + -0.05f);
  47. line.SetPosition(0, p0);
  48. line.SetPosition(1, p1);
  49. }
  50. }