Collect.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import { ItemName } from "../EventName/EventName";
  8. import PopComponet from "../Template/PopComponet";
  9. import CollectManger from "./CollectManger";
  10. import Collectitem from "./Collectitem";
  11. import PopManger from "./PopManger";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class Collect extends PopComponet {
  15. @property(cc.Node)
  16. Itemparent: cc.Node = null
  17. protected onEnable(): void {
  18. this.init_progress()
  19. this.init_item()
  20. }
  21. init_progress() {
  22. let _progress = CollectManger.getInstance().HoldNum / CollectManger.getInstance().Total
  23. this.node.getComponentInChildren(cc.ProgressBar).progress = _progress
  24. this.node.getComponentInChildren(cc.ProgressBar).node.getComponentInChildren(cc.Label).string =
  25. `已收集${CollectManger.getInstance().HoldNum}/${CollectManger.getInstance().Total}`
  26. }
  27. init_item() {
  28. CollectManger.getInstance().AllCollectList.forEach(element => {
  29. PopManger.getInstance().LoadAssets<cc.Prefab>(ItemName.Collectitem).then((Prefab) => {
  30. let subPrefab = cc.instantiate(Prefab)
  31. subPrefab.getComponent(Collectitem).MyType = element
  32. subPrefab.parent = this.Itemparent
  33. }).catch((error) => {
  34. // 加载失败的处理
  35. });
  36. })
  37. }
  38. }