AllArea.ts 911 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import ViewObject from "../main/ViewObject";
  2. import Area, { Zone } from "./Area";
  3. import ZoneItem from "./item/ZoneItem";
  4. /**
  5. * 所有分区
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class AllArea extends ViewObject {
  10. public area:Area;
  11. @property(cc.Node)
  12. mContent: cc.Node = null;
  13. @property(cc.Prefab)
  14. mZoneItem: cc.Prefab = null;
  15. onLoad () {
  16. let zones = this.area.zones;
  17. for (let i = 0; i < zones.length; i++) {
  18. const element = zones[i];
  19. this.addItem(element);
  20. }
  21. }
  22. public addItem(zone:Zone){
  23. let node = cc.instantiate(this.mZoneItem);
  24. let item = node.getComponent(ZoneItem);
  25. item.zone = zone;
  26. node.parent = this.mContent;
  27. item.setCallback((m:ZoneItem)=>{
  28. this.area.setOptZone(m.zone);
  29. this.__distroyAll();
  30. });
  31. }
  32. }