LayerAction.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, ERigidBody2DType, RigidBody2D } from 'cc';
  2. import { CarColors } from './CarColorsGlobalTypes';
  3. import { PinComponent } from './Components/PinComponent';
  4. import { ElementAction } from './ElementAction';
  5. import { DataModel } from './Model/DataModel';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('LayerAction')
  8. export class LayerAction extends Component {
  9. layer_group_id = 0;
  10. layer_color: CarColors = null;
  11. start() {
  12. }
  13. update(deltaTime: number) {
  14. }
  15. public get_hole_num(): number {
  16. let hole_num: number = 0;
  17. this.node.children.forEach(element_node => {
  18. hole_num += element_node.getComponent(ElementAction).get_hole_num();
  19. });
  20. return hole_num;
  21. }
  22. public init_layer() {
  23. this.layer_group_id = DataModel.get_new_group_index();
  24. this.node.children.forEach(element_node => {
  25. element_node.getComponent(ElementAction).init_element(this.layer_group_id, this.layer_color);
  26. });
  27. }
  28. public init_pin(color_pin_arr: CarColors[]) {
  29. this.node.children.forEach(element_node => {
  30. element_node.getComponent(ElementAction).init_pin(this.layer_group_id, color_pin_arr);
  31. });
  32. }
  33. get_pin_color(arr: PinComponent[]) {
  34. this.node.children.forEach(element_node => {
  35. element_node.getComponent(ElementAction)!.get_pin_color(arr);
  36. });
  37. }
  38. public get_element_num(): number {
  39. return this.node.children.length;
  40. }
  41. layer_status: number = 0;
  42. /**0 =隐藏,1=显示,2=黑色模式 */
  43. public set_status(args: number) {
  44. switch (args) {
  45. case 0:
  46. this.node.active = false;
  47. break;
  48. case 1:
  49. this.node.active = true;
  50. if (this.layer_status == 0) {
  51. this.node.children.forEach(element_node => {
  52. element_node.getComponent(ElementAction)?.flash_img();
  53. });
  54. }
  55. if (this.layer_status == 2) {
  56. this.node.children.forEach(element_node => {
  57. element_node.getComponent(ElementAction)?.set_layer_bg_or_orgin(false);
  58. element_node.getComponent(ElementAction)?.flash_img();
  59. });
  60. }
  61. console.log('显示layer+++++++++++++')
  62. break;
  63. case 2:
  64. if (this.layer_status != 2) {
  65. this.node.children.forEach(element_node => {
  66. element_node.getComponent(ElementAction)?.set_layer_bg_or_orgin(true);
  67. });
  68. this.scheduleOnce(() => {
  69. this.node.active = true;
  70. }, 1);
  71. }
  72. break;
  73. }
  74. this.layer_status = args;
  75. }
  76. }