-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ignacio-chiazzo/multiple-objects
Move logic of virtual object to a Manager
- Loading branch information
Showing
4 changed files
with
98 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// virtualObjectsManager.swift | ||
// ARKitProject | ||
// | ||
// Created by Ignacio Chiazzo on 2017-12-10. | ||
// Copyright © 2017 Apple. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import os.log | ||
|
||
class VirtualObjectsManager { | ||
|
||
static let shared = VirtualObjectsManager() | ||
|
||
// AutoIncrement Unique Id | ||
private var nextID = 1 | ||
func generateUid() -> Int { | ||
nextID += 1 | ||
return nextID | ||
} | ||
|
||
private var virtualObjects: [VirtualObject] = [VirtualObject]() | ||
private var virtualObjectSelected: VirtualObject? | ||
|
||
func addVirtualObject(virtualObject: VirtualObject) { | ||
virtualObjects.append(virtualObject) | ||
} | ||
|
||
func resetVirtualObjects() { | ||
for object in virtualObjects { | ||
object.unloadModel() | ||
object.removeFromParentNode() | ||
} | ||
virtualObjectSelected = nil | ||
virtualObjects = [] | ||
} | ||
|
||
func removeVirtualObject(virtualObject: VirtualObject) { | ||
if let index = virtualObjects.index(where: { $0.id == virtualObject.id }) { | ||
virtualObjects.remove(at: index) | ||
} else { | ||
os_log("Element not found", type: .error) | ||
} | ||
} | ||
|
||
func removeVirtualObjectSelected() { | ||
guard let object = virtualObjectSelected else { | ||
return | ||
} | ||
|
||
removeVirtualObject(virtualObject: object) | ||
object.unloadModel() | ||
object.removeFromParentNode() | ||
virtualObjectSelected = nil | ||
} | ||
|
||
func getVirtualObjects() -> [VirtualObject] { | ||
return self.virtualObjects | ||
} | ||
|
||
func isAVirtualObjectPlaced() -> Bool { | ||
return virtualObjectSelected != nil | ||
} | ||
|
||
func setVirtualObjectSelected(virtualObject: VirtualObject) { | ||
self.virtualObjectSelected = virtualObject | ||
} | ||
|
||
func getVirtualObjectSelected() -> VirtualObject? { | ||
return self.virtualObjectSelected | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters