diff --git a/spine-ts/spine-construct3/src/aces.json b/spine-ts/spine-construct3/src/aces.json index b160a007c..5981d1500 100644 --- a/spine-ts/spine-construct3/src/aces.json +++ b/spine-ts/spine-construct3/src/aces.json @@ -150,6 +150,43 @@ "type": "string" } ] + }, + { + "id": "create-custom-skin", + "scriptName": "CreateCustomSkin", + "highlight": false, + "params": [ + { + "id": "skin-name", + "type": "string" + } + ] + }, + { + "id": "add-custom-skin", + "scriptName": "AddCustomSkin", + "highlight": false, + "params": [ + { + "id": "custom-skin-name", + "type": "string" + }, + { + "id": "skin-to-add-name", + "type": "string" + } + ] + }, + { + "id": "set-custom-skin", + "scriptName": "SetCustomSkin", + "highlight": false, + "params": [ + { + "id": "skin-name", + "type": "string" + } + ] } ], "expressions": [ diff --git a/spine-ts/spine-construct3/src/c3runtime/actions.ts b/spine-ts/spine-construct3/src/c3runtime/actions.ts index 18a314fa9..da4ecc6d8 100644 --- a/spine-ts/spine-construct3/src/c3runtime/actions.ts +++ b/spine-ts/spine-construct3/src/c3runtime/actions.ts @@ -39,6 +39,18 @@ C3.Plugins.EsotericSoftware_SpineConstruct3.Acts = SetAttachment (this: SDKInstanceClass, slotName: string, attachmentName: string) { this.setAttachment(slotName, attachmentName === "" ? null : attachmentName); + }, + + CreateCustomSkin (this: SDKInstanceClass, skinName: string) { + this.createCustomSkin(skinName); + }, + + AddCustomSkin (this: SDKInstanceClass, customSkinName: string, skinToAddName: string) { + this.addCustomSkin(customSkinName, skinToAddName); + }, + + SetCustomSkin (this: SDKInstanceClass, skinName: string) { + this.setCustomSkin(skinName); } }; diff --git a/spine-ts/spine-construct3/src/c3runtime/instance.ts b/spine-ts/spine-construct3/src/c3runtime/instance.ts index 37ee6f3e2..a93173a63 100644 --- a/spine-ts/spine-construct3/src/c3runtime/instance.ts +++ b/spine-ts/spine-construct3/src/c3runtime/instance.ts @@ -1,4 +1,4 @@ -import type { AnimationState, AnimationStateListener, AssetLoader, Event, Skeleton, SkeletonRendererCore, TextureAtlas, } from "@esotericsoftware/spine-construct3-lib"; +import type { AnimationState, AnimationStateListener, AssetLoader, Event, Skeleton, SkeletonRendererCore, Skin, TextureAtlas, } from "@esotericsoftware/spine-construct3-lib"; const C3 = globalThis.C3; const spine = globalThis.spine; @@ -18,6 +18,7 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { propScaleY = 1; propFlipX = false; isPlaying = true; + customSkins: Record = {}; textureAtlas?: TextureAtlas; renderer?: IRenderer; @@ -183,6 +184,45 @@ class SpineC3Instance extends globalThis.ISDKWorldInstanceBase { this.skeleton?.setAttachment(slotName, attachmentName); } + public createCustomSkin (skinName: string) { + if (!this.skeleton) return; + + if (this.customSkins[skinName]) { + this.customSkins[skinName].clear(); + } else { + this.customSkins[skinName] = new spine.Skin(skinName); + } + } + + public addCustomSkin (customSkinName: string, skinToAddName: string) { + if (!this.skeleton) return; + + if (!this.customSkins[customSkinName]) { + console.warn(`[Spine] Custom skin "${customSkinName}" does not exist. Create it first.`); + return; + } + + const skinToAdd = this.skeleton.data.findSkin(skinToAddName); + if (!skinToAdd) { + console.warn(`[Spine] Skin "${skinToAddName}" not found in skeleton data.`); + return; + } + + this.customSkins[customSkinName].addSkin(skinToAdd); + } + + public setCustomSkin (skinName: string) { + if (!this.skeleton) return; + + if (!this.customSkins[skinName]) { + console.warn(`[Spine] Custom skin "${skinName}" does not exist.`); + return; + } + + this.skeleton.setSkin(this.customSkins[skinName]); + this.skeleton.setupPose(); + } + private _setSkin () { const { skeleton } = this; if (!skeleton) return; diff --git a/spine-ts/spine-construct3/src/lang/en-US.json b/spine-ts/spine-construct3/src/lang/en-US.json index 5c276c08d..1785d14f1 100644 --- a/spine-ts/spine-construct3/src/lang/en-US.json +++ b/spine-ts/spine-construct3/src/lang/en-US.json @@ -224,6 +224,43 @@ "desc": "Name of the attachment to set" } } + }, + "create-custom-skin": { + "list-name": "Create custom skin", + "display-text": "Create custom skin {0}", + "description": "Create a new custom skin that can combine multiple skins", + "params": { + "skin-name": { + "name": "Skin name", + "desc": "Name for the custom skin" + } + } + }, + "add-custom-skin": { + "list-name": "Add to custom skin", + "display-text": "Add skin {1} to custom skin {0}", + "description": "Add an existing skin to a custom skin", + "params": { + "custom-skin-name": { + "name": "Custom skin name", + "desc": "Name of the custom skin to add to" + }, + "skin-to-add-name": { + "name": "Skin to add", + "desc": "Name of the existing skin to add" + } + } + }, + "set-custom-skin": { + "list-name": "Set custom skin", + "display-text": "Set custom skin {0}", + "description": "Apply a custom skin to the skeleton", + "params": { + "skin-name": { + "name": "Skin name", + "desc": "Name of the custom skin to apply" + } + } } }, "expressions": { diff --git a/spine-ts/spine-construct3/src/lang/zh-CN.json b/spine-ts/spine-construct3/src/lang/zh-CN.json index 599660a85..3f430ccb6 100644 --- a/spine-ts/spine-construct3/src/lang/zh-CN.json +++ b/spine-ts/spine-construct3/src/lang/zh-CN.json @@ -226,6 +226,43 @@ } } }, + "create-custom-skin": { + "list-name": "创建自定义皮肤", + "display-text": "创建自定义皮肤{0}", + "description": "创建一个可以组合多个皮肤的新自定义皮肤", + "params": { + "skin-name": { + "name": "皮肤名称", + "desc": "自定义皮肤的名称" + } + } + }, + "add-custom-skin": { + "list-name": "添加到自定义皮肤", + "display-text": "将皮肤{1}添加到自定义皮肤{0}", + "description": "将现有皮肤添加到自定义皮肤", + "params": { + "custom-skin-name": { + "name": "自定义皮肤名称", + "desc": "要添加到的自定义皮肤名称" + }, + "skin-to-add-name": { + "name": "要添加的皮肤", + "desc": "要添加的现有皮肤名称" + } + } + }, + "set-custom-skin": { + "list-name": "设置自定义皮肤", + "display-text": "设置自定义皮肤{0}", + "description": "将自定义皮肤应用到骨架", + "params": { + "skin-name": { + "name": "皮肤名称", + "desc": "要应用的自定义皮肤名称" + } + } + }, "expressions": { "double": { "description": "将数字翻倍。",