12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using JTSystems;
- public class FoldLinesGeneratorNew : MonoBehaviour
- {
- [Header(" Components ")]
- [SerializeField] private LineRenderer linePrefab;
- private Paper currentPaper;
- private void Awake()
- {
- // LevelManager.onPaperInstantiated += DrawFoldingLines;
- // UIManager.onLevelCompleteSet += ClearPaperDelegates;
- }
-
- private void OnDestroy()
- {
-
- }
- private void ClearPaperDelegates(int none)
- {
- currentPaper.onPaperStateChanged -= UpdateFoldingLines;
- currentPaper = null;
- UpdateFoldingLines();
- }
- public void DrawFoldingLines(Paper paper)
- {
- Debug.Log("DrawFoldingLines");
- currentPaper = paper;
- currentPaper.onPaperStateChanged += UpdateFoldingLines;
- UpdateFoldingLines();
- }
- private void UpdateFoldingLines()
- {
- transform.Clear();
- if (currentPaper == null) return;
- Folding[] foldings = currentPaper.GetFoldings(false);
- foreach (Folding folding in foldings)
- if (!folding.IsFolded())
- DrawFolding(folding);
- }
- private void DrawFolding(Folding folding)
- {
- LineRenderer line = Instantiate(linePrefab, transform);
- Vector3[] foldingDirection = folding.GetRotationAxis().AsLine();
- Vector3 p0 = foldingDirection[0].With(y: currentPaper.transform.position.y + -0.05f);
- Vector3 p1 = foldingDirection[1].With(y: currentPaper.transform.position.y + -0.05f);
- line.SetPosition(0, p0);
- line.SetPosition(1, p1);
- }
- }
|