2019-12-19 02:52:32 +00:00
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
|
|
@ccclass
|
2019-12-20 02:58:26 +00:00
|
|
|
|
export default class GlowOutterEffectScene extends cc.Component {
|
2019-12-19 08:25:44 +00:00
|
|
|
|
@property(cc.Node)
|
|
|
|
|
examplesParentNode: cc.Node = null;
|
2019-12-19 02:52:32 +00:00
|
|
|
|
|
|
|
|
|
start() {
|
2019-12-19 08:25:44 +00:00
|
|
|
|
this._updateRenderComponentOutterGlowMaterial(0);
|
2019-12-19 02:52:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSideCallBack(slider: cc.Slider, customEventData: string) {
|
2019-12-19 08:25:44 +00:00
|
|
|
|
this._updateRenderComponentOutterGlowMaterial(slider.progress / 100);
|
2019-12-19 02:52:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-12-19 08:25:44 +00:00
|
|
|
|
* 更新渲染组件的材质
|
2019-12-19 02:52:32 +00:00
|
|
|
|
*
|
|
|
|
|
* 1. 获取材质
|
|
|
|
|
* 2. 给材质的自定义 unitform 变量赋值
|
|
|
|
|
* 3. 重新将材质赋值回去
|
|
|
|
|
*
|
2019-12-19 08:25:44 +00:00
|
|
|
|
* @param size 描边长度比例[0,1] 比如0.5,那么就是宽*0.5 高*0.5
|
2019-12-19 02:52:32 +00:00
|
|
|
|
*/
|
2019-12-19 08:25:44 +00:00
|
|
|
|
private _updateRenderComponentOutterGlowMaterial(size: number) {
|
|
|
|
|
this.examplesParentNode.children.forEach(childNode => {
|
|
|
|
|
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
|
|
|
|
|
let material: cc.Material = renderComponent.getMaterial(0);
|
|
|
|
|
material.setProperty("outlineSize", size);
|
|
|
|
|
renderComponent.setMaterial(0, material);
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-19 02:52:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|