12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import { ItemName } from "../EventName/EventName";
- import PopComponet from "../Template/PopComponet";
- import CollectManger from "./CollectManger";
- import Collectitem from "./Collectitem";
- import PopManger from "./PopManger";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Collect extends PopComponet {
- @property(cc.Node)
- Itemparent: cc.Node = null
- protected onEnable(): void {
- this.init_progress()
- this.init_item()
- }
- init_progress() {
- let _progress = CollectManger.getInstance().HoldNum / CollectManger.getInstance().Total
- this.node.getComponentInChildren(cc.ProgressBar).progress = _progress
- this.node.getComponentInChildren(cc.ProgressBar).node.getComponentInChildren(cc.Label).string =
- `已收集${CollectManger.getInstance().HoldNum}/${CollectManger.getInstance().Total}`
- }
- init_item() {
- CollectManger.getInstance().AllCollectList.forEach(element => {
- PopManger.getInstance().LoadAssets<cc.Prefab>(ItemName.Collectitem).then((Prefab) => {
- let subPrefab = cc.instantiate(Prefab)
- subPrefab.getComponent(Collectitem).MyType = element
- subPrefab.parent = this.Itemparent
- }).catch((error) => {
- // 加载失败的处理
- });
- })
- }
- }
|