在设计中我们会经常遇到要让节点的属性跟随其他节点属性的值一起变化,这个时候我们可以使用kanzi里的绑定实现。

通过绑定,我们可以实现根据其他节点的属性和属性分量来刷新一个节点的属性和属性分量。绑定能够让在其他节点属性改变或者外部事件发生的情况下,自动更新属性的值。

最简单的绑定就是将一个节点的属性绑定到一个常量或者它自己的一个属性,复杂些的比如将一个节点的属性和属性分量绑定到几个其他不同节点。在kanzi studio中,可以在节点的属性窗口里Bingdings属性下添加绑定,而且,kanzi studio会用蓝色标注有绑定的属性,如下图:

当创建绑定时要注意以下几点:

1、只有绑定到相似的数据类型才是有效的。比如,你只能将颜色属性绑定颜色属性上,是二维向量的属性绑定到二维向量的属性上等。

2、绑定只会算绑定表达式的最终值,不论是一元、二元操作,还是一个固定值或者变量。

3、在绑定中,四种基本类型(integer,float,boolean和string)是都可以相互转换。在integer,float,boolean这三种类型之间转换,会根据属性的类型隐式转换的。但无论是转到string类型,还是从string类型转到其他,都是要指明的。

下面我们重点来看看属性绑定表达式的使用,我们首先来看看它的语法:

1、注释

语法:#(comments)

#后面可以跟着我们的注释。如下:

#后面就可以跟着注释
#计算A的值
A = (4 + 5)

2、基本加减乘除、赋值:

A=4
B=2
#Return  6
A + B
#Reurn 2
A - B
#Return 8
A * B
#Return 2
A / B

3、类型转换:

1)转换成整形

语法:INT(value)

2)转换成浮点类型

语法:FLOAT(value)

3)转换成布尔类型

语法:BOOL(valued)

4)转换成字符串类型

语法:STRING(value)

4、内置函数:

1)绝对值

语法:ABS(value)

2)  动画

语法:Animation(property,“animationDataResourceID”)

3)计算大于等于的最小的整数

CEIL(value)

4)将值限定到一定范围(MIN(MAX(value,low),high))

语法:CLAMP(low,high,value)

5)计算小于等于的最大整数

语法:FLOOR(value)

6)Linear step(return the same value as CLAMP(0,1,(value-low)/(high-low))

语法:LINEARSTEP(low,high,value)

7)Round(计算最接近的整数)

语法:ROUND(value)

8)指数

语法:POW(n,e)

9)求模

语法:MOD(value1,value2)

10)求平方根

语法:SQRT(n)

11)比较阈值

语法:STEP(threshold,value)

返回值:如果大于等于threshold,返回1,否则返回0.

12)颜色分量

语法:Color4(r,g,b,a)

# Sets the color to white and opaque.
Color4(1, 1, 1, 1)# Same as above, but with alternative syntax.
Color(1, 1, 1, 1)# Sets the color to red with 50% transparency.
Color4(1, 0, 0, 0.5)# Invalid expression, one argument is missing.
Color4(0.1, 1, 0.4)
# Use variables as attributes of the Color4() to assign the
# attribute values of the whole Color property.
#
# Assigns custom properties Red, Green, and Blue to variables
# you use to control the color of an object.
red = {@./Red}
green = {@./Green}
blue = {@./Blue}
color = Color4(0, 0, 0, 1)
# Assigns the red, green, and blue variables to each color channel attribute.
color.ColorR = red
color.ColorG = green
color.ColorB = blue
color

13)转换分量

语法:MatrixSRT(ScaleX,ScaleY,ScaleZ,RotationX,RotationY,RotationZ,TranslationX,TranslationY,TranslationZ)

# Scales the object on the x, y, and z axes to 1 unit,
# rotates it around the x axis by 30 degrees
# and moves it on the z axis by 2 units.
MatrixSRT(1, 1, 1, 30, 0, 0, 0, 0, 2)
# Use variables as attributes of the MatrixSRT() to assign the
# attribute values of the whole Render Transformation property.# Assigns custom property Rotation to a variable you use to control
# the rotation of an object.
rotate = {@./Rotation}
position = MatrixSRT(1, 1, 1, 0, 0, 0, 0, 0, 0)# Assigns the rotation variable to each rotation attribute.
position.RotationX = rotate
position.RotationY = rotate
position.RotationZ = rotate
position

接下里看看绑定的表达式:

1、属性绑定:

语法:{[path]/[property]}

当你在路径前使用@符号,当资源和目标对象之间位置发生了改变,kanzi sudio会自动帮你更新绑定的表达式,否则,如果没有用@符号,节点相对位置发生了改变,表达式不会更新,绑定就会失效。但是要注意使用@符号用于属性绑定只能用于同一个模板,不能用于不同模板之间。

# Binds to property Layout Width of the current object.
{@./LayoutWidth}# Binds to the property FOV of the Camera object.
{../Camera/Fov}

2、别名(alias)绑定

