Created
July 30, 2017 12:12
-
-
Save tarukosu/fd17f182796aa137805d3e8e8dba6f9b to your computer and use it in GitHub Desktop.
SweepVisualizer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using UnityEngine; | |
| namespace UnitySweep { | |
| public class SweepVisualizer : MonoBehaviour { | |
| public GameObject PointPrefab; | |
| Sweep Sweep; | |
| List<GameObject> pointList; | |
| void Start() { | |
| pointList = new List<GameObject>(); | |
| Sweep = GetComponent<Sweep>(); | |
| Sweep.ScanUpdated += ScanUpdated; | |
| } | |
| void ScanUpdated(Scan scan) | |
| { | |
| //clear old points | |
| foreach(var oldPoint in pointList) | |
| { | |
| Destroy(oldPoint); | |
| } | |
| foreach (var sample in scan.Samples) | |
| { | |
| var position = sample.Distance * new Vector3(Mathf.Cos(Mathf.Deg2Rad * sample.Angle), 0, Mathf.Sin(Mathf.Deg2Rad * sample.Angle)); | |
| var point = Instantiate(PointPrefab, position, Quaternion.identity, transform); | |
| pointList.Add(point); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment