Skip to content

Instantly share code, notes, and snippets.

/2017-03-25_11-57-16.txt Secret
Created Mar 25, 2017

Embed
What would you like to do?
public class VectrosityGrid : MonoBehaviour
{
public float GridSize;
public Bounds GridBounds;
public float VerticalOffset;
public Material GridMaterial;
[SerializeField] private bool _gridDirty;
private VectorLine _line;
private WorldEvents _events;
private World _world;
private ChunkHandler _chunkHandler;
// Use this for initialization
void Start()
{
_gridDirty = true;
_line = new VectorLine("Grid", new List<Vector3>(), 1.5f, LineType.Discrete);
_line.color = new Color32(255, 255, 255, 255);
_line.material = GridMaterial;
_line.rectTransform.SetParent(transform.parent);
// get the chunk handler
_chunkHandler = GetComponent<ChunkHandler>();
GridBounds = _chunkHandler.Chunk.Bounds;
}
// Update is called once per frame
void Update()
{
if (_gridDirty)
RegenerateGrid();
}
private void RegenerateGrid()
{
_line.points3.Clear();
//float x = GridBounds.min.x;
for (float x = GridBounds.min.x; x < GridBounds.max.x; x += GridSize)
{
// draw the "vertical" lines
_line.points3.Add(new Vector3(x, VerticalOffset, GridBounds.min.z));
_line.points3.Add(new Vector3(x, VerticalOffset, GridBounds.max.z));
}
// also draw the right-most point.
_line.points3.Add(new Vector3(GridBounds.max.x, VerticalOffset, GridBounds.max.z));
_line.points3.Add(new Vector3(GridBounds.max.x, VerticalOffset, GridBounds.min.z));
for (float z = GridBounds.min.z; z < GridBounds.max.z; z += GridSize)
{
// draw the "vertical" lines
_line.points3.Add(new Vector3(GridBounds.min.x, VerticalOffset, z));
_line.points3.Add(new Vector3(GridBounds.max.x, VerticalOffset, z));
}
// also draw the top-most line
_line.points3.Add(new Vector3(GridBounds.min.x, VerticalOffset, GridBounds.max.z));
_line.points3.Add(new Vector3(GridBounds.max.x, VerticalOffset, GridBounds.max.z));
_line.Draw3DAuto();
_gridDirty = false;
}
private void OnDrawGizmos()
{
Gizmos.DrawWireCube(GridBounds.center, GridBounds.size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.