2020-01-11 16:35:56 +00:00
|
|
|
import LocalDiffusionCtrl, { LocalDiffusionUniform } from "./LocalDiffusionCtrl";
|
2020-01-11 10:58:30 +00:00
|
|
|
|
2020-01-10 09:44:43 +00:00
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
|
|
|
export default class LocalDiffusionEffectScene extends cc.Component {
|
2020-01-11 10:58:30 +00:00
|
|
|
private _redSlider: cc.Slider = null;
|
|
|
|
private _redSliderLabel: cc.Label = null;
|
|
|
|
|
|
|
|
private _greenSlider: cc.Slider = null;
|
|
|
|
private _greenSliderLabel: cc.Label = null;
|
|
|
|
|
|
|
|
private _blueSlider: cc.Slider = null;
|
|
|
|
private _blueSliderLabel: cc.Label = null;
|
|
|
|
|
|
|
|
private _alphaSlider: cc.Slider = null;
|
|
|
|
private _alphaSliderLabel: cc.Label = null;
|
|
|
|
|
|
|
|
private _radiuSlider: cc.Slider = null;
|
|
|
|
private _radiuSliderLabel: cc.Label = null;
|
2020-01-10 09:44:43 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
private _cropAlphaToggle: cc.Toggle = null;
|
|
|
|
|
2020-01-10 09:44:43 +00:00
|
|
|
private _examplesParentNode: cc.Node = null;
|
|
|
|
|
|
|
|
onLoad() {
|
2020-01-10 15:05:44 +00:00
|
|
|
cc.dynamicAtlasManager.enabled = false;
|
2020-01-10 09:44:43 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
this._redSlider = cc.find("Canvas/Content/Controller/ColorRedSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._redSliderLabel = cc.find("Canvas/Content/Controller/ColorRedSlider/ValueLabel").getComponent(cc.Label);
|
|
|
|
|
|
|
|
this._greenSlider = cc.find("Canvas/Content/Controller/ColorGreenSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._greenSliderLabel = cc.find("Canvas/Content/Controller/ColorGreenSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-11 10:58:30 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
this._blueSlider = cc.find("Canvas/Content/Controller/ColorBlueSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._blueSliderLabel = cc.find("Canvas/Content/Controller/ColorBlueSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-11 10:58:30 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
this._alphaSlider = cc.find("Canvas/Content/Controller/ColorAlphaSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._alphaSliderLabel = cc.find("Canvas/Content/Controller/ColorAlphaSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-11 10:58:30 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
this._radiuSlider = cc.find("Canvas/Content/Controller/RadiuSlider/Slider").getComponent(cc.Slider);
|
|
|
|
this._radiuSliderLabel = cc.find("Canvas/Content/Controller/RadiuSlider/ValueLabel").getComponent(cc.Label);
|
2020-01-11 10:58:30 +00:00
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
this._cropAlphaToggle = cc.find("Canvas/Content/Controller/CropAlphaToggle/Toggle").getComponent(cc.Toggle);
|
2020-01-11 10:58:30 +00:00
|
|
|
|
|
|
|
// 代码添加控制脚本
|
2020-01-10 09:44:43 +00:00
|
|
|
this._examplesParentNode = cc.find("Canvas/Content/Examples");
|
2020-01-11 10:58:30 +00:00
|
|
|
this._examplesParentNode.children.forEach(childNode => {
|
|
|
|
childNode.addComponent(LocalDiffusionCtrl);
|
|
|
|
});
|
2020-01-10 09:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onEnable() {
|
2020-01-11 16:35:56 +00:00
|
|
|
this._redSlider.node.on("slide", this._onPropertyChanged, this);
|
|
|
|
this._greenSlider.node.on("slide", this._onPropertyChanged, this);
|
|
|
|
this._blueSlider.node.on("slide", this._onPropertyChanged, this);
|
|
|
|
this._alphaSlider.node.on("slide", this._onPropertyChanged, this);
|
|
|
|
this._radiuSlider.node.on("slide", this._onPropertyChanged, this);
|
|
|
|
this._cropAlphaToggle.node.on("toggle", this._onPropertyChanged, this);
|
2020-01-10 09:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onDisable() {
|
2020-01-11 16:35:56 +00:00
|
|
|
this._redSlider.node.off("slide", this._onPropertyChanged, this);
|
|
|
|
this._greenSlider.node.off("slide", this._onPropertyChanged, this);
|
|
|
|
this._blueSlider.node.off("slide", this._onPropertyChanged, this);
|
|
|
|
this._alphaSlider.node.off("slide", this._onPropertyChanged, this);
|
|
|
|
this._radiuSlider.node.off("slide", this._onPropertyChanged, this);
|
|
|
|
this._cropAlphaToggle.node.off("toggle", this._onPropertyChanged, this);
|
2020-01-10 09:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
2020-01-11 16:35:56 +00:00
|
|
|
this._onPropertyChanged();
|
2020-01-10 09:44:43 +00:00
|
|
|
}
|
|
|
|
|
2020-01-11 16:35:56 +00:00
|
|
|
private _onPropertyChanged() {
|
2020-01-11 10:58:30 +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)}`;
|
|
|
|
this._radiuSliderLabel.string = `${this._radiuSlider.progress.toFixed(2)}`;
|
2020-01-10 09:44:43 +00:00
|
|
|
|
2020-01-11 10:58:30 +00:00
|
|
|
// 通知子节点更新材质
|
2020-01-10 09:44:43 +00:00
|
|
|
this._examplesParentNode.children.forEach(childNode => {
|
2020-01-11 16:35:56 +00:00
|
|
|
childNode.emit("on_property_change", <LocalDiffusionUniform>{
|
|
|
|
centerColor: cc.color(
|
2020-01-11 10:58:30 +00:00
|
|
|
Math.round(255 * this._redSlider.progress),
|
|
|
|
Math.round(255 * this._greenSlider.progress),
|
|
|
|
Math.round(255 * this._blueSlider.progress),
|
|
|
|
Math.round(255 * this._alphaSlider.progress)
|
|
|
|
),
|
2020-01-11 16:35:56 +00:00
|
|
|
radius: this._radiuSlider.progress,
|
|
|
|
cropAlpha: this._cropAlphaToggle.isChecked
|
|
|
|
});
|
2020-01-10 09:44:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|