【文件属性】:
文件名称:新版Creator 2.1.2,终于支持 ShaderHelper 了----ShaderHelper2.zip
文件大小:793KB
文件格式:ZIP
更新时间:2023-01-05 03:12:32
shader
新版Creator 2.1.2,终于支持 ShaderHelper 了
let
ShaderProperty
=
cc
.
Class
({
name
:
'ShaderProperty'
,
properties
:
{
key
:
''
,
value
:
''
,
}
});
cc
.
Class
({
extends
:
cc
.
Component
,
properties
:
{
effect
:
cc
.
EffectAsset
,
//effect资源
speed
:
0.01
,
//控制动态Shader的time参数
props
:
[
ShaderProperty
],
//shader参数
},
start
()
{
if
(!
this
.
effect
)
{
return
;
}
//获取精灵组件
let
sprite
=
this
.
node
.
getComponent
(
cc
.
Sprite
);
if
(!
sprite
)
{
return
;
}
//实例化一个材质对象
let
material
=
new
cc
.
Material
();
//在材质对象上开启USE_TEXTURE定义
material
.
define
(
'USE_TEXTURE'
,
true
);
//为材质设置effect,也是就绑定Shader了
material
.
effectAsset
=
this
.
effect
;
material
.
name
=
this
.
effect
.
name
;
//将材质绑定到精灵组件上,精灵可以绑定多个材质
//这里我们替换0号默认材质
sprite
.
setMaterial
(
0
,
material
);
//从精灵组件上获取材质,这步很重要,不然没效果
this
.
material
=
sprite
.
getMaterial
(
0
);
//初始化参数
this
.
time
=
0
;
this
.
props
.
forEach
(
item
=>
this
.
material
.
setProperty
(
item
.
key
,
item
.
value
));
},
/**
* 在update事件中更新材质参数
* 不同的Shader这里可能需要重写
*/
update
()
{
if
(!
this
.
material
||
!
this
.
speed
)
{
return
;
}
if
(
this
.
flag
)
{
this
.
time
+=
this
.
speed
;
}
else
{
this
.
time
-=
this
.
speed
;
}
if
(
this
.
time
>=
1.2
)
{
this
.
flag
=
0
;
}
else
if
(
this
.
time
<=
-
0.2
)
{
this
.
flag
=
1
;
}
//更新Shader代码中的time参数
this
.
material
.
setProperty
(
'time'
,
this
.
time
);
},
});
【文件预览】:
settings
----project.json(655B)
----services.json(6KB)
creator.d.ts
gzh.jpg
packages
LICENSE
readme.md
jsconfig.json
project.json
local
----node-library.json(56B)
----settings.json(2B)
----scene.json(47B)
----node-tree-state.json(1KB)
----console.json(80B)
----layout.windows.json(2KB)
----logs()
--------project.log(32KB)
----local.json(57B)
assets
----components()
--------ShaderTime.ts.meta(197B)
--------ShaderNameLabel.ts(566B)
--------ShaderHelper.ts(3KB)
--------ShaderHelper.ts.meta(197B)
--------ShaderNameLabel.ts.meta(197B)
--------ShaderTime.ts(1KB)
--------.DS_Store(6KB)
----scene.meta(137B)
----resources()
--------effects()
--------effects.meta(137B)
----texutres()
--------content.png(94KB)
--------image.jpg.meta(733B)
--------wcard.png(205KB)
--------image.jpg(239KB)
--------wcard.png.meta(739B)
--------content.png.meta(735B)
----texutres.meta(137B)
----resources.meta(137B)
----scene()
--------test-single.fire(6KB)
--------test-single.fire.meta(146B)
--------test-shader-display.fire(69KB)
--------test-shader-display.fire.meta(146B)
----components.meta(137B)
----.DS_Store(6KB)