2020-01-09 01:26:04 +00:00
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
|
|
@ccclass
|
2020-01-16 15:05:32 +00:00
|
|
|
|
export default class RoundCornerCropV1EffectScene extends cc.Component {
|
|
|
|
|
private _radiuSlider: cc.Slider = null;
|
|
|
|
|
private _radiuLabel: cc.Label = null;
|
2020-01-09 01:26:04 +00:00
|
|
|
|
|
|
|
|
|
private _examplesParentNode: cc.Node = null;
|
|
|
|
|
|
|
|
|
|
onLoad() {
|
2020-01-09 02:01:28 +00:00
|
|
|
|
// 关闭动态合图
|
|
|
|
|
cc.dynamicAtlasManager.enabled = false;
|
|
|
|
|
|
2020-01-16 15:05:32 +00:00
|
|
|
|
this._radiuSlider = cc.find("Canvas/Content/Controller/RadiusSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._radiuLabel = cc.find("Canvas/Content/Controller/RadiusSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-09 01:26:04 +00:00
|
|
|
|
|
|
|
|
|
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onEnable() {
|
2020-01-16 15:05:32 +00:00
|
|
|
|
this._radiuSlider.node.on("slide", this._onSliderChanged, this);
|
2020-01-09 01:26:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDisable() {
|
2020-01-16 15:05:32 +00:00
|
|
|
|
this._radiuSlider.node.off("slide", this._onSliderChanged, this);
|
2020-01-09 01:26:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
start() {
|
|
|
|
|
this._onSliderChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private _onSliderChanged() {
|
2020-01-16 15:05:32 +00:00
|
|
|
|
this._radiuLabel.string = `${this._radiuSlider.progress.toFixed(2)}`;
|
2020-01-09 01:26:04 +00:00
|
|
|
|
|
2020-01-09 02:01:28 +00:00
|
|
|
|
// 更新材质
|
|
|
|
|
this._updateRenderComponentMaterial({
|
2020-01-16 15:05:32 +00:00
|
|
|
|
roundCornerRadius: this._radiuSlider.progress
|
2020-01-09 02:01:28 +00:00
|
|
|
|
});
|
2020-01-09 01:26:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-09 02:01:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* 更新渲染组件的材质
|
|
|
|
|
*
|
|
|
|
|
* 1. 获取材质
|
|
|
|
|
* 2. 给材质的 unitform 变量赋值
|
|
|
|
|
* 3. 重新将材质赋值回去
|
|
|
|
|
*/
|
|
|
|
|
private _updateRenderComponentMaterial(param: {
|
|
|
|
|
/**
|
|
|
|
|
* 圆角半径 [0.0, 0.5] ,0.5 表示圆形裁剪
|
|
|
|
|
*/
|
|
|
|
|
roundCornerRadius: number;
|
|
|
|
|
}) {
|
|
|
|
|
this._examplesParentNode.children.forEach(childNode => {
|
|
|
|
|
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
|
|
|
|
let material: cc.Material = renderComponent.getMaterial(0);
|
2020-01-16 15:05:32 +00:00
|
|
|
|
material.setProperty("radius", param.roundCornerRadius);
|
2020-01-09 02:01:28 +00:00
|
|
|
|
renderComponent.setMaterial(0, material);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-01-09 01:26:04 +00:00
|
|
|
|
}
|