Commit 72a0436a authored by Chunchi Che's avatar Chunchi Che

rerange simpleDuel hands.ts

parent 5c23d243
...@@ -10,39 +10,63 @@ export default (hands: Card[], scene: BABYLON.Scene) => { ...@@ -10,39 +10,63 @@ export default (hands: Card[], scene: BABYLON.Scene) => {
handShape, handShape,
scene scene
); );
// 位置 // 位置&旋转
hand.position = new BABYLON.Vector3( setupHandTransform(hand, item);
item.transform.position?.x, // 材质
item.transform.position?.y, setupHandMaterial(hand, item, scene);
item.transform.position?.z // 事件管理
setupHandAction(hand, item, idx, scene);
});
};
function setupHandTransform(mesh: BABYLON.Mesh, state: Card) {
mesh.position = new BABYLON.Vector3(
state.transform.position?.x,
state.transform.position?.y,
state.transform.position?.z
); );
hand.rotation = new BABYLON.Vector3( mesh.rotation = new BABYLON.Vector3(
item.transform.rotation?.x, state.transform.rotation?.x,
item.transform.rotation?.y, state.transform.rotation?.y,
item.transform.rotation?.z state.transform.rotation?.z
);
}
function setupHandMaterial(
mesh: BABYLON.Mesh,
state: Card,
scene: BABYLON.Scene
) {
const handMaterial = new BABYLON.StandardMaterial(
`handMaterial${state.meta.id}`,
scene
); );
// 材质
const handMaterial = new BABYLON.StandardMaterial("handMaterial", scene);
// 材质贴纸 // 材质贴纸
handMaterial.diffuseTexture = new BABYLON.Texture( handMaterial.diffuseTexture = new BABYLON.Texture(
`https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${item.meta.id}.jpg`, `https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/${state.meta.id}.jpg`,
scene scene
); );
hand.material = handMaterial; mesh.material = handMaterial;
}
// 事件管理 function setupHandAction(
hand.actionManager = new BABYLON.ActionManager(scene); mesh: BABYLON.Mesh,
state: Card,
handIdx: number,
scene: BABYLON.Scene
) {
mesh.actionManager = new BABYLON.ActionManager(scene);
// 监听点击事件 // 监听点击事件
hand.actionManager.registerAction( mesh.actionManager.registerAction(
new BABYLON.ExecuteCodeAction( new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPickTrigger, BABYLON.ActionManager.OnPickTrigger,
(event) => { (event) => {
console.log(`<Click>hand: ${idx}`, "card:", item, "event:", event); console.log(`<Click>hand: ${handIdx}`, "card:", state, "event:", event);
} }
) )
); );
// 监听`Hover`事件 // 监听`Hover`事件
hand.actionManager.registerAction( mesh.actionManager.registerAction(
new BABYLON.CombineAction( new BABYLON.CombineAction(
{ trigger: BABYLON.ActionManager.OnPointerOverTrigger }, { trigger: BABYLON.ActionManager.OnPointerOverTrigger },
[ [
...@@ -50,7 +74,7 @@ export default (hands: Card[], scene: BABYLON.Scene) => { ...@@ -50,7 +74,7 @@ export default (hands: Card[], scene: BABYLON.Scene) => {
{ {
trigger: BABYLON.ActionManager.OnPointerOverTrigger, trigger: BABYLON.ActionManager.OnPointerOverTrigger,
}, },
hand, mesh,
"scaling", "scaling",
CONFIG.HandHoverScaling() CONFIG.HandHoverScaling()
), ),
...@@ -58,14 +82,14 @@ export default (hands: Card[], scene: BABYLON.Scene) => { ...@@ -58,14 +82,14 @@ export default (hands: Card[], scene: BABYLON.Scene) => {
new BABYLON.ExecuteCodeAction( new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPointerOverTrigger, BABYLON.ActionManager.OnPointerOverTrigger,
(event) => { (event) => {
console.log(`<Hover>hand: ${idx}`, "event: ", event); console.log(`<Hover>hand: ${handIdx}`, "event: ", event);
} }
), ),
] ]
) )
); );
// 监听`Hover`离开事件 // 监听`Hover`离开事件
hand.actionManager.registerAction( mesh.actionManager.registerAction(
new BABYLON.CombineAction( new BABYLON.CombineAction(
{ trigger: BABYLON.ActionManager.OnPointerOutTrigger }, { trigger: BABYLON.ActionManager.OnPointerOutTrigger },
[ [
...@@ -73,7 +97,7 @@ export default (hands: Card[], scene: BABYLON.Scene) => { ...@@ -73,7 +97,7 @@ export default (hands: Card[], scene: BABYLON.Scene) => {
{ {
trigger: BABYLON.ActionManager.OnPointerOutTrigger, trigger: BABYLON.ActionManager.OnPointerOutTrigger,
}, },
hand, mesh,
"scaling", "scaling",
CONFIG.HandHoverOutScaling() CONFIG.HandHoverOutScaling()
), ),
...@@ -81,11 +105,10 @@ export default (hands: Card[], scene: BABYLON.Scene) => { ...@@ -81,11 +105,10 @@ export default (hands: Card[], scene: BABYLON.Scene) => {
new BABYLON.ExecuteCodeAction( new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPointerOutTrigger, BABYLON.ActionManager.OnPointerOutTrigger,
(event) => { (event) => {
console.log(`<Hover Out>hand: ${idx}`, "event:", event); console.log(`<Hover Out>hand: ${handIdx}`, "event:", event);
} }
), ),
] ]
) )
); );
}); }
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment