UECell.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import UEBase from "../../frameWork/compment/UEBase";
  2. import UECube from "./UECube";
  3. const { ccclass, property } = cc._decorator;
  4. export interface I_CellData {
  5. zIndex: number;
  6. ueCube: UECube;
  7. }
  8. @ccclass
  9. export default class UECell extends UEBase {
  10. static readonly BundleKey: string = "gridMap";
  11. static readonly PrefabUrl: string = "UECell";
  12. static readonly CLS: string = "UECell";
  13. @property(cc.Node)
  14. private node_select: cc.Node = null!;
  15. cellData: I_CellData = null!;
  16. Init(cellData: I_CellData) {
  17. this.cellData = cellData;
  18. this.node.zIndex = cellData.zIndex;
  19. }
  20. SetCube(cube: UECube) {
  21. this.cellData.ueCube = cube;
  22. if (cube) {
  23. this.cellData.ueCube.SetZIndex(this.cellData.zIndex);
  24. }
  25. }
  26. SetSelect(isSelect: boolean) {
  27. this.node_select.active = isSelect;
  28. }
  29. /** 是否有物品可以拖动 */
  30. CanDrag(): boolean {
  31. return !this.IsEmpty();
  32. }
  33. GetCube(): UECube {
  34. return this.cellData.ueCube;
  35. }
  36. /** 该棋格是否是空的 */
  37. IsEmpty(): boolean {
  38. return this.cellData.ueCube == null;
  39. }
  40. MoveCubeToCell(toCell: UECell) {
  41. this.cellData.ueCube.MoveToNewPos(toCell.node.position.clone());
  42. }
  43. }