@@ -122,14 +122,28 @@ private extension FileCopier {
122122 guard fileManager. fileExists ( atPath: mainFilePath) else {
123123 return . failure( UBKitError . missingUnityFile ( " main.mm " ) )
124124 }
125+ let changeInitResult = changeUnityInitMethod ( pathString: mainFilePath)
126+ guard changeInitResult == . success else {
127+ return changeInitResult
128+ }
125129
126130 let appControllerFilePath = workingPath. appending ( config. unity. projectName) . appending ( " /ios_build/Classes/UnityAppController.h " )
127131 guard fileManager. fileExists ( atPath: appControllerFilePath) else {
128132 return . failure( UBKitError . missingUnityFile ( " UnityAppController.h " ) )
129133 }
134+ let changeAppControllerResult = changeUnityAppControllerMethod ( pathString: appControllerFilePath)
135+ guard changeAppControllerResult == . success else {
136+ return changeAppControllerResult
137+ }
130138
131- changeUnityInitMethod ( pathString: mainFilePath)
132- changeUnityAppControllerMethod ( pathString: appControllerFilePath)
139+ let metalHelperFilePath = workingPath. appending ( config. unity. projectName) . appending ( " /ios_build/Classes/Unity/MetalHelper.mm " )
140+ guard fileManager. fileExists ( atPath: metalHelperFilePath) else {
141+ return . failure( UBKitError . missingUnityFile ( " MetalHelper.mm " ) )
142+ }
143+ let changeMetalResult = changeUnityMetalHelper ( pathString: metalHelperFilePath)
144+ guard changeMetalResult == . success else {
145+ return changeMetalResult
146+ }
133147 return . success
134148 }
135149
@@ -177,7 +191,7 @@ private extension FileCopier {
177191 }
178192 }
179193
180- func changeUnityInitMethod( pathString: String ) {
194+ func changeUnityInitMethod( pathString: String ) -> Result {
181195 do {
182196 let fileString = try String ( contentsOfFile: pathString)
183197 let unityString = " int main(int argc, char* argv[]) "
@@ -186,11 +200,13 @@ private extension FileCopier {
186200
187201 try newFileString. data ( using: . utf8) ? . write ( to: URL ( fileURLWithPath: pathString) )
188202 } catch {
189- print ( " FAILED TO READ FILE " )
203+ return . failure ( UBKitError . missingUnityFile ( " main.mm " ) )
190204 }
205+
206+ return . success
191207 }
192208
193- func changeUnityAppControllerMethod( pathString: String ) {
209+ func changeUnityAppControllerMethod( pathString: String ) -> Result {
194210 do {
195211 let fileString = try String ( contentsOfFile: pathString)
196212 let unityString = """
@@ -210,8 +226,24 @@ private extension FileCopier {
210226 let newFileString = fileString. replacingOccurrences ( of: unityString, with: replacementString)
211227 try newFileString. data ( using: . utf8) ? . write ( to: URL ( fileURLWithPath: pathString) )
212228 } catch {
213- print ( " FAILED TO READ FILE " )
229+ return . failure( UBKitError . missingUnityFile ( " UnityAppController.h " ) )
230+ }
231+
232+ return . success
233+ }
234+
235+ func changeUnityMetalHelper( pathString: String ) -> Result {
236+ do {
237+ let fileString = try String ( contentsOfFile: pathString)
238+ let unityString = " surface->stencilRB = [surface->device newTextureWithDescriptor: stencilTexDesc]; "
239+ let replacementString = " stencilTexDesc.usage |= MTLTextureUsageRenderTarget; \n surface->stencilRB = [surface->device newTextureWithDescriptor: stencilTexDesc]; "
240+ let newFileString = fileString. replacingOccurrences ( of: unityString, with: replacementString)
241+ try newFileString. data ( using: . utf8) ? . write ( to: URL ( fileURLWithPath: pathString) )
242+ } catch {
243+ return . failure( UBKitError . missingUnityFile ( " MetalHelper.mm " ) )
214244 }
245+
246+ return . success
215247 }
216248}
217249
@@ -225,8 +257,8 @@ private extension FileCopier {
225257 var uuid : String = " "
226258 var counter : UInt = 0
227259 let className : String = String ( describing: T . self) . replacingOccurrences ( of: " PBX " , with: " " )
228- let classAcronym = String ( className. characters . filter { String ( $0) . lowercased ( ) != String ( $0) } )
229- let stringID = String ( abs ( id. hashValue) . description. characters . prefix ( 10 - classAcronym. characters . count) )
260+ let classAcronym = className. filter ( { String ( $0) . lowercased ( ) != String ( $0) } )
261+ let stringID = String ( abs ( id. hashValue) . description. prefix ( 10 - classAcronym. utf8 . count) )
230262 repeat {
231263 counter += 1
232264 uuid = " \( classAcronym) \( stringID) \( String ( format: " %02d " , counter) ) "
0 commit comments