|
@@ -1,8 +1,9 @@
|
|
|
-import { _decorator, AssetManager, Button, Component, instantiate, Node, sp, Vec2 } from 'cc';
|
|
|
-import { getSelectAllKeys, selectedSkinList, Skin, SkinData } from '../../script/Manager/LocalDataMgr';
|
|
|
+import { _decorator, AssetManager, Button, Component, instantiate, Node, Prefab, sp, Vec2 } from 'cc';
|
|
|
+import { allSkinList, getAllSkinKeys, Skin, SkinData } from '../../script/Manager/LocalDataMgr';
|
|
|
import { SkinItem } from './SkinItem';
|
|
|
import { LayerMgr } from '../../script/Manager/LayerMgr';
|
|
|
import { BundleName } from '../../script/Config/EnumCfg';
|
|
|
+import EventMgr from '../../script/Manager/EventMgr';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('SelectSkinPanel')
|
|
@@ -28,9 +29,9 @@ export class SelectSkinPanel extends Component {
|
|
|
|
|
|
init() {
|
|
|
LayerMgr.instance.loadBundle("editor", () => {
|
|
|
- this._allSkinList = selectedSkinList
|
|
|
+ this._allSkinList = allSkinList
|
|
|
this._skinData = Skin.getSkinData();
|
|
|
- let allSkillKeys = getSelectAllKeys()
|
|
|
+ let allSkillKeys = getAllSkinKeys()
|
|
|
let count = allSkillKeys.length;
|
|
|
for(let i = 0; i < count; i++){
|
|
|
this.createItem(allSkillKeys[i],this.spineoffset);
|
|
@@ -43,17 +44,19 @@ export class SelectSkinPanel extends Component {
|
|
|
itemNode.parent = this.itemRoot;
|
|
|
this._items.push(itemNode);
|
|
|
itemNode.active = true
|
|
|
- let skPath = selectedSkinList[key]
|
|
|
- this.loadSpine(skPath, (spineData: sp.SkeletonData) => {
|
|
|
- itemNode.getComponent(SkinItem).init(key,spineData,"loop2",spineOffset,this.judgeSelect(key))
|
|
|
+ let spPath = allSkinList[key]
|
|
|
+ this.loadSpineData("editor",spPath, (spine: Prefab) => {
|
|
|
+ itemNode.getComponent(SkinItem).init(key,spine,"loop2",spineOffset,this.judgeSelect(key))
|
|
|
})
|
|
|
}
|
|
|
onSingleSkinClick() {
|
|
|
-
|
|
|
+ Skin.setSelectStatu(true)
|
|
|
+ EventMgr.ins.dispatchEvent("regenerate")
|
|
|
}
|
|
|
|
|
|
onMultiSkinClick() {
|
|
|
-
|
|
|
+ Skin.setSelectStatu(false)
|
|
|
+ EventMgr.ins.dispatchEvent("regenerate")
|
|
|
}
|
|
|
|
|
|
judgeSelect(key)
|
|
@@ -65,40 +68,76 @@ export class SelectSkinPanel extends Component {
|
|
|
|
|
|
|
|
|
|
|
|
- spineDataMap: Map<string, sp.SkeletonData> = new Map();
|
|
|
- /**
|
|
|
- * 加载spine数据
|
|
|
- * @param path spine数据路径
|
|
|
- * @param callback 回调函数
|
|
|
- */
|
|
|
- loadSpineData(bundleName: BundleName | string, spinepath: string, callback: (spineData: sp.SkeletonData) => void) {
|
|
|
+ // spineDataMap: Map<string, sp.SkeletonData> = new Map();
|
|
|
+ spineDataMap: Map<string, Prefab> = new Map();
|
|
|
+ // /**
|
|
|
+ // * 加载spine数据
|
|
|
+ // * @param path spine数据路径
|
|
|
+ // * @param callback 回调函数
|
|
|
+ // */
|
|
|
+ // loadSpineData(bundleName: BundleName | string, spinepath: string, callback: (spineData: sp.SkeletonData) => void) {
|
|
|
+ // let bundle: AssetManager.Bundle = LayerMgr.instance.getBundle(bundleName)
|
|
|
+ // if (bundle) {
|
|
|
+ // bundle.load(spinepath, sp.SkeletonData, (err, res) => {
|
|
|
+ // if (err) {
|
|
|
+ // console.error(err)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // let spineData: sp.SkeletonData = (res as sp.SkeletonData);
|
|
|
+ // callback(spineData)
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ loadSpineData(bundleName: BundleName | string, spinepath: string, callback: (sp:Prefab) => void) {
|
|
|
let bundle: AssetManager.Bundle = LayerMgr.instance.getBundle(bundleName)
|
|
|
if (bundle) {
|
|
|
- bundle.load(spinepath, sp.SkeletonData, (err, res) => {
|
|
|
+ bundle.load(spinepath, Prefab, (err, res) => {
|
|
|
if (err) {
|
|
|
console.error(err)
|
|
|
return
|
|
|
}
|
|
|
- let spineData: sp.SkeletonData = (res as sp.SkeletonData);
|
|
|
+ let spineData: Prefab = (res as Prefab);
|
|
|
callback(spineData)
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- loadSpine(path: string, callback: (spineData: sp.SkeletonData) => void) {
|
|
|
+ // loadSpine(path: string, callback: (spineData: sp.SkeletonData) => void) {
|
|
|
+ // if (this.spineDataMap.has(path)) {
|
|
|
+ // callback(this.spineDataMap.get(path));
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // this.loadSpineData("editor", path, (spineData: sp.SkeletonData) => {
|
|
|
+ // this.spineDataMap.set(path, spineData);
|
|
|
+ // callback(spineData);
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ loadSpine(path: string, callback: (sp:Prefab) => void) {
|
|
|
if (this.spineDataMap.has(path)) {
|
|
|
callback(this.spineDataMap.get(path));
|
|
|
return;
|
|
|
}
|
|
|
- this.loadSpineData("editor", path, (spineData: sp.SkeletonData) => {
|
|
|
- this.spineDataMap.set(path, spineData);
|
|
|
- callback(spineData);
|
|
|
+ this.loadSpineData("editor", path, (sp:Prefab) => {
|
|
|
+ this.spineDataMap.set(path, sp);
|
|
|
+ callback(sp);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
clearSelectAllSkins()
|
|
|
{
|
|
|
Skin.removeAllSelectSkin()
|
|
|
+ this.refreshSkinSelectioin()
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshSkinSelectioin()
|
|
|
+ {
|
|
|
+ let allSkillKeys = getAllSkinKeys()
|
|
|
+ let count = allSkillKeys.length;
|
|
|
+ for(let i = 0; i < count; i++){
|
|
|
+ let item = this._items[i]
|
|
|
+ item.getComponent(SkinItem).setSelectSkin(false)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|