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 GlowInnerEffectScene extends cc.Component {
|
2019-12-20 07:59:56 +00:00
|
|
|
|
private _redSlider: cc.Slider = null;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
private _redSliderLabel: cc.Label = null;
|
|
|
|
|
|
2019-12-20 07:59:56 +00:00
|
|
|
|
private _greenSlider: cc.Slider = null;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
private _greenSliderLabel: cc.Label = null;
|
|
|
|
|
|
2019-12-20 07:59:56 +00:00
|
|
|
|
private _blueSlider: cc.Slider = null;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
private _blueSliderLabel: cc.Label = null;
|
|
|
|
|
|
2019-12-20 07:59:56 +00:00
|
|
|
|
private _alphaSlider: cc.Slider = null;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
private _alphaSliderLabel: cc.Label = null;
|
|
|
|
|
|
|
|
|
|
private _glowWidthSlider: cc.Slider = null;
|
|
|
|
|
private _glowWidthSliderLabel: cc.Label = null;
|
|
|
|
|
|
2019-12-24 09:07:17 +00:00
|
|
|
|
private _glowThresholdSlider: cc.Slider = null;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
private _glowThresholdSliderLabel: cc.Label = null;
|
|
|
|
|
|
2020-06-23 09:09:30 +00:00
|
|
|
|
private _scrollView: cc.ScrollView = null;
|
2019-12-20 07:59:56 +00:00
|
|
|
|
|
|
|
|
|
onLoad() {
|
2020-06-23 10:51:11 +00:00
|
|
|
|
cc.dynamicAtlasManager.enabled = false;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
this._redSlider = cc.find("Canvas/Content/Sliders/ColorRedSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._redSliderLabel = cc.find("Canvas/Content/Sliders/ColorRedSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
|
|
this._greenSlider = cc.find("Canvas/Content/Sliders/ColorGreenSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._greenSliderLabel = cc.find("Canvas/Content/Sliders/ColorGreenSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
|
|
this._blueSlider = cc.find("Canvas/Content/Sliders/ColorBlueSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._blueSliderLabel = cc.find("Canvas/Content/Sliders/ColorBlueSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
|
|
this._alphaSlider = cc.find("Canvas/Content/Sliders/ColorAlphaSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._alphaSliderLabel = cc.find("Canvas/Content/Sliders/ColorAlphaSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
|
|
this._glowWidthSlider = cc.find("Canvas/Content/Sliders/GlowWidthSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._glowWidthSliderLabel = cc.find("Canvas/Content/Sliders/GlowWidthSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
|
|
this._glowThresholdSlider = cc.find("Canvas/Content/Sliders/GlowThresholdSlider/Slider").getComponent(cc.Slider);
|
|
|
|
|
this._glowThresholdSliderLabel = cc.find("Canvas/Content/Sliders/GlowThresholdSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
2020-06-23 09:09:30 +00:00
|
|
|
|
this._scrollView = cc.find("Canvas/Content/ScrollView").getComponent(cc.ScrollView);
|
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);
|
2019-12-24 10:34:08 +00:00
|
|
|
|
this._glowWidthSlider.node.on("slide", this._onSliderChanged, this);
|
2019-12-24 09:07:17 +00:00
|
|
|
|
this._glowThresholdSlider.node.on("slide", this._onSliderChanged, this);
|
2019-12-20 07:59:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2019-12-24 10:34:08 +00:00
|
|
|
|
this._glowWidthSlider.node.off("slide", this._onSliderChanged, this);
|
2019-12-24 09:07:17 +00:00
|
|
|
|
this._glowThresholdSlider.node.off("slide", this._onSliderChanged, this);
|
2019-12-20 07:59:56 +00:00
|
|
|
|
}
|
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() {
|
2019-12-24 10:34:08 +00:00
|
|
|
|
// 更新进度条值 Label 文本
|
|
|
|
|
this._redSliderLabel.string = `${this._redSlider.progress.toFixed(2)} | ${Math.round(255 * this._redSlider.progress)}`;
|
|
|
|
|
this._greenSliderLabel.string = `${this._greenSlider.progress.toFixed(2)} | ${Math.round(255 * this._greenSlider.progress)}`;
|
|
|
|
|
this._blueSliderLabel.string = `${this._blueSlider.progress.toFixed(2)} | ${Math.round(255 * this._blueSlider.progress)}`;
|
|
|
|
|
this._alphaSliderLabel.string = `${this._alphaSlider.progress.toFixed(2)} | ${Math.round(255 * this._alphaSlider.progress)}`;
|
|
|
|
|
|
2020-06-23 09:12:44 +00:00
|
|
|
|
let realGlowWidthProgress = this._glowWidthSlider.progress * 200;
|
|
|
|
|
this._glowWidthSliderLabel.string = `${realGlowWidthProgress.toFixed(0)}`;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
|
2019-12-24 10:49:48 +00:00
|
|
|
|
// 这里为约束一下值发光阈值值在 [0.0, 0.5] 因为 0.5+ 之后的效果可能就是其他效果,也可以自己修改这里
|
|
|
|
|
// let realGlowThresholdProgress = this._glowThresholdSlider.progress * 0.5;
|
|
|
|
|
let realGlowThresholdProgress = this._glowThresholdSlider.progress;
|
2019-12-24 10:34:08 +00:00
|
|
|
|
this._glowThresholdSliderLabel.string = `${realGlowThresholdProgress.toFixed(2)}`;
|
|
|
|
|
|
|
|
|
|
// 更新材质
|
2019-12-26 07:59:40 +00:00
|
|
|
|
this._updateRenderComponentMaterial({
|
2019-12-20 07:59:56 +00:00
|
|
|
|
glowColor: cc.v4(this._redSlider.progress, this._greenSlider.progress, this._blueSlider.progress, this._alphaSlider.progress),
|
2020-06-23 09:12:44 +00:00
|
|
|
|
glowRange: realGlowWidthProgress,
|
2020-06-23 07:15:55 +00:00
|
|
|
|
glowThreshold: realGlowThresholdProgress,
|
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. 获取材质
|
2019-12-24 10:34:08 +00:00
|
|
|
|
* 2. 给材质的 unitform 变量赋值
|
2019-12-19 02:52:32 +00:00
|
|
|
|
* 3. 重新将材质赋值回去
|
|
|
|
|
*/
|
2019-12-26 07:59:40 +00:00
|
|
|
|
private _updateRenderComponentMaterial(param: {
|
2019-12-20 07:59:56 +00:00
|
|
|
|
/**
|
2020-06-23 09:12:44 +00:00
|
|
|
|
* 发光宽度(px)
|
2019-12-20 07:59:56 +00:00
|
|
|
|
*/
|
2020-06-23 09:12:44 +00:00
|
|
|
|
glowRange: number;
|
2019-12-20 07:59:56 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发光颜色 [0.0, 1.0]
|
|
|
|
|
*/
|
|
|
|
|
glowColor: cc.Vec4;
|
2019-12-24 09:07:17 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发光阈值 [0.0, 1.0]
|
|
|
|
|
*/
|
|
|
|
|
glowThreshold: number;
|
2019-12-20 07:59:56 +00:00
|
|
|
|
}) {
|
2020-06-23 09:09:30 +00:00
|
|
|
|
this._scrollView.content.children.forEach((childNode) => {
|
2020-06-23 07:15:55 +00:00
|
|
|
|
childNode.getComponents(cc.RenderComponent).forEach((renderComponent) => {
|
|
|
|
|
let spriteFrameRect = (<cc.Sprite>renderComponent).spriteFrame.getRect();
|
2019-12-19 08:25:44 +00:00
|
|
|
|
let material: cc.Material = renderComponent.getMaterial(0);
|
2020-06-23 07:15:55 +00:00
|
|
|
|
material.setProperty("spriteWidth", spriteFrameRect.width);
|
|
|
|
|
material.setProperty("spriteHeight", spriteFrameRect.height);
|
2020-06-23 09:12:44 +00:00
|
|
|
|
material.setProperty("glowRange", param.glowRange);
|
2019-12-20 07:59:56 +00:00
|
|
|
|
material.setProperty("glowColor", param.glowColor);
|
2019-12-24 09:07:17 +00:00
|
|
|
|
material.setProperty("glowThreshold", param.glowThreshold);
|
2019-12-19 08:25:44 +00:00
|
|
|
|
renderComponent.setMaterial(0, material);
|
|
|
|
|
});
|
|
|
|
|
});
|
2019-12-19 02:52:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|