105 lines
3.0 KiB
C#
105 lines
3.0 KiB
C#
using NUnit.Framework;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DrawGrid : MonoBehaviour
|
|
{
|
|
public GameObject line_h;
|
|
public GameObject line_v;
|
|
|
|
public int lineCount;
|
|
public float lineLength;
|
|
public float lineThickness;
|
|
float lineHeight = 0.001f;
|
|
|
|
List<GameObject> detailLines = new();
|
|
List<GameObject> ThickLines = new();
|
|
bool detailLineActive = true;
|
|
|
|
public Transform playerPos;
|
|
public float detailLineDeactiveHeight = 20;
|
|
|
|
private void Start()
|
|
{
|
|
for (int i = 0; i < lineCount; i++)
|
|
{
|
|
Vector3 linePos_h = new Vector3(0, 0, i);
|
|
GameObject plusLine_h = Instantiate(line_h, linePos_h, line_h.transform.rotation, transform);
|
|
GameObject minusLine_h = Instantiate(line_h, -linePos_h, line_h.transform.rotation, transform);
|
|
|
|
Vector3 linePos_v = new Vector3(i, 0, 0);
|
|
GameObject plusLine_v = Instantiate(line_v, linePos_v, line_v.transform.rotation, transform);
|
|
GameObject minusLine_v = Instantiate(line_v, -linePos_v, line_v.transform.rotation, transform);
|
|
|
|
plusLine_h.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness);
|
|
minusLine_h.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness);
|
|
plusLine_v.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness);
|
|
minusLine_v.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness);
|
|
|
|
if (i % 10 != 0)
|
|
{
|
|
detailLines.Add(plusLine_h);
|
|
detailLines.Add(minusLine_h);
|
|
detailLines.Add(plusLine_v);
|
|
detailLines.Add(minusLine_v);
|
|
}
|
|
else
|
|
{
|
|
ThickLines.Add(plusLine_h);
|
|
ThickLines.Add(minusLine_h);
|
|
ThickLines.Add(plusLine_v);
|
|
ThickLines.Add(minusLine_v);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
float playerHeight = playerPos.position.y;
|
|
|
|
if (playerHeight > detailLineDeactiveHeight)
|
|
{
|
|
DeactivateDetailLine();
|
|
}
|
|
else
|
|
{
|
|
ActivateDetailLine();
|
|
}
|
|
}
|
|
|
|
void ActivateDetailLine()
|
|
{
|
|
if (detailLineActive)
|
|
return;
|
|
|
|
foreach (GameObject line in detailLines)
|
|
{
|
|
line.gameObject.SetActive(true);
|
|
}
|
|
foreach (GameObject line in ThickLines)
|
|
{
|
|
line.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness);
|
|
}
|
|
|
|
detailLineActive = true;
|
|
}
|
|
|
|
void DeactivateDetailLine()
|
|
{
|
|
if (!detailLineActive)
|
|
return;
|
|
|
|
foreach (GameObject line in detailLines)
|
|
{
|
|
line.gameObject.SetActive(false);
|
|
}
|
|
foreach (GameObject line in ThickLines)
|
|
{
|
|
line.transform.localScale = new Vector3(lineLength, lineHeight, lineThickness * 4);
|
|
}
|
|
|
|
detailLineActive = false;
|
|
}
|
|
|
|
}
|