Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CityGen
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kent Holt
CityGen
Commits
874459b6
Commit
874459b6
authored
6 years ago
by
zohaib
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of prod3.imt.hig.no:Kent/CityGen into Simulation
parents
77b44fe3
e4e288ef
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/Scripts/Editor/CityGenWindow.cs
+72
-32
72 additions, 32 deletions
Assets/Scripts/Editor/CityGenWindow.cs
with
72 additions
and
32 deletions
Assets/Scripts/Editor/CityGenWindow.cs
+
72
−
32
View file @
874459b6
using
System.Collections
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine
;
using
UnityEditor
;
using
UnityEditor
;
...
@@ -9,38 +10,25 @@ public class CityGenWindow : EditorWindow
...
@@ -9,38 +10,25 @@ public class CityGenWindow : EditorWindow
[
System
.
NonSerialized
]
[
System
.
NonSerialized
]
private
string
saveFolder
;
private
string
saveFolder
;
[
System
.
NonSerialized
]
[
System
.
NonSerialized
]
private
string
filename
=
"editor.json"
;
[
System
.
NonSerialized
]
private
bool
citySelectionMenuEnabled
=
true
;
private
bool
citySelectionMenuEnabled
=
true
;
[
System
.
NonSerialized
]
[
System
.
NonSerialized
]
private
Vector2
citySelectionMenuScrollPosition
;
private
Vector2
citySelectionMenuScrollPosition
;
public
List
<
string
>
entries
=
new
List
<
string
>();
public
List
<
string
>
entries
=
new
List
<
string
>();
private
void
OnEnable
()
CityGen
cityGen
=
new
CityGen
();
{
saveFolder
=
Application
.
persistentDataPath
+
"/CityData"
;
}
public
void
OnGUI
()
public
void
OnGUI
()
{
{
//MakeCitySelec
tionMenu();
//MakeCitySelec
"
}
}
public
void
OnDestroy
()
// ######### GUI Functions #########
{
entries
.
Add
(
"City1"
);
entries
.
Add
(
"City2"
);
entries
.
Add
(
"City3"
);
entries
.
Add
(
"City4"
);
entries
.
Add
(
"City5"
);
save
();
load
();
foreach
(
string
str
in
entries
)
{
Debug
.
Log
(
str
);
}
}
private
void
MakeCitySelectionMenu
()
// Make Main menu for selecting the city to edit.
private
void
MakeMainCityMenu
()
{
{
this
.
citySelectionMenuScrollPosition
=
GUILayout
.
BeginScrollView
(
this
.
citySelectionMenuScrollPosition
,
GUILayout
.
Width
(
100
),
GUILayout
.
Height
(
100
));
this
.
citySelectionMenuScrollPosition
=
GUILayout
.
BeginScrollView
(
this
.
citySelectionMenuScrollPosition
,
GUILayout
.
Width
(
100
),
GUILayout
.
Height
(
100
));
for
(
int
i
=
0
;
i
<
5
;
i
++)
for
(
int
i
=
0
;
i
<
5
;
i
++)
...
@@ -49,26 +37,59 @@ public class CityGenWindow : EditorWindow
...
@@ -49,26 +37,59 @@ public class CityGenWindow : EditorWindow
GUILayout
.
EndScrollView
();
GUILayout
.
EndScrollView
();
}
}
private
bool
HandleMainCityMenuEvent
(
string
cityname_filename
)
{
if
(!
cityGen
.
load
(
cityname_filename
))
{
Debug
.
Log
(
"Couldn't find file for: "
+
cityname_filename
);
return
false
;
}
return
true
;
}
// ######### Window Event Funtions #########
private
void
OnEnable
()
{
saveFolder
=
Application
.
persistentDataPath
+
"/CityData/"
;
// Not first launch, editor file exists
if
(
System
.
IO
.
File
.
Exists
(
this
.
saveFolder
+
this
.
filename
))
load
();
}
public
void
OnDestroy
()
{
save
();
}
// ######### Save + Load #########
// Save the data about city.
// Save the data about city.
void
save
()
{
void
save
()
{
// Wrap the list for jason conversion
CityEntryListWrapper
<
string
>
list
=
new
CityEntryListWrapper
<
string
>(
this
.
entries
);
// Covert city object to json.
// Covert city object to json.
string
stringDataAsJson
=
JsonUtility
.
ToJson
(
this
.
entries
);
string
stringDataAsJson
=
JsonUtility
.
ToJson
(
list
);
//print(Application.persistentDataPath + this.jsonFilePath);
// Creates a directory in local disk.
// Creates a directory in local disk.
System
.
IO
.
Directory
.
CreateDirectory
(
Application
.
persistentDataPath
+
"/CityData"
);
System
.
IO
.
Directory
.
CreateDirectory
(
this
.
saveFolder
);
// Write all the data to a file.
// Write all the data to a file.
System
.
IO
.
File
.
WriteAllText
(
this
.
saveFolder
,
stringDataAsJson
);
System
.
IO
.
File
.
WriteAllText
(
this
.
saveFolder
+
this
.
filename
,
stringDataAsJson
);
}
}
// Load the data about city.
// Load the data about city.
void
load
(){
void
load
()
string
cityDataAsJson
=
System
.
IO
.
File
.
ReadAllText
(
Application
.
persistentDataPath
+
this
.
saveFolder
);
{
entries
=
JsonUtility
.
FromJson
<
List
<
string
>>(
cityDataAsJson
);
// Read from file.
string
cityDataAsJson
=
System
.
IO
.
File
.
ReadAllText
(
this
.
saveFolder
+
this
.
filename
);
// Dump result in wrapper object.
CityEntryListWrapper
<
string
>
obj
=
JsonUtility
.
FromJson
<
CityEntryListWrapper
<
string
>>(
cityDataAsJson
);
// Transfer data.
this
.
entries
=
obj
.
list
;
}
}
// ######### Container Classes #########
// ######### Show CityGen in Window Tab #########
// Menu entry
// Menu entry
[
MenuItem
(
"Window/City Gen"
)]
[
MenuItem
(
"Window/City Gen"
)]
public
static
void
ShowWindow
()
public
static
void
ShowWindow
()
...
@@ -77,3 +98,22 @@ public class CityGenWindow : EditorWindow
...
@@ -77,3 +98,22 @@ public class CityGenWindow : EditorWindow
EditorWindow
.
GetWindow
<
CityGenWindow
>(
"City Gen"
);
EditorWindow
.
GetWindow
<
CityGenWindow
>(
"City Gen"
);
}
}
}
}
// ######### Container Classes #########
// ######### Wrapper Classes #########
[
System
.
Serializable
]
public
class
CityEntryListWrapper
<
T
>
{
public
List
<
T
>
list
=
new
List
<
T
>();
public
CityEntryListWrapper
()
{
//
}
public
CityEntryListWrapper
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment