mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-09-25 08:05:57 +00:00
完善 docs
This commit is contained in:
2691
demo/assets/spine/skin/spine-skin.prefab
Normal file
2691
demo/assets/spine/skin/spine-skin.prefab
Normal file
File diff suppressed because it is too large
Load Diff
8
demo/assets/spine/skin/spine-skin.prefab.meta
Normal file
8
demo/assets/spine/skin/spine-skin.prefab.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"ver": "1.2.9",
|
||||
"uuid": "03129ae1-98e5-4264-a51b-6f95f23d742a",
|
||||
"optimizationPolicy": "AUTO",
|
||||
"asyncLoadAssets": false,
|
||||
"readonly": false,
|
||||
"subMetas": {}
|
||||
}
|
60
demo/assets/spine/skin/spine-skin.ts
Normal file
60
demo/assets/spine/skin/spine-skin.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
@ccclass
|
||||
export default class SpineSkin extends cc.Component {
|
||||
|
||||
@property(cc.Node)
|
||||
addBoyBtn: cc.Node = null;
|
||||
|
||||
@property(cc.Node)
|
||||
removeBoyBtn: cc.Node = null;
|
||||
|
||||
@property(cc.Node)
|
||||
randomChangeBtn: cc.Node = null;
|
||||
|
||||
@property(cc.Node)
|
||||
boy: cc.Node = null;
|
||||
|
||||
@property([cc.SpriteFrame])
|
||||
heads: cc.SpriteFrame[] = [];
|
||||
|
||||
boys: cc.Node[] = [];
|
||||
|
||||
protected start(): void {
|
||||
const boySpine = this.boy.getComponentInChildren(sp.Skeleton);
|
||||
const newSkeletonData = boySpine.skeletonData.clone();
|
||||
boySpine.skeletonData = newSkeletonData;
|
||||
boySpine.animation = 'attack';
|
||||
|
||||
this.boys.push(this.boy);
|
||||
|
||||
this.addBoyBtn.on('click', () => {
|
||||
const newBoy = cc.instantiate(this.boy);
|
||||
const newBoySpine = newBoy.getComponentInChildren(sp.Skeleton);
|
||||
boySpine.skeletonData = newBoySpine.skeletonData.clone();
|
||||
boySpine.animation = 'attack';
|
||||
|
||||
this.boy.parent.addChild(newBoy);
|
||||
newBoy.setPosition(this.boys[this.boys.length - 1].position);
|
||||
newBoy.x += 100;
|
||||
if (this.boys.length % 2 === 1) {
|
||||
newBoy.getComponentInChildren(sp.Skeleton).setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.PRIVATE_CACHE);
|
||||
newBoy.getComponentInChildren(cc.Label).string = `Spine - Cache`;
|
||||
}
|
||||
this.boys.push(newBoy);
|
||||
});
|
||||
|
||||
this.removeBoyBtn.on('click', () => {
|
||||
if (this.boys.length > 1) {
|
||||
this.boys[this.boys.length - 1].destroy();
|
||||
this.boys.length -= 1;
|
||||
}
|
||||
});
|
||||
|
||||
this.randomChangeBtn.on('click', () => {
|
||||
const boy = this.boys[this.boys.length - 1].getComponentInChildren(sp.Skeleton);
|
||||
boy.setRegion('Head', 'Head', sp.SkeletonData.createRegion(this.heads[Math.floor(Math.random() * (this.heads.length))]));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
9
demo/assets/spine/skin/spine-skin.ts.meta
Normal file
9
demo/assets/spine/skin/spine-skin.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.8",
|
||||
"uuid": "27990422-853f-43c5-a2c7-52900cb9edef",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user