部分解决方案
您可以behaviours
以某种非常有限的方式访问和重新创建。为此,您需要Notify
在 Reality Composer 的动作序列中包含具有明确名称的动作。
RealityKit 的代码如下所示:
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
let boxAnchor = try! Experience.loadBox()
arView.scene.anchors.append(boxAnchor)
boxAnchor.actions.repetitive.onAction = self.remodelling
}
fileprivate func remodelling(_ entity: Entity?) {
guard let entity = entity else { return }
entity.children[0].position.x = -0.25
let modelEntity = entity.children[0] as! ModelEntity
modelEntity.model?.mesh = .generateSphere(radius: 0.1)
modelEntity.model?.materials = [UnlitMaterial(color: .green)]
}
}
其中actions
实例属性是:
public private(set) lazy var actions: Actions { get set }
repetitive
是:
public private(set) lazy var repetitive: Experience.NotifyAction { get set }
onAction
是:
public var onAction: ((Entity?) -> Void)?
附加信息
以下是不可编辑的内容ActionsAndBehaviours.Experience.Box.Actions
:
import Combine
import Foundation
import RealityKit
import SwiftOnoneSupport
import UIKit
import simd
@available(iOS 13.0, macOS 10.15, *)
public enum Experience {
public class NotifyAction {
public let identifier: String
public var onAction: ((Entity?) -> Void)?
}
public enum LoadRealityFileError : Error {
case fileNotFound(String)
}
public static func loadBox() throws -> ActionsAndBehaviours.Experience.Box
public static func loadBoxAsync(completion: @escaping (Result<ActionsAndBehaviours.Experience.Box, Error>) -> Void)
public class Box : Entity, HasAnchoring {
public var steelBox: Entity? { get }
lazy public private(set) var actions: ActionsAndBehaviours.Experience.Box.Actions
public class Actions {
lazy public private(set) var repetitive: ActionsAndBehaviours.Experience.NotifyAction
lazy public private(set) var allActions: [ActionsAndBehaviours.Experience.NotifyAction]
}
}
}