-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelationScript.cs
More file actions
151 lines (126 loc) · 5.92 KB
/
relationScript.cs
File metadata and controls
151 lines (126 loc) · 5.92 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class relationScript : MonoBehaviour
{
public float size;
public List<modelAsset> models = new List<modelAsset>();
public GameObject editOn;
public bool previewIsOn = false;
private GameObject lastCreated;
private GameObject lastCreatedUp;
private GameObject lastCreatedDown;
private GameObject lastCreatedLeft;
private GameObject lastCreatedRight;
private GameObject lastCreatedBack;
private GameObject lastCreatedForward;
public modelAsset modelAss;
public Vector3Int size2Fill;
public float fillPercent;
public List<unfinishedModelElement> unfinishedModelList = new List<unfinishedModelElement>();
public void buildObject() {
removeLastCreated(true);
lastCreated = GameObject.CreatePrimitive(PrimitiveType.Cube);
editOn = lastCreated;
modelAss = new modelAsset();
}
public void changeObject(GameObject go) {
if (go) {
GameObject newObject = Instantiate(go, Vector3.zero, go.transform.rotation, this.transform);
newObject.transform.position = lastCreated.transform.position;
newObject.transform.parent = go.transform.parent;
DestroyImmediate(lastCreated);
//This line is not really necessary but i still keep it
//DestroyImmediate(editOn);
lastCreated = newObject;
editOn = newObject;
}
}
public void saveModel() {
if(modelAss.Prefab != null) {
modelAss.objHeight = Mathf.Max(1, modelAss.objHeight);
models.Add(modelAss);
modelAss = new modelAsset();
}
}
public void removeLastCreated(bool isSelfDestroy) {
if (isSelfDestroy) {
DestroyImmediate(lastCreated);
}
//This is for returning back to a known state
DestroyImmediate(lastCreatedUp);
DestroyImmediate(lastCreatedDown);
DestroyImmediate(lastCreatedLeft);
DestroyImmediate(lastCreatedRight);
DestroyImmediate(lastCreatedBack);
DestroyImmediate(lastCreatedForward);
}
public void visualizeWithModel() {
if(modelAss.up == null || modelAss.down == null || modelAss.left == null ||
modelAss.right == null || modelAss.back == null || modelAss.forward == null) {
return;
}
removeLastCreated(false);
//Because we have 6 different lists this is the way i clear, this could be improved with one two dimensional array but at this time
//of the implementation I've used this structure, can be improved further with static arrays project wise
if (modelAss.up.Count > 0) {
DestroyImmediate(lastCreatedUp);
lastCreatedUp = Instantiate(modelAss.up[0], transform.position + Vector3.up * Mathf.Max(modelAss.objHeight, 1), modelAss.up[0].transform.rotation, this.transform);
}
if(modelAss.down.Count > 0) {
DestroyImmediate(lastCreatedDown);
lastCreatedDown = Instantiate(modelAss.down[0], transform.position + Vector3.down, modelAss.down[0].transform.rotation, this.transform);
}
if(modelAss.forward.Count > 0) {
DestroyImmediate(lastCreatedForward);
lastCreatedForward = Instantiate(modelAss.forward[0], transform.position + Vector3.forward, modelAss.forward[0].transform.rotation, this.transform);
}
if(modelAss.back.Count > 0) {
DestroyImmediate(lastCreatedBack);
lastCreatedBack = Instantiate(modelAss.back[0], transform.position + Vector3.back, modelAss.back[0].transform.rotation, this.transform);
}
if(modelAss.left.Count > 0) {
DestroyImmediate(lastCreatedLeft);
lastCreatedLeft = Instantiate(modelAss.left[0], transform.position + Vector3.left, modelAss.left[0].transform.rotation, this.transform);
}
if(modelAss.right.Count > 0) {
DestroyImmediate(lastCreatedRight);
lastCreatedRight = Instantiate(modelAss.right[0], transform.position + Vector3.right, modelAss.right[0].transform.rotation, this.transform);
}
}
public void visualizeWithPrefab(List<GameObject> l) {
visualizeWithPrefab(l, 1);
}
public void visualizeWithPrefab(List<GameObject> l, int height) {
if(l.Count != 6) {
Debug.Log("Not 6");
return;
}
removeLastCreated(false);
if (l[0] != null) {
lastCreatedUp = Instantiate(l[0], transform.position + Vector3.up * Mathf.Max(height,1), l[0].transform.rotation, this.transform);
}
if (l[1] != null) {
lastCreatedDown = Instantiate(l[1], transform.position + Vector3.down, l[1].transform.rotation, this.transform);
}
if (l[2] != null) {
lastCreatedForward = Instantiate(l[2], transform.position + Vector3.forward, l[2].transform.rotation, this.transform);
}
if (l[3] != null) {
lastCreatedBack = Instantiate(l[3], transform.position + Vector3.back, l[3].transform.rotation, this.transform);
}
if (l[4] != null) {
lastCreatedLeft = Instantiate(l[4], transform.position + Vector3.left, l[4].transform.rotation, this.transform);
}
if (l[5] != null) {
lastCreatedRight = Instantiate(l[5], transform.position + Vector3.right, l[5].transform.rotation, this.transform);
}
}
private void OnDrawGizmosSelected() {
//This is the color of the wireframe, it is a good way to start exposing this variable to the inspector as the first thing to do in this project.
Gizmos.color = new Color32(0, 255, 0, 255);
Gizmos.DrawWireCube(transform.position, size2Fill);
}
}