This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
forked from MicroGSD/RoadArchitect
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GSDTerrain.cs
116 lines (101 loc) · 2.58 KB
/
GSDTerrain.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#region "Imports"
using UnityEngine;
using System.Collections.Generic;
#endregion
[ExecuteInEditMode]
public class GSDTerrain : MonoBehaviour
{
#if UNITY_EDITOR
[SerializeField]
[HideInInspector]
private int mGSDID = -1;
public int GSDID
{
get { return mGSDID; }
set
{
//Do nothing.
}
}
[HideInInspector]
public Terrain tTerrain;
//Splat map:
public int SplatResoWidth = 1024;
public int SplatResoHeight = 1024;
public Color SplatBackground = new Color(0f, 0f, 0f, 1f);
public Color SplatForeground = new Color(1f, 1f, 1f, 1f);
public float SplatWidth = 30f;
public bool SplatSkipBridges = false;
public bool SplatSkipTunnels = false;
public bool SplatSingleRoad = false;
public int SplatSingleChoiceIndex = 0;
public string RoadSingleChoiceUID = "";
private void OnEnable()
{
CheckID();
if (!tTerrain)
{
tTerrain = transform.gameObject.GetComponent<Terrain>();
}
}
public void CheckID()
{
if (Application.isEditor)
{
if (mGSDID < 0)
{
mGSDID = GetNewID();
}
if (!tTerrain)
{
tTerrain = transform.gameObject.GetComponent<Terrain>();
}
}
}
private int GetNewID()
{
Object[] tTerrainObjs = GameObject.FindObjectsOfType(typeof(GSDTerrain));
List<int> AllIDS = new List<int>();
foreach (GSDTerrain TID in tTerrainObjs)
{
if (TID.GSDID > 0)
{
AllIDS.Add(TID.GSDID);
}
}
bool bNotDone = true;
int SpamChecker = 0;
int SpamCheckerMax = AllIDS.Count + 64;
int tRand;
while (bNotDone)
{
if (SpamChecker > SpamCheckerMax)
{
Debug.LogError("Failed to generate GSDTerrainID");
break;
}
tRand = Random.Range(1, 2000000000);
if (!AllIDS.Contains(tRand))
{
bNotDone = false;
return tRand;
}
SpamChecker += 1;
}
return -1;
}
#endif
private void Start()
{
#if UNITY_EDITOR
this.enabled = true;
CheckID();
if (!tTerrain)
{
tTerrain = transform.gameObject.GetComponent<Terrain>();
}
#else
this.enabled = false;
#endif
}
}