swift visionOS 1.0中不推荐使用“baseColor”:请改用“color”属性

xzv2uavs  于 12个月前  发布在  Swift
关注(0)|答案(1)|浏览(112)

我在visionOS应用程序中从URL加载后在平面上显示图像。它工作正常,但我收到此警告:
visionOS 1.0中不推荐使用baseColor:改用color属性

static func fetch(url: String) {
   let remoteURL = URL(string: url)!
          
   let fileURL = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
           
   let data = try! Data(contentsOf: remoteURL)
   try! data.write(to: fileURL)

   do {
        let texture = try TextureResource.load(contentsOf: fileURL)
        var material = SimpleMaterial()
        material.baseColor = MaterialColorParameter.texture(texture)
        
   } catch  {
        print(error.localizedDescription)
    }
}

字符串
如果我试着通过这样做来修复它:

material.color = MaterialColorParameter.texture(texture)


我得到这个错误:

Cannot assign value of type 'MaterialColorParameter' to type 'SimpleMaterial.BaseColor' (aka 'PhysicallyBasedMaterial.BaseColor')


你知道问题出在哪里吗?谢谢!

ppcbkaq5

ppcbkaq51#

SimpleMaterial.BaseColor(iOS 15+)与SimpleMaterial.MaterialColorParameter(iOS 13+)的类型不同。您无法为彼此分配不同的类型。请尝试以下操作:

do {
    let texture = try TextureResource.load(contentsOf: fileURL)
    var material = SimpleMaterial()
    material.color = SimpleMaterial.BaseColor(tint: .white, texture: .init(texture))
}

字符串

相关问题