indexManager.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 EventName from "../EventName/EventName";
  8. import MyComponent from "../Template/MyComponent";
  9. import BarrierDrag from "./barrierDrag";
  10. const { ccclass, property } = cc._decorator;
  11. //负责子节点的 层级排序
  12. @ccclass
  13. export default class indexManager extends MyComponent {
  14. // LIFE-CYCLE CALLBACKS:
  15. onLoad() {
  16. super.onLoad();
  17. this.regEvent(EventName.UpdataRender, this.up, this)
  18. }
  19. up() {
  20. // //玩家不再编辑中 才排序
  21. // if (!BarrierDrag.PlayEditer && this.node.children.length > 0) {
  22. // // this.node.setSiblingIndex(this.node.parent.childrenCount)
  23. // for (let index = 0; index < this.node.children.length; index++) {
  24. // const element = this.node.children[index];
  25. // let tempBarrierDrag = element.getComponent(BarrierDrag)
  26. // if (tempBarrierDrag) {
  27. // let MapPos = tempBarrierDrag.getNodeMapPos()
  28. // element.zIndex = (200 - (MapPos.x + MapPos.y * 6))
  29. // }
  30. // }
  31. // }
  32. //玩家不再编辑中 才排序
  33. if (this.node.children.length > 0) {
  34. // this.node.setSiblingIndex(this.node.parent.childrenCount)
  35. for (let index = 0; index < this.node.children.length; index++) {
  36. const element = this.node.children[index];
  37. let tempBarrierDrag = element.getComponent(BarrierDrag)
  38. if (tempBarrierDrag) {
  39. let MapPos = tempBarrierDrag.getNodeMapPos()
  40. element.zIndex = (200 - (MapPos.x + MapPos.y * 6))
  41. }
  42. }
  43. }
  44. }
  45. onDestroy(): void {
  46. super.onDestroy()
  47. this.unscheduleAllCallbacks()
  48. }
  49. // update (dt) {}
  50. }