Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dyingIsMainstream
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gamejam-gpn15
dyingIsMainstream
Commits
9b187eac
Commit
9b187eac
authored
Jun 05, 2015
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace tabs with spaces in level management
parent
46dad222
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
113 additions
and
113 deletions
+113
-113
DeserializedLevels.cs
Assets/Scripts/LevelManagement/DeserializedLevels.cs
+24
-24
DeserializedLevelsCrossChecker.cs
...Scripts/LevelManagement/DeserializedLevelsCrossChecker.cs
+24
-24
DeserializedLevelsLoader.cs
Assets/Scripts/LevelManagement/DeserializedLevelsLoader.cs
+2
-2
DeserializedLevelsSaver.cs
Assets/Scripts/LevelManagement/DeserializedLevelsSaver.cs
+45
-45
XmlIO.cs
Assets/Scripts/LevelManagement/XmlIO.cs
+18
-18
No files found.
Assets/Scripts/LevelManagement/DeserializedLevels.cs
View file @
9b187eac
...
...
@@ -6,16 +6,16 @@ using System.IO;
[XmlRoot("Levels")]
public
class
DeserializedLevels
{
[
XmlElement
(
"Developer"
)]
public
Developer
developer
;
public
class
Developer
{
[
XmlAttribute
(
"StartLevel"
)]
public
string
startLevel
;
}
[
XmlElement
(
"Level"
)]
public
Level
[]
levels
;
[
XmlElement
(
"Developer"
)]
public
Developer
developer
;
public
class
Developer
{
[
XmlAttribute
(
"StartLevel"
)]
public
string
startLevel
;
}
[
XmlElement
(
"Level"
)]
public
Level
[]
levels
;
public
class
Level
{
[
XmlElement
(
"Item"
)]
...
...
@@ -31,25 +31,25 @@ public class DeserializedLevels
public
string
y
;
}
public
class
Item
{
[
XmlAttribute
(
"prefab"
)]
public
string
prefab
;
[
XmlAttribute
(
"x"
)]
public
string
x
;
[
XmlAttribute
(
"y"
)]
public
string
y
;
[
XmlAttribute
(
"rot"
)]
public
string
rot
;
public
class
Item
{
[
XmlAttribute
(
"prefab"
)]
public
string
prefab
;
[
XmlAttribute
(
"x"
)]
public
string
x
;
[
XmlAttribute
(
"y"
)]
public
string
y
;
[
XmlAttribute
(
"rot"
)]
public
string
rot
;
[
XmlAttribute
(
"scalex"
)]
public
string
scalex
;
[
XmlAttribute
(
"scaley"
)]
public
string
scaley
;
}
}
}
Assets/Scripts/LevelManagement/DeserializedLevelsCrossChecker.cs
View file @
9b187eac
...
...
@@ -9,15 +9,15 @@ using System.Linq;
public
class
DeserializedLevelsCrossChecker
{
//Hallo Tim und Philipp. Die Datei kuckt nur ob irgendwas mit den Prefabs komisch ist.
// cross check /Resources/Prefabs and Levels.xml if there are any item prefabs that exist only in one but not the other
public
void
crossCheck
()
{
// create a list of /Resources/Prefabs for resources and Levels.Xml
List
<
string
>
resPrefabList
=
new
List
<
string
>();
List
<
string
>
xmlPrefabList
=
new
List
<
string
>();
// Get prefabs from Levels.xml
DeserializedLevels
deserializedLevels
=
XmlIO
.
LoadXml
<
DeserializedLevels
>(
"Levels"
);
// cross check /Resources/Prefabs and Levels.xml if there are any item prefabs that exist only in one but not the other
public
void
crossCheck
()
{
// create a list of /Resources/Prefabs for resources and Levels.Xml
List
<
string
>
resPrefabList
=
new
List
<
string
>();
List
<
string
>
xmlPrefabList
=
new
List
<
string
>();
// Get prefabs from Levels.xml
DeserializedLevels
deserializedLevels
=
XmlIO
.
LoadXml
<
DeserializedLevels
>(
"Levels"
);
foreach
(
DeserializedLevels
.
Level
level
in
deserializedLevels
.
levels
)
{
foreach
(
DeserializedLevels
.
Item
item
in
level
.
items
)
...
...
@@ -26,23 +26,23 @@ public class DeserializedLevelsCrossChecker {
}
// Get prefabs from the /Resources/Prefabs folder
// get all child items in the /Resources/Prefabs folder
DirectoryInfo
dir
=
new
DirectoryInfo
(
"Assets/Resources/Prefabs"
);
FileInfo
[]
fileInfos
=
dir
.
GetFiles
(
"*.prefab"
);
fileInfos
.
Select
(
f
=>
f
.
FullName
).
ToArray
();
// Get prefabs from the /Resources/Prefabs folder
// get all child items in the /Resources/Prefabs folder
DirectoryInfo
dir
=
new
DirectoryInfo
(
"Assets/Resources/Prefabs"
);
FileInfo
[]
fileInfos
=
dir
.
GetFiles
(
"*.prefab"
);
fileInfos
.
Select
(
f
=>
f
.
FullName
).
ToArray
();
// Add each prefab's file name to prefabList and truncate the .prefab extension from the end
foreach
(
FileInfo
fileInfo
in
fileInfos
)
resPrefabList
.
Add
(
fileInfo
.
Name
.
Substring
(
0
,
fileInfo
.
Name
.
Length
-
".prefab"
.
Length
));
// Add each prefab's file name to prefabList and truncate the .prefab extension from the end
foreach
(
FileInfo
fileInfo
in
fileInfos
)
resPrefabList
.
Add
(
fileInfo
.
Name
.
Substring
(
0
,
fileInfo
.
Name
.
Length
-
".prefab"
.
Length
));
// Cross checks
foreach
(
string
prefab
in
xmlPrefabList
.
Except
(
resPrefabList
).
ToList
())
Debug
.
LogError
(
prefab
+
" is missing in the /Resorces/Prefabs folder but used in Levels.xml"
);
// Cross checks
foreach
(
string
prefab
in
xmlPrefabList
.
Except
(
resPrefabList
).
ToList
())
Debug
.
LogError
(
prefab
+
" is missing in the /Resorces/Prefabs folder but used in Levels.xml"
);
foreach
(
string
prefab
in
resPrefabList
.
Except
(
xmlPrefabList
).
ToList
())
Debug
.
Log
(
prefab
+
" exists in the /Resorces/Prefabs folder but not used in Levels.xml"
);
foreach
(
string
prefab
in
resPrefabList
.
Except
(
xmlPrefabList
).
ToList
())
Debug
.
Log
(
prefab
+
" exists in the /Resorces/Prefabs folder but not used in Levels.xml"
);
Debug
.
Log
(
"Cross Check Done"
);
}
Debug
.
Log
(
"Cross Check Done"
);
}
}
Assets/Scripts/LevelManagement/DeserializedLevelsLoader.cs
View file @
9b187eac
...
...
@@ -114,8 +114,8 @@ public class DeserializedLevelsLoader
// DONE, these are only helper functions below
// if no value then return zero or one, otherwise convert to float
float
toFloatZeroIfNull
(
string
value
)
{
return
value
==
null
?
0
:
float
.
Parse
(
value
);
}
float
toFloatOneIfNull
(
string
value
)
{
return
value
==
null
?
1
:
float
.
Parse
(
value
);
}
float
toFloatZeroIfNull
(
string
value
)
{
return
value
==
null
?
0
:
float
.
Parse
(
value
);
}
float
toFloatOneIfNull
(
string
value
)
{
return
value
==
null
?
1
:
float
.
Parse
(
value
);
}
void
setPos2D
(
GameObject
g
,
Vector2
pos
)
{
...
...
Assets/Scripts/LevelManagement/DeserializedLevelsSaver.cs
View file @
9b187eac
...
...
@@ -4,40 +4,40 @@ using System.Xml;
public
class
DeserializedLevelsSaver
{
public
const
string
xmlItemsToExportGOName
=
"XmlItemsToExport"
;
public
const
string
xmlItemsToExportGOName
=
"XmlItemsToExport"
;
public
void
saveExportItems
()
{
// Create XmlItemsToExport if does not exist yet
if
(
GameObject
.
Find
(
xmlItemsToExportGOName
)
==
null
)
new
GameObject
(
xmlItemsToExportGOName
);
GameObject
xmlItemsToExportGO
=
GameObject
.
Find
(
xmlItemsToExportGOName
);
var
xmlItemsToExportGOchildren
=
xmlItemsToExportGO
.
GetComponentsInChildren
<
Transform
>();
// Check if any children exist
if
(
xmlItemsToExportGOchildren
.
Length
==
0
)
Debug
.
LogError
(
"Add the prefabs to "
+
xmlItemsToExportGOName
);
DeserializedLevels
.
Level
levelXml
=
new
DeserializedLevels
.
Level
();
public
void
saveExportItems
()
{
// Create XmlItemsToExport if does not exist yet
if
(
GameObject
.
Find
(
xmlItemsToExportGOName
)
==
null
)
new
GameObject
(
xmlItemsToExportGOName
);
GameObject
xmlItemsToExportGO
=
GameObject
.
Find
(
xmlItemsToExportGOName
);
var
xmlItemsToExportGOchildren
=
xmlItemsToExportGO
.
GetComponentsInChildren
<
Transform
>();
// Check if any children exist
if
(
xmlItemsToExportGOchildren
.
Length
==
0
)
Debug
.
LogError
(
"Add the prefabs to "
+
xmlItemsToExportGOName
);
DeserializedLevels
.
Level
levelXml
=
new
DeserializedLevels
.
Level
();
int
n
=
0
;
// count number of children skipping sub-items
foreach
(
Transform
item
in
xmlItemsToExportGOchildren
)
if
(
item
.
parent
==
xmlItemsToExportGO
.
transform
)
n
++;
int
n
=
0
;
// count number of children skipping sub-items
foreach
(
Transform
item
in
xmlItemsToExportGOchildren
)
if
(
item
.
parent
==
xmlItemsToExportGO
.
transform
)
n
++;
// the items array should have that many elements
levelXml
.
items
=
new
DeserializedLevels
.
Item
[
n
];
// the items array should have that many elements
levelXml
.
items
=
new
DeserializedLevels
.
Item
[
n
];
// use i for counting items, i would be equal (one more to be precise) to n at the end of the cycle
int
i
=
0
;
// use i for counting items, i would be equal (one more to be precise) to n at the end of the cycle
int
i
=
0
;
// cycle through the children again and add them to items
foreach
(
Transform
item
in
xmlItemsToExportGOchildren
)
{
// skip sub-items
if
(
item
.
parent
!=
xmlItemsToExportGO
.
transform
)
continue
;
// cycle through the children again and add them to items
foreach
(
Transform
item
in
xmlItemsToExportGOchildren
)
{
// skip sub-items
if
(
item
.
parent
!=
xmlItemsToExportGO
.
transform
)
continue
;
levelXml
.
items
[
i
]
=
new
DeserializedLevels
.
Item
();
...
...
@@ -48,24 +48,24 @@ public class DeserializedLevelsSaver
levelXml
.
items
[
i
].
scalex
=
toStringNullIfOne
(
item
.
localScale
.
x
);
levelXml
.
items
[
i
].
scaley
=
toStringNullIfOne
(
item
.
localScale
.
y
);
// increase i for the next cycle
i
++;
}
// increase i for the next cycle
i
++;
}
// Export just one level
DeserializedLevels
levelsXmlToExport
=
new
DeserializedLevels
();
levelsXmlToExport
.
levels
=
new
DeserializedLevels
.
Level
[
1
];
levelsXmlToExport
.
levels
[
0
]
=
levelXml
;
XmlIO
.
SaveXml
<
DeserializedLevels
>(
levelsXmlToExport
,
"./Assets/Resources/"
+
xmlItemsToExportGOName
+
".xml"
);
}
// Export just one level
DeserializedLevels
levelsXmlToExport
=
new
DeserializedLevels
();
levelsXmlToExport
.
levels
=
new
DeserializedLevels
.
Level
[
1
];
levelsXmlToExport
.
levels
[
0
]
=
levelXml
;
XmlIO
.
SaveXml
<
DeserializedLevels
>(
levelsXmlToExport
,
"./Assets/Resources/"
+
xmlItemsToExportGOName
+
".xml"
);
}
string
toStringNullIfZero
(
float
num
)
{
return
num
==
0
?
null
:
mathRound
(
num
,
2
).
ToString
();
}
string
toStringNullIfOne
(
float
num
)
{
return
num
==
1
?
null
:
mathRound
(
num
,
2
).
ToString
();
}
string
toStringNullIfZero
(
float
num
)
{
return
num
==
0
?
null
:
mathRound
(
num
,
2
).
ToString
();
}
string
toStringNullIfOne
(
float
num
)
{
return
num
==
1
?
null
:
mathRound
(
num
,
2
).
ToString
();
}
float
mathRound
(
float
round
,
int
decimals
)
{
return
Mathf
.
Round
(
round
*
Mathf
.
Pow
(
10
,
decimals
))
/
Mathf
.
Pow
(
10
,
decimals
);
}
float
mathRound
(
float
round
,
int
decimals
)
{
return
Mathf
.
Round
(
round
*
Mathf
.
Pow
(
10
,
decimals
))
/
Mathf
.
Pow
(
10
,
decimals
);
}
}
Assets/Scripts/LevelManagement/XmlIO.cs
View file @
9b187eac
...
...
@@ -5,25 +5,25 @@ using UnityEngine; // necessary for TextAsset
public
static
class
XmlIO
{
public
static
void
SaveXml
<
T
>
(
this
object
deserializedXml
,
string
path
)
where
T
:
class
{
using
(
var
stream
=
new
FileStream
(
path
,
FileMode
.
Create
))
{
var
s
=
new
XmlSerializer
(
typeof
(
T
));
s
.
Serialize
(
stream
,
deserializedXml
);
}
}
public
static
void
SaveXml
<
T
>
(
this
object
deserializedXml
,
string
path
)
where
T
:
class
{
using
(
var
stream
=
new
FileStream
(
path
,
FileMode
.
Create
))
{
var
s
=
new
XmlSerializer
(
typeof
(
T
));
s
.
Serialize
(
stream
,
deserializedXml
);
}
}
public
static
T
LoadXml
<
T
>(
string
textAssetName
)
where
T
:
class
{
TextAsset
xmlTextAsset
=
(
TextAsset
)
Resources
.
Load
(
textAssetName
,
typeof
(
TextAsset
));
public
static
T
LoadXml
<
T
>(
string
textAssetName
)
where
T
:
class
{
TextAsset
xmlTextAsset
=
(
TextAsset
)
Resources
.
Load
(
textAssetName
,
typeof
(
TextAsset
));
using
(
var
stream
=
new
StringReader
(
xmlTextAsset
.
text
))
{
var
s
=
new
XmlSerializer
(
typeof
(
T
));
T
deserializedXml
=
s
.
Deserialize
(
stream
)
as
T
;
return
deserializedXml
;
}
}
using
(
var
stream
=
new
StringReader
(
xmlTextAsset
.
text
))
{
var
s
=
new
XmlSerializer
(
typeof
(
T
));
T
deserializedXml
=
s
.
Deserialize
(
stream
)
as
T
;
return
deserializedXml
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment