forked from MicroGSD/RoadArchitect
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GSDRoadSystem.cs
100 lines (86 loc) · 2.73 KB
/
GSDRoadSystem.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
using UnityEngine;
#if UNITY_EDITOR
using System.Collections;
#endif
public class GSDRoadSystem : MonoBehaviour{
#if UNITY_EDITOR
public bool opt_bMultithreading = true;
public bool opt_bSaveMeshes = false;
public bool opt_bAllowRoadUpdates = true;
public GameObject AddRoad(bool bForceSelect = false){
Object[] tObj = GameObject.FindObjectsOfType(typeof(GSDRoad));
int NewRoadNumber = (tObj.Length+1);
//Road:
GameObject tRoadObj = new GameObject("Road" + NewRoadNumber.ToString());
UnityEditor.Undo.RegisterCreatedObjectUndo(tRoadObj, "Created road");
tRoadObj.transform.parent = transform;
GSDRoad tRoad = tRoadObj.AddComponent<GSDRoad>();
//Spline:
GameObject tSplineObj = new GameObject("Spline");
tSplineObj.transform.parent = tRoad.transform;
tRoad.GSDSpline = tSplineObj.AddComponent<GSDSplineC>();
tRoad.GSDSpline.mSplineRoot = tSplineObj;
tRoad.GSDSpline.tRoad = tRoad;
tRoad.GSDSplineObj = tSplineObj;
tRoad.GSDRS = this;
tRoad.SetupUniqueIdentifier();
tRoad.ConstructRoad_ResetTerrainHistory();
if(bForceSelect){
UnityEditor.Selection.activeGameObject = tRoadObj;
}
return tRoadObj;
}
public Camera EditorPlayCamera = null;
public void EditorCameraSetSingle(){
if(EditorPlayCamera == null){
Camera[] EditorCams = (Camera[])GameObject.FindObjectsOfType(typeof(Camera));
if(EditorCams != null && EditorCams.Length == 1){
EditorPlayCamera = EditorCams[0];
}
}
}
public void UpdateAllRoads(){
GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));
// int i=0;
int RoadCount = tRoadObjs.Length;
GSDRoad tRoad = null;
GSDSplineC[] tPiggys = null;
if(RoadCount > 1){
tPiggys = new GSDSplineC[RoadCount];
for (int h = 0; h < RoadCount; h++) {
tRoad = tRoadObjs[h];
tPiggys[h] = tRoad.GSDSpline;
}
}
tRoad=tRoadObjs[0];
if(tPiggys != null && tPiggys.Length > 0){
tRoad.PiggyBacks = tPiggys;
}
tRoad.UpdateRoad();
}
//Workaround for submission rules:
public void UpdateAllRoads_MultiThreadOptions(){
GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));
int RoadCount = tRoadObjs.Length;
GSDRoad tRoad = null;
for(int h=0;h<RoadCount;h++){
tRoad=tRoadObjs[h];
if(tRoad != null){
tRoad.opt_bMultithreading = opt_bMultithreading;
}
}
}
//Workaround for submission rules:
public void UpdateAllRoads_SaveMeshesAsAssetsOptions(){
GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));
int RoadCount = tRoadObjs.Length;
GSDRoad tRoad = null;
for(int h=0;h<RoadCount;h++){
tRoad=tRoadObjs[h];
if(tRoad != null){
tRoad.opt_bSaveMeshes = opt_bSaveMeshes;
}
}
}
#endif
}