Skip to content

Commit

Permalink
Open source
Browse files Browse the repository at this point in the history
  • Loading branch information
tattn committed Oct 16, 2023
1 parent bb2cf52 commit 53ae4ba
Show file tree
Hide file tree
Showing 7 changed files with 728 additions and 44 deletions.
18 changes: 18 additions & 0 deletions app/xcode/Sources/VCamUI/Extensions/CGSize+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CGSize+.swift
//
//
// Created by Tatsuya Tanaka on 2022/04/29.
//

import CoreGraphics

public extension CGSize {
mutating func scaleToFit(size: CGSize) {
if width > height {
width = height * size.width / size.height
} else {
height = width * size.height / size.width
}
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
//
// RootContentView.swift
//
// RootView.swift
//
//
// Created by Tatsuya Tanaka on 2022/06/25.
//

import SwiftUI
import VCamBridge

public struct RootContentView<MenuBottomView: View>: View {
public init(menuBottomView: MenuBottomView, unityView: NSView, interactable: ExternalStateBinding<Bool> = .init(.interactable)) {
self.menuBottomView = menuBottomView
public struct RootView: View {
public init(unityView: NSView, interactable: ExternalStateBinding<Bool> = .init(.interactable)) {
self.unityView = unityView
self.interactable = interactable
}

let unityView: NSView

@StateObject var state = VCamUIState()

@AppStorage(key: .locale) var locale
private var interactable: ExternalStateBinding<Bool>

public var body: some View {
RootViewContent(unityView: unityView, interactable: interactable)
.background(.regularMaterial)
.environmentObject(state)
.environment(\.locale, locale.isEmpty ? .current : Locale(identifier: locale))
}
}

private struct RootViewContent: View {
init(unityView: NSView, interactable: ExternalStateBinding<Bool>) {
self.unityView = unityView
self._interactable = interactable
}

let menuBottomView: MenuBottomView
let unityView: NSView

@ExternalStateBinding(.interactable) private var interactable
@UniReload private var reload: Void

public var body: some View {
var body: some View {
if interactable {
HStack(spacing: 0) {
VCamMenu(
bottomView: menuBottomView.frame(height: 280)
)
.onTapGesture {
unityView.window?.makeFirstResponder(nil)
NotificationCenter.default.post(name: .unfocusObject, object: nil)
}
.disabled(!interactable)
VCamMenu()
.onTapGesture {
unityView.window?.makeFirstResponder(nil)
NotificationCenter.default.post(name: .unfocusObject, object: nil)
}
.disabled(!interactable)

VSplitView {
HStack(alignment: .bottom, spacing: 0) {
Expand Down Expand Up @@ -57,7 +76,7 @@ public struct RootContentView<MenuBottomView: View>: View {
}
}

struct UnityView: View, Equatable {
private struct UnityView: View, Equatable {
let unityView: NSView

var body: some View {
Expand All @@ -70,24 +89,22 @@ struct UnityView: View, Equatable {
static func == (lhs: Self, rhs: Self) -> Bool {
true
}
}

private struct UnityContainerView: NSViewRepresentable {
let unityView: NSView
func makeNSView(context: Context) -> some NSView {
unityView
}
private struct UnityContainerView: NSViewRepresentable {
let unityView: NSView

func makeNSView(context: Context) -> some NSView {
unityView
}

func updateNSView(_ nsView: NSViewType, context: Context) {
func updateNSView(_ nsView: NSViewType, context: Context) {
}
}
}

struct RootContentView_Previews: PreviewProvider {
static var previews: some View {
RootContentView(
menuBottomView: Color.blue,
unityView: NSView(),
interactable: .constant(true)
)
}
#Preview {
RootView(
unityView: NSView(),
interactable: .constant(true)
)
}
4 changes: 4 additions & 0 deletions app/xcode/Sources/VCamUI/SceneObjectManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public final class SceneObjectManager: ObservableObject {
uniUpdateScene()
}

public func didChangeObjects() {
self.objects = objects
}

public func dispose() {
objects = objects.filter { $0.id == SceneObject.avatarID }
RenderTextureManager.shared.removeAll()
Expand Down
Loading

0 comments on commit 53ae4ba

Please sign in to comment.