输入
⚠️ 已弃用:推荐使用数据绑定(Data Binding)替代输入(Inputs)来控制 Rive 动画。
输入(Inputs)让你在运行时通过数值、布尔值和触发器来控制状态机。
控制输入
与 rive-android 运行时中的其他方法一样,使用视图来设置状态机输入的值。这种情况下无需获取状态机输入实例的引用来设置值。
有三种不同的方法用于设置数值、布尔值和触发器输入:
.setNumberState(stateMachineName: String, inputName: String, value: Float).setBooleanState(stateMachineName: String, inputName: String, value: Boolean).fireState(stateMachineName: String, inputName: String)
// 设置数值输入
animationView.setNumberState("Designer's Test", "Level", 0f)
// 设置布尔输入
animationView.setBooleanState("Boolean test", "foo", true)
// 触发一个触发器输入
animationView.fireState("Trigger test", "fireInput")
嵌套输入
使用路径来访问嵌套输入。设置上例中的 Volume 输入:
// `animationView` 是 RiveAnimationView
animationView.setNumberStateAtPath("volume", 80.0, "Volume Molecule/Volume Component")
RiveAnimationView 上的所有选项:
setNumberStateAtPath(inputName: String, value: Float, path: String)setBooleanStateAtPath(inputName: String, value: Boolean, path: String)fireStateAtPath(inputName: String, path: String)
RiveFileController 上的所有选项:
setNumberStateAtPath(inputName: String, value: Float, path: String)setBooleanStateAtPath(inputName: String, value: Boolean, path: String)fireStateAtPath(inputName: String, path: String)