Skip to content

Commit d64dd34

Browse files
committed
V0.1a Basic structure and editor window.
1 parent b63e3db commit d64dd34

6 files changed

Lines changed: 374 additions & 16 deletions

File tree

LICENSE.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 288 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,304 @@
11
// Editor script of modular system
22
// Author: Heavyskymobile - Rozx
3-
// Date: 2016-10-13
4-
// Version 0.1
3+
// Date: 2016-11-05
4+
// Version 0.1a
55

66

77

88
using UnityEngine;
99
using UnityEditor;
10+
using UnityEditorInternal;
1011
using System.Collections.Generic;
1112

1213
namespace ModularSystem{
1314

1415
[CustomEditor(typeof(ModularSystem))]
1516
public class ModularEditor : Editor{
1617

18+
19+
public ModularSystem modularSystem;
20+
21+
private bool partSetFoldout;
22+
private List<ReorderableList> partLists = new List<ReorderableList>();
23+
24+
private int drawingListIndex;
25+
26+
// This function is called when the object is loaded.
27+
protected void OnEnable()
28+
{
29+
30+
modularSystem = (ModularSystem)target;
31+
32+
UpdatePartList();
33+
34+
}
35+
36+
37+
public override void OnInspectorGUI()
38+
{
39+
40+
//modularSystem = (ModularSystem)target;
41+
42+
EditorGUILayout.BeginVertical();
43+
44+
// display the basic information
45+
46+
47+
// display random seed options
48+
49+
50+
modularSystem.mySeedMode = (RandomSeedMode)EditorGUILayout.EnumPopup("Random Seed Mode",modularSystem.mySeedMode);
51+
52+
53+
switch(modularSystem.mySeedMode){
54+
55+
56+
case RandomSeedMode.Default:
57+
58+
EditorGUILayout.HelpBox("Default seed mode is the mode that allow system and unity engine automatically generate the random seed.",MessageType.Info);
59+
60+
61+
break;
62+
63+
case RandomSeedMode.Manual:
64+
65+
EditorGUILayout.BeginHorizontal();
66+
67+
modularSystem.randomSeed = EditorGUILayout.IntField("Random Seed:", modularSystem.randomSeed);
68+
69+
if(GUILayout.Button("Randomize seed")){
70+
71+
72+
73+
}
74+
75+
76+
EditorGUILayout.EndHorizontal();
77+
78+
EditorGUILayout.HelpBox("Manual Seed mode allow you to manually configure the random seed.",MessageType.Info);
79+
80+
81+
break;
82+
83+
84+
case RandomSeedMode.PositionBased:
85+
86+
EditorGUILayout.HelpBox("Position based mode allow the random seed generated based on the root gameobject's position, so a gameobject at the same position will get same random seed everytime.",MessageType.Info);
87+
88+
89+
break;
90+
91+
}
92+
93+
94+
// begin area of part set settings
95+
96+
partSetFoldout = EditorGUILayout.Foldout(partSetFoldout,"Part set settings");
97+
98+
99+
if(partSetFoldout){
100+
101+
EditorGUILayout.HelpBox("Here is the area where you can set up procedure generated gameobjects.",MessageType.Info);
102+
103+
// for each partset
104+
105+
106+
foreach(PartSet ps in modularSystem.partSetList.ToArray()){
107+
108+
109+
ps.isActivate = EditorGUILayout.BeginToggleGroup(ps.name,ps.isActivate);
110+
111+
if(ps.isActivate){
112+
113+
// indivudial partset settings
114+
115+
ps.name = EditorGUILayout.TextField("Part Set Name:", ps.name);
116+
117+
ps.attachTransform = (Transform)EditorGUILayout.ObjectField("Attached Transform: ",ps.attachTransform,typeof(Transform),true);
118+
119+
EditorGUILayout.Separator();
120+
121+
// start of part settings
122+
123+
int index = modularSystem.partSetList.IndexOf(ps);
124+
125+
drawingListIndex = index;
126+
127+
partLists[index].DoLayoutList();
128+
129+
130+
131+
// button of new part
132+
133+
if(GUILayout.Button("New Part")){
134+
135+
CreateNewPart(ps);
136+
137+
}
138+
139+
140+
141+
// delete part set button
142+
143+
if(GUILayout.Button("Delete Part Set:[" + ps.name + "]")){
144+
145+
if (EditorUtility.DisplayDialog("Delete Item", "Do you really want to delete [" + ps.name + "]?", "Yes","Cancel"))
146+
{
147+
DeletePartSet(ps);
148+
}
149+
150+
}
151+
}
152+
153+
154+
EditorGUILayout.EndToggleGroup();
155+
156+
EditorGUILayout.Separator();
157+
158+
159+
}
160+
161+
162+
// button of create new part set
163+
164+
EditorGUILayout.Separator();
165+
166+
if(GUILayout.Button("Create New Part Set")){
167+
168+
CreatePartSet();
169+
170+
}
171+
172+
}
173+
174+
175+
176+
EditorGUILayout.EndVertical();
177+
178+
Repaint();
179+
180+
}
181+
182+
183+
public int GetRandomizeSeed(){
184+
185+
return 0;
186+
187+
}
188+
189+
190+
public void CreatePartSet(){
191+
192+
PartSet newPartset = new PartSet();
193+
194+
newPartset.isActivate = true;
195+
newPartset.name = "new Part Set";
196+
197+
modularSystem.partSetList.Add(newPartset);
198+
199+
UpdatePartList();
200+
201+
}
202+
203+
public void DeletePartSet(PartSet ps){
204+
205+
modularSystem.partSetList.Remove(ps);
206+
207+
UpdatePartList();
208+
209+
}
210+
211+
212+
public void CreateNewPart(PartSet ps){
213+
214+
Part newPart = new Part();
215+
216+
newPart.name = "NewPart[" + ps.partList.Count.ToString() + "]";
217+
newPart.position = Vector3.zero;
218+
newPart.rotation = Vector3.zero;
219+
newPart.scale = Vector3.zero;
220+
221+
newPart.weight = 0;
222+
223+
ps.partList.Add(newPart);
224+
225+
226+
}
227+
228+
229+
public void CreateNewPart(ReorderableList rl){
230+
231+
Part newPart = new Part();
232+
233+
newPart.name = "NewPart[" + rl.list.Count.ToString() + "]";
234+
newPart.position = Vector3.zero;
235+
newPart.rotation = Vector3.zero;
236+
newPart.scale = Vector3.zero;
237+
238+
newPart.weight = 0;
239+
240+
rl.list.Add(newPart);
241+
242+
243+
}
244+
245+
246+
public void DeletePart(Part p, PartSet ps){
247+
248+
ps.partList.Remove(p);
249+
250+
}
251+
252+
public void SelectPartElement(ReorderableList list){
253+
254+
255+
256+
}
257+
258+
public void DrawHeader(Rect rect){
259+
260+
}
261+
262+
263+
public void DrawPartElement(Rect rect, int index, bool isActive, bool isFocused){
264+
265+
Part p = modularSystem.partSetList[drawingListIndex].partList[index];
266+
267+
p.name = EditorGUI.TextField(new Rect(rect.x + 10, rect.y + 5, rect.width - 18, 15), "Name: ",p.name);
268+
p.position = EditorGUI.Vector3Field(new Rect(rect.x + 10, rect.y + 30, rect.width - 18, 20), "Position:", p.position);
269+
p.rotation = EditorGUI.Vector3Field(new Rect(rect.x + 10, rect.y + 50, rect.width - 18, 20), "Rotation:", p.rotation);
270+
p.scale = EditorGUI.Vector3Field(new Rect(rect.x + 10, rect.y + 70, rect.width - 18, 20), "Scale:", p.scale);
271+
p.weight = EditorGUI.IntField(new Rect(rect.x + 10, rect.y + 90, rect.width - 18, 15),"Random Weight:",p.weight);
272+
273+
p.prefab = (GameObject)EditorGUI.ObjectField(new Rect(rect.x + 10, rect.y + 110, rect.width - 18, 15),"Part Prefab:",p.prefab,typeof(GameObject),true);
274+
275+
}
276+
277+
278+
public void UpdatePartList(){
279+
280+
partLists.Clear();
281+
282+
foreach(PartSet ps in modularSystem.partSetList.ToArray()){
283+
284+
285+
partLists.Add(new ReorderableList(ps.partList,typeof(Part), true, true, true, true));
286+
287+
int index = modularSystem.partSetList.IndexOf(ps);
288+
289+
290+
partLists[index].elementHeight = 130f;
291+
292+
// list drawing events
293+
partLists[index].drawElementCallback = DrawPartElement;
294+
partLists[index].onAddCallback = CreateNewPart;
295+
partLists[index].drawHeaderCallback = DrawHeader;
296+
297+
}
298+
299+
}
300+
301+
302+
17303
}
18304
}

