Skip to content

Commit

Permalink
Open source
Browse files Browse the repository at this point in the history
  • Loading branch information
tattn committed Oct 21, 2023
1 parent e76cc6e commit 0e4d8fd
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 143 deletions.
1 change: 0 additions & 1 deletion app/xcode/Sources/VCamEntity/Notification+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation

public extension Notification.Name {
static let reloadUI = Notification.Name("vcam.reloadUI")
static let showEmojiPicker = Notification.Name("vcam.showEmojiPicker")
static let deviceWasChanged = Notification.Name("vcam.deviceWasChanged")
static let unfocusObject = Notification.Name("vcam.unfocusObject")
Expand Down
23 changes: 0 additions & 23 deletions app/xcode/Sources/VCamUI/Extensions/UniBridge+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,6 @@ import VCamEntity
import SwiftUI
import VCamBridge

extension UniState {
public init(_ state: CustomState) {
get = state.get
set = state.set
name = state.name
reloadThrottle = state.reloadThrottle
}

public struct CustomState {
public init(get: @escaping () -> Value, set: @escaping (Value) -> Void, name: String = "", reloadThrottle: Bool = false) {
self.get = get
self.set = set
self.name = name
self.reloadThrottle = reloadThrottle
}

public var get: () -> Value
public var set: (Value) -> Void
public var name = ""
public var reloadThrottle = false
}
}

extension UniBridge {
public var canvasCGSize: CGSize {
let size = canvasSize
Expand Down
33 changes: 0 additions & 33 deletions app/xcode/Sources/VCamUI/Extensions/UniSet.swift

This file was deleted.

2 changes: 2 additions & 0 deletions app/xcode/Sources/VCamUI/MacWindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class MacWindowManager {

private var openWindows: [String: NSWindow] = [:]

public var openCredits: () -> Void = {}

public func open<T: MacWindow>(_ windowView: T) {
let id = self.id(T.self)
if let window = openWindows[id] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import AppKit
import VCamEntity
import VCamLocalization
import VCamBridge
import struct SwiftUI.Image

public struct VCamMessageAction: VCamAction {
Expand All @@ -19,10 +20,8 @@ public struct VCamMessageAction: VCamAction {
public var name: String { L10n.message.text }
public var icon: Image { Image(systemName: "text.bubble") }

@UniState(.message, name: "message") private var message

@MainActor
public func callAsFunction(context: VCamActionContext) async throws {
message = configuration.message
UniBridge.shared.message.wrappedValue = configuration.message
}
}
82 changes: 0 additions & 82 deletions app/xcode/Sources/VCamUI/UniState.swift

This file was deleted.

112 changes: 112 additions & 0 deletions app/xcode/Sources/VCamUI/UnityCallback.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// UnityCallback.swift
//
//
// Created by Tatsuya Tanaka on 2023/01/21.
//

import Foundation
import VCamData
import VCamBridge
import VCamCamera
import VCamTracking
import VCamLogger

@_cdecl("uniOnVCamSystemStart")
public func uniOnVCamSystemStart() {
Logger.log("uniOnVCamSystemStart")
WindowManager.shared.system.isUniVCamSystemEnabled = true
WindowManager.shared.system.startSystem()
UniReload.Reloader.shared.objectWillChange.send()
}

@_cdecl("uniOnVCamSystemDestroy")
public func uniOnVCamSystemDestroy() {
Logger.log("uniOnVCamSystemDestroy")
WindowManager.shared.system.isUniVCamSystemEnabled = false
UniReload.Reloader.shared.objectWillChange.send()
}

@_cdecl("uniOnApplyCaptureSystem")
public func uniOnApplyCaptureSystem() {
UniBridge.shared.useFullTracking(UserDefaults.standard.value(for: .integrationMocopi))
Tracking.shared.updateLipSyncIfNeeded()

UniBridge.cachedBlendShapes = UniBridge.shared.blendShapes.components(separatedBy: ",")
}

@_cdecl("uniUseAutoConvertVRM1")
public func uniUseAutoConvertVRM1() -> Bool {
UserDefaults.standard.value(for: .useAutoConvertVRM1)
}

@_cdecl("uniDisposeWindow")
public func uniDisposeWindow() {
Logger.log("")
WindowManager.shared.dispose()
}

@_cdecl("uniHideWindow")
public func uniHideWindow() {
Logger.log("")
WindowManager.shared.hide()
}

@_cdecl("uniReloadUI")
public func uniReloadUI() {
guard WindowManager.shared.isConfigured,
WindowManager.shared.system.isUniVCamSystemEnabled else { return }
UniReload.Reloader.shared.objectWillChange.send()
}

@_cdecl("uniUpdateRenderFrame")
public func uniUpdateRenderFrame() {
guard WindowManager.shared.isConfigured else { return }
VirtualCameraManager.shared.sendImageToVirtualCamera(
with: MainTexture.shared.texture,
useHMirror: UserDefaults.cached.useHMirror
)

VideoRecorder.shared.renderFrame(MainTexture.shared.texture)
}

@_cdecl("uniRegisterString")
public func uniRegisterString(_ get: @escaping @convention(c) (Int32) -> UnsafePointer<CChar>, _ set: @escaping @convention(c) (Int32, UnsafePointer<CChar>) -> Void) {
UniBridge.shared.stringMapper.getValue = { String(cString: get($0.rawValue)) }
UniBridge.shared.stringMapper.setValue = { set($0.rawValue, strdup($1)) }
}

@_cdecl("uniRegisterInt")
public func uniRegisterInt(_ get: @escaping @convention(c) (Int32) -> Int32, _ set: @escaping @convention(c) (Int32, Int32) -> Void) {
UniBridge.shared.intMapper.getValue = { get($0.rawValue) }
UniBridge.shared.intMapper.setValue = { set($0.rawValue, $1) }
}

@_cdecl("uniRegisterFloat")
public func uniRegisterFloat(_ get: @escaping @convention(c) (Int32) -> Float, _ set: @escaping @convention(c) (Int32, Float) -> Void) {
UniBridge.shared.floatMapper.getValue = { CGFloat(get($0.rawValue)) }
UniBridge.shared.floatMapper.setValue = { set($0.rawValue, Float($1)) }
}

@_cdecl("uniRegisterBool")
public func uniRegisterBool(_ get: @escaping @convention(c) (Int32) -> Bool, _ set: @escaping @convention(c) (Int32, Bool) -> Void) {
UniBridge.shared.boolMapper.getValue = { get($0.rawValue) }
UniBridge.shared.boolMapper.setValue = { set($0.rawValue, $1) }
}

@_cdecl("uniRegisterTrigger")
public func uniRegisterTrigger(_ trigger: @escaping @convention(c) (Int32) -> Void) {
UniBridge.shared.triggerMapper.getValue = { trigger($0.rawValue) }
}

@_cdecl("uniRegisterStruct")
public func uniRegisterStruct(_ get: @escaping @convention(c) (Int32) -> UnsafeMutableRawPointer, _ set: @escaping @convention(c) (Int32, UnsafeMutableRawPointer) -> Void) {
UniBridge.shared.structMapper.getValue = { get($0.rawValue) }
UniBridge.shared.structMapper.setValue = { set($0.rawValue, $1) }
}

@_cdecl("uniRegisterArray")
public func uniRegisterArray(_ get: @escaping @convention(c) (Int32) -> UnsafeMutableRawPointer, _ set: @escaping @convention(c) (Int32, UnsafeMutableRawPointer) -> Void) {
UniBridge.shared.arrayMapper.getValue = { get($0.rawValue) }
UniBridge.shared.arrayMapper.setValue = { set($0.rawValue, $1) }
}
3 changes: 2 additions & 1 deletion app/xcode/Sources/VCamUI/VCamMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import SwiftUI
import VCamEntity
import VCamCamera
import VCamTracking
import VCamBridge

public struct VCamMainView: View {
public init() {}

@UniState(.message, name: "message") private var message
@ExternalStateBinding(.message) private var message

@State private var isCameraExtensionDisallow = false

Expand Down

0 comments on commit 0e4d8fd

Please sign in to comment.