This file contains hidden or 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
struct ParallaxModifier: ViewModifier { | |
@ObservedObject var manager: MotionManager = MotionManager.shared | |
var magnitude: Double | |
func body(content: Content) -> some View { | |
content | |
.offset(x: CGFloat(manager.roll * magnitude), y: CGFloat(manager.pitch * magnitude)) | |
} | |
} |
This file contains hidden or 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
class MotionManager: ObservableObject { | |
@Published var pitch: Double = 0.0 | |
@Published var roll: Double = 0.0 | |
private var manager: CMMotionManager | |
static var shared = MotionManager() | |
init() { |
This file contains hidden or 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
public string GetGroundTypeFromPosition(Vector3 position) | |
{ | |
if(sortedLayers == null) | |
{ | |
sortedLayers = layers | |
.ToArray() | |
.OrderByDescending(x => x.GetComponent<TilemapRenderer>().sortingOrder); | |
} | |
foreach(var tileMap in sortedLayers) |
This file contains hidden or 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
Dependencies { | |
Service { _ in Bar.init() } | |
Service { Foo(bar: $0.get()) } | |
Service(.global) { _ in ViewModel.init() } | |
}.build() |
This file contains hidden or 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
import UIKit | |
protocol WorkProtocol: class { | |
func work() | |
} | |
class ViewModel { | |
weak var delegate: WorkProtocol? | |
} |
This file contains hidden or 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
@propertyWrapper | |
struct Injected<Service> { | |
typealias DelayedInjection = () -> Service | |
var service: Service? | |
var delayed: DelayedInjection? | |
init() { | |
delayed = { Dependencies.main.resolve() } |
This file contains hidden or 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
public extension Dependencies { | |
/// Create a overridable main resolver | |
fileprivate static var main = Dependencies() | |
func get<Service>() -> Service { | |
return resolve() | |
} | |
/// Function builder that accepts a single or multiple services |
This file contains hidden or 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
/// Private extension | |
private extension Dependencies { | |
/// Resolve a serice based on its ObjectIdentifier | |
func resolve<Service>() -> Service { | |
var service = self.factories[ObjectIdentifier(Service.self)]! | |
guard let instance = service.instance, service.cycle == .global else { |
This file contains hidden or 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
public struct Service { | |
public enum LifeCycle { | |
case global | |
case oneOf | |
} | |
/// Holds the lifecycle of the current service | |
public var cycle: LifeCycle |
This file contains hidden or 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
/// Public class | |
public class Dependencies { | |
/// Will hold all our factories | |
public var factories: [ObjectIdentifier: Service] = [:] | |
/// Make sure that our init will stay private so they need to use the provider functionBuilder | |
private init() { } | |
/// Make sure that all the dependencies are removed when we deinit |