@@ -26,28 +26,19 @@ import Foundation
26
26
class UnityProject {
27
27
28
28
private let config : Config
29
- private let workingPath : String
30
- private let projectName : String
31
- private let unitySceneNames : [ String ]
32
-
33
29
private let fileManager = FileManager ( )
34
30
private lazy var shell = Shell ( )
35
- private let unityAppPath : String
36
31
37
32
init ( config: Config ) {
38
33
self . config = config
39
- self . projectName = config. iOS. projectName
40
- self . workingPath = config. unity. projectPath
41
- self . unityAppPath = config. unity. applicationPath
42
- self . unitySceneNames = config. unity. sceneNames
43
34
}
44
35
45
36
func create( ) -> Result {
46
- guard UBKit . validatePath ( unityAppPath , isDirectory: false ) else {
47
- return . failure( UBKitError . invalidFolder ( unityAppPath ) )
37
+ guard UBKit . validatePath ( config . unity . applicationPath , isDirectory: false ) else {
38
+ return . failure( UBKitError . invalidFolder ( config . unity . applicationPath ) )
48
39
}
49
40
50
- print ( " Unity Project Path: \( workingPath ) \n " )
41
+ print ( " Unity Project Path: \( config . unity . projectPath ) \n " )
51
42
let unityFolderResult = createUnityFolder ( )
52
43
guard unityFolderResult == . success else {
53
44
return unityFolderResult
@@ -83,7 +74,7 @@ private extension UnityProject {
83
74
func createUnityFolder( ) -> Result {
84
75
do {
85
76
try fileManager. createDirectory (
86
- atPath: workingPath ,
77
+ atPath: config . unity . projectPath ,
87
78
withIntermediateDirectories: false ,
88
79
attributes: nil )
89
80
} catch {
@@ -95,11 +86,11 @@ private extension UnityProject {
95
86
96
87
func generateUnityProject( ) -> Result {
97
88
let semaphore = DispatchSemaphore ( value: 0 )
98
- let unityProjectPath = workingPath . appending ( projectName)
89
+ let unityProjectPath = config . unity . projectPath . appending ( config . unity . projectName)
99
90
var statusCode : Int32 = 0
100
91
101
92
shell. perform (
102
- unityAppPath ,
93
+ config . unity . applicationPath ,
103
94
UnityCommandLine . Arguments. batchmode,
104
95
UnityCommandLine . Arguments. createProject,
105
96
unityProjectPath,
@@ -123,7 +114,7 @@ private extension UnityProject {
123
114
}
124
115
125
116
func createUnityEditorScripts( ) -> Result {
126
- let assetsFilePath = workingPath . appending ( projectName) . appending ( " /Assets/ " )
117
+ let assetsFilePath = config . unity . projectPath . appending ( config . unity . projectName) . appending ( " /Assets/ " )
127
118
guard UBKit . validatePath ( assetsFilePath, isDirectory: true ) else {
128
119
return . failure( UBKitError . invalidFolder ( assetsFilePath) )
129
120
}
@@ -139,21 +130,21 @@ private extension UnityProject {
139
130
140
131
guard fileManager. createFile (
141
132
atPath: editorFilePath. appending ( " iOSBuildScript.cs " ) ,
142
- contents: File . unityBuildScriptFile ( iOSProjectFolderPath: config. iOS. projectPath, iOSProjectName: projectName) ,
133
+ contents: File . unityBuildScriptFile ( iOSProjectFolderPath: config. iOS. projectPath, iOSProjectName: config . iOS . projectName) ,
143
134
attributes: nil ) else {
144
135
return . failure( UBKitError . unableToCreateFile ( " Unity iOS Build Script " ) )
145
136
}
146
137
147
138
guard fileManager. createFile (
148
139
atPath: editorFilePath. appending ( " XcodeProjectRefresher.cs " ) ,
149
- contents: File . unityProjectScriptFile ( projectName : projectName, iOSProjectPath: config. iOS. projectPath) ,
140
+ contents: File . unityProjectScriptFile ( iOSProjectName : config . iOS . projectName, iOSProjectPath: config. iOS. projectPath) ,
150
141
attributes: nil ) else {
151
142
return . failure( UBKitError . unableToCreateFile ( " Unity Project Script " ) )
152
143
}
153
144
154
145
guard fileManager. createFile (
155
146
atPath: editorFilePath. appending ( " XcodeFrameworks.cs " ) ,
156
- contents: File . unityFrameworksScriptFile ( projectName : projectName, iOSProjectPath: config. iOS. projectPath) ,
147
+ contents: File . unityFrameworksScriptFile ( iOSProjectName : config . iOS . projectName, iOSProjectPath: config. iOS. projectPath) ,
157
148
attributes: nil ) else {
158
149
return . failure( UBKitError . unableToCreateFile ( " Xcode Frameworks Script " ) )
159
150
}
@@ -164,21 +155,21 @@ private extension UnityProject {
164
155
func runInitialProjectBuild( ) -> Result {
165
156
let semaphore = DispatchSemaphore ( value: 0 )
166
157
var statusCode : Int32 = 999
167
- let projectPath = workingPath . appending ( projectName)
158
+ let projectPath = config . unity . projectPath . appending ( config . unity . projectName)
168
159
let outputLocation = projectPath. appending ( " / " ) . appending ( " ios_build " )
169
160
170
161
// MARK: - Main
171
- print ( " Initializing Unity scene \( unitySceneNames [ 0 ] ) for iOS... " )
162
+ print ( " Initializing Unity scene \( config . unity . sceneNames [ 0 ] ) for iOS... " )
172
163
print ( " This will take some time to complete \n " )
173
164
shell. perform (
174
- unityAppPath ,
165
+ config . unity . applicationPath ,
175
166
UnityCommandLine . Arguments. batchmode,
176
167
UnityCommandLine . Arguments. projectPath,
177
168
projectPath,
178
169
UnityCommandLine . Arguments. outputLocation,
179
170
outputLocation,
180
171
UnityCommandLine . Arguments. sceneName,
181
- unitySceneNames [ 0 ] ,
172
+ config . unity . sceneNames [ 0 ] ,
182
173
UnityCommandLine . Arguments. executeMethod,
183
174
UnityCommandLine . buildAction,
184
175
UnityCommandLine . Arguments. quit,
0 commit comments