ModularSystem/ModularClass.cs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
11
// Defines modular classes here
22
// Author: Heavyskymobile - Rozx
3-
// Date: 2016-10-13
4-
// Version 0.1
3+
// Date: 2016-11-05
4+
// Version 0.1a
55

66
using UnityEngine;
77
using System.Collections;
8+
using System.Collections.Generic;
89

910
namespace ModularSystem{
1011

11-
public class ModularClass : MonoBehaviour {
1212

13-
// Use this for initialization
14-
void Start () {
13+
14+
[System.Serializable]
15+
public class PartSet{
16+
17+
public bool isActivate;
18+
19+
public string name;
20+
21+
public Transform attachTransform;
22+
23+
public List<Part> partList = new List<Part>();
24+
}
25+
26+
27+
28+
[System.Serializable]
29+
public class Part{
30+
31+
public string name;
32+
33+
public Vector3 position;
34+
public Vector3 rotation;
35+
public Vector3 scale;
1536

16-
}
37+
public GameObject prefab;
1738

18-
// Update is called once per frame
19-
void Update () {
39+
// Spawn weight
40+
public int weight;
2041

21-
}
2242
}
43+
44+
45+
public enum StartingMethod{
46+
47+
Awake, OnCall
48+
}
49+
50+
51+
public enum RandomSeedMode{
52+
53+
Default, Manual, PositionBased
54+
}
55+
56+
2357
}

0 commit comments

Comments
 (0)