语法:{#[aliasName]/[property]}

# Binds to the Layout Width property of the target object of the alias named Sphere.
{#Sphere/LayoutWidth}# Multiplies the FOV property of the target object of the alias named MainCamera
# with the Render Transformation property attribute Scale X.
{#MainCamera/Fov} * {../Box/RenderTransformation}.ScaleX

3、分量(attribute)绑定

语法:{[path]/[property].[attribute]}

# Binds to the attribute Scale X (value of the Scale X attribute)
# of the Box node's Layout Transformation property.
{../Box/LayoutTransformation}.ScaleX# Multiply property FOV with Render Transformation property attribute Scale X.
{../Camera/Fov} * {../Box/RenderTransformation}.ScaleX

Kanzi学习之路(6):属性绑定相关推荐

  1. Kanzi学习之路(1):Kanzi的简介和安装

    2016年底的时候,写了一篇kanzi学习之路的序,http://blog.csdn.net/u010977122/article/details/53791660 ,希望感兴趣的猿友or媛友一起加入 ...

  2. kanzi学习之路(序)

    凤凰科技讯 北京时间2016年12月19日消息,据外媒报道,中国移动操作系统公司中科创达软件股份有限公司在周一宣布,已同意以6400万欧元(约合6700万美元)收购芬兰汽车软件公司Rightware. ...

  3. Kanzi学习之路(4):Kanzi的属性系统

    由于中间隔了一个年假,所以这两周都没有更新,今天来一起学习一下kanzi的属系统,由于内容太多,本文只讲解一些概念和在kanzi studio中的使用,下一次会分享在kanzi engine中的使用. ...

  4. Kanzi学习之路(2):Hello world!

    安装了kanzi之后,今天我们先来写一个简单的Hello World程序,了解kanzi开发的一个大体流程,从UI设计师用kanzi studio开发,到到处kzb资源文件,再 到软件工程师用vs开发 ...

  5. Kanzi学习之路(3):Kanzi的树形结构和常用控件介绍

    今天我们来通过kanzi studio,感性的了解一下kanzi App的结构和一些常用的控件. 首先我们先新建一个工程,lesson3,通过前面的学习,对于kanzi studio的交互界面有了初步 ...

  6. Kanzi学习之路(7):kanzi的资源预加载

    为了便于资源文件的管理,kanzi有着一套自己的资源文件管理系统,将所有的资源文件打包进.kzb文件中.但是资源文件又很庞大,为了加快开机速度,应用程序的响应速度,很多时候我们要选择预加载资源,多线程 ...

  7. HTML学习之路-11background属性

    目录 一.基本介绍 二.案例 1 a.代码 b.结果 c.总结 三.案例二背景图定位 a.要求 四.雪碧图背景列表 一.基本介绍 background属性是css中应用比较多,且比较重要的一个属性,它 ...

  8. Mendix敏捷开发零基础学习《一》-基础(数据模型、页面创建、数据源绑定、属性绑定、关系型数据模型)

    目录结构 Mendix敏捷开发零基础学习<一> 一.环境依赖 二.业务场景 三.需求分析 四.项目实现 1.创建项目 2.创建数据模型 3.创建页面 4.数据源绑定 5.属性绑定 6.数据 ...

  9. F#学习之路(3) 如何组织程序(下)

    二.名称空间(namespace) 名称空间,将一组逻辑上相关的类型.模块放在一起,主要是为了解决名称冲突的问题,同时也便于更好的理解程序结构.F#的名称空间概念及定义与C#基本相似. 1.定义名称空 ...

最新文章

  1. usaco Factorials
  2. 【C++语法】回车与换行(vs2008)
  3. Symfony2学习笔记之HTTP Cache
  4. Eigen: C++开源矩阵计算工具——Eigen的简单用法
  5. 通用分销渠道和通用产品组的解析
  6. Spring Boot集成JPA的Column注解命名字段无效的问题
  7. 怎么样把c语言转变为汇编语言,如何把汇编语言转换成C语言
  8. OCS 2007 R2搭建后端SQL 2005企业版池
  9. 曾经“杀手级”的桌面语言 Java 将要退隐江湖?
  10. poj 1503 Integer Inquiry高精度
  11. Jquery ajax, Axios, Fetch区别之我见
  12. python:TypeError: ‘dict_keys‘ object does not support indexing
  13. AForge.net获取摄像头
  14. 基于python的毕业设计仓库库存管理系统
  15. javassist使用
  16. libtorrent安装windows版
  17. linux开机自动启动sh脚本
  18. 让Excel 只显示有限行和列
  19. Insert Guest Additions CD image 没有反应
  20. Dango 之 Xadmin

热门文章

  1. spring管理事务管理1----------编程式(以下源码均为spring2.5.6)
  2. 计算机学院毕业典礼口号,大学毕业典礼横幅标语大全
  3. 适用Macos的几款好用的人物照片编辑工具
  4. win10隐藏3d对象等文件夹(自用)
  5. 浏览器支持base64编码
  6. 解决电脑插耳机声音外放
  7. 数据中台的云原生机会 | 甲子光年
  8. [ExtJS] 颜色选择器2.0
  9. Android系统之制作开机LOGO
  10. 叮叮获取所有用户信息_钉钉小程序获取用户信息