CocosCreator-Shader-Effect-.../assets/scripts/RoundCornerCropEffectScene.ts

63 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-01-09 01:26:04 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class RoundCornerCropEffectScene extends cc.Component {
private _roundCornerRadiuSlider: cc.Slider = null;
private _roundCornerRadiuLabel: cc.Label = null;
private _examplesParentNode: cc.Node = null;
onLoad() {
2020-01-09 02:01:28 +00:00
// 关闭动态合图
cc.dynamicAtlasManager.enabled = false;
2020-01-09 01:26:04 +00:00
this._roundCornerRadiuSlider = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/Slider").getComponent(cc.Slider);
this._roundCornerRadiuLabel = cc.find("Canvas/Content/Sliders/RoundCornerRadiusSlider/ValueLabel").getComponent(cc.Label);
this._examplesParentNode = cc.find("Canvas/Content/Examples");
}
onEnable() {
this._roundCornerRadiuSlider.node.on("slide", this._onSliderChanged, this);
}
onDisable() {
this._roundCornerRadiuSlider.node.off("slide", this._onSliderChanged, this);
}
start() {
this._onSliderChanged();
}
private _onSliderChanged() {
this._roundCornerRadiuLabel.string = `${this._roundCornerRadiuSlider.progress.toFixed(2)}`;
2020-01-09 02:01:28 +00:00
// 更新材质
this._updateRenderComponentMaterial({
roundCornerRadius: this._roundCornerRadiuSlider.progress
});
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);
material.setProperty("roundCornerRadius", param.roundCornerRadius);
renderComponent.setMaterial(0, material);
});
});
}
2020-01-09 01:26:04 +00:00
}