-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrackGeneratorEditor.cs
More file actions
82 lines (76 loc) · 2.15 KB
/
TrackGeneratorEditor.cs
File metadata and controls
82 lines (76 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TrackGenerator))]
public class TrackGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
TrackGenerator generator = (TrackGenerator)target;
if (GUILayout.Button("Random"))
{
GenerateRandom(generator);
}
if (GUILayout.Button("Looping"))
{
generator.Expand(Directions.Looping);
}
if (GUILayout.Button("Forward"))
{
generator.Expand(Directions.Forward);
}
if (GUILayout.Button("Fast Forward"))
{
for (int i = 0; i < 20; i++)
{
generator.Expand(Directions.Forward);
}
}
if (GUILayout.Button("Left"))
{
generator.Expand(Directions.Left);
}
if (GUILayout.Button("Right"))
{
generator.Expand(Directions.Right);
}
if (GUILayout.Button("Reset"))
{
generator.Reset();
}
}
private static void GenerateRandom(TrackGenerator generator)
{
bool curve = true;
bool curveLeft = false;
bool curveRight = false;
for (int i = 0; i < 100; i++)
{
float random = Random.Range(0, 2f);
if (random <= 1f || curve)
{
for (int k = 0; k < 5; k++)
{
curve = false;
generator.Expand(Directions.Forward);
}
}
else if (random > 1f && random < 1.5f && !curveLeft)
{
curve = true;
curveLeft = true;
curveRight = false;
generator.Expand(Directions.Left);
}
else if (!curveRight)
{
curve = true;
curveLeft = false;
curveRight = true;
generator.Expand(Directions.Right);
}
}
}
}