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

76 lines
3.0 KiB
TypeScript
Raw Normal View History

2019-12-19 02:52:32 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class GlowInnerEffectScene extends cc.Component {
2019-12-20 07:59:56 +00:00
private _redSlider: cc.Slider = null;
private _greenSlider: cc.Slider = null;
private _blueSlider: cc.Slider = null;
private _alphaSlider: cc.Slider = null;
private _widthSlider: cc.Slider = null;
private _examplesParentNode: cc.Node = null;
onLoad() {
2019-12-24 01:58:54 +00:00
this._redSlider = cc.find("Canvas/Content/SliderLayouts/ColorRedSliderPrefab/Slider").getComponent(cc.Slider);
this._greenSlider = cc.find("Canvas/Content/SliderLayouts/ColorGreenSliderPrefab/Slider").getComponent(cc.Slider);
this._blueSlider = cc.find("Canvas/Content/SliderLayouts/ColorBlueSliderPrefab/Slider").getComponent(cc.Slider);
this._alphaSlider = cc.find("Canvas/Content/SliderLayouts/ColorAlphaSliderPrefab/Slider").getComponent(cc.Slider);
this._widthSlider = cc.find("Canvas/Content/SliderLayouts/GlowWidthSliderPrefab/Slider").getComponent(cc.Slider);
this._examplesParentNode = cc.find("Canvas/Content/Examples");
2019-12-20 07:59:56 +00:00
}
onEnable() {
this._redSlider.node.on("slide", this._onSliderChanged, this);
this._greenSlider.node.on("slide", this._onSliderChanged, this);
this._blueSlider.node.on("slide", this._onSliderChanged, this);
this._alphaSlider.node.on("slide", this._onSliderChanged, this);
this._widthSlider.node.on("slide", this._onSliderChanged, this);
}
onDisable() {
this._redSlider.node.off("slide", this._onSliderChanged, this);
this._greenSlider.node.off("slide", this._onSliderChanged, this);
this._blueSlider.node.off("slide", this._onSliderChanged, this);
this._alphaSlider.node.off("slide", this._onSliderChanged, this);
this._widthSlider.node.off("slide", this._onSliderChanged, this);
}
2019-12-19 02:52:32 +00:00
start() {
2019-12-20 07:59:56 +00:00
this._onSliderChanged();
2019-12-19 02:52:32 +00:00
}
2019-12-20 07:59:56 +00:00
private _onSliderChanged() {
this._updateRenderComponentOutterGlowMaterial({
glowColor: cc.v4(this._redSlider.progress, this._greenSlider.progress, this._blueSlider.progress, this._alphaSlider.progress),
2019-12-23 15:12:22 +00:00
glowColorSize: this._widthSlider.progress * 0.01
2019-12-20 07:59:56 +00:00
});
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-20 07:59:56 +00:00
private _updateRenderComponentOutterGlowMaterial(param: {
/**
* [0.0, 1.0]
*/
glowColorSize: number;
/**
* [0.0, 1.0]
*/
glowColor: cc.Vec4;
}) {
this._examplesParentNode.children.forEach(childNode => {
2019-12-19 08:25:44 +00:00
childNode.getComponents(cc.RenderComponent).forEach(renderComponent => {
let material: cc.Material = renderComponent.getMaterial(0);
2019-12-20 07:59:56 +00:00
material.setProperty("glowColorSize", param.glowColorSize);
material.setProperty("glowColor", param.glowColor);
2019-12-19 08:25:44 +00:00
renderComponent.setMaterial(0, material);
});
});
2019-12-19 02:52:32 +00:00
}
}