LayerAction.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, Node, Rect, tween, UIOpacity, UITransform, Vec2 } from 'cc';
  2. import { PinAction } from './PinAction';
  3. import { ElementAction } from './ElementAction';
  4. import { ColorDate } from './ColorDate';
  5. import { Global } from './Global';
  6. import { DataModel } from './DataModel';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('LayerAction')
  9. export class LayerAction extends Component {
  10. layer_group_id = 0;
  11. layer_color:ColorDate = null;
  12. start() {
  13. console.log("zh:layerAction.ts start");
  14. }
  15. update(deltaTime: number) {
  16. }
  17. public get_hole_num():number{
  18. let hole_num:number = 0;
  19. this.node.children.forEach(element_node => {
  20. hole_num+= element_node.getComponent(ElementAction).get_hole_num();
  21. });
  22. return hole_num;
  23. }
  24. public init_layer(){
  25. this.layer_group_id = DataModel.get_new_group_index();
  26. this.layer_color = DataModel.get_layer_color();
  27. this.node.children.forEach(element_node => {
  28. element_node.getComponent(ElementAction).init_element(this.layer_group_id,this.layer_color);
  29. });
  30. }
  31. public init_pin(color_pin_arr:ColorDate[]){
  32. this.node.children.forEach(element_node => {
  33. element_node.getComponent(ElementAction).init_pin(this.layer_group_id,color_pin_arr);
  34. });
  35. }
  36. get_pin_color(arr:PinAction[]){
  37. this.node.children.forEach(element_node => {
  38. element_node.getComponent(ElementAction)?.get_pin_color(arr);
  39. });
  40. }
  41. public get_element_size():number{
  42. return this.node.children.length;
  43. }
  44. public layer_active(active:boolean,t:number=0.3){
  45. let need_show = !this.node.active;
  46. this.node.active = active;
  47. // this.node.opa
  48. let opc_1 = 100;
  49. let opc_2 = 200;
  50. if(need_show&&active&&this.node.getComponent(UIOpacity)){
  51. this.node.getComponent(UIOpacity).opacity = 0;
  52. tween(this.node.getComponent(UIOpacity))
  53. .to(t, { opacity: opc_1 },Global.our_easing)
  54. .to(t, { opacity: opc_2 },Global.our_easing)
  55. .to(t, { opacity: opc_1 },Global.our_easing)
  56. .to(t, { opacity: opc_2 },Global.our_easing)
  57. .to(t, { opacity: opc_1 },Global.our_easing)
  58. .to(t, { opacity: opc_2 },Global.our_easing)
  59. .to(t, { opacity: opc_1 },Global.our_easing)
  60. .to(t, { opacity: 255 },Global.our_easing)
  61. .call(()=>{
  62. this.node.getComponent(UIOpacity).opacity = 255;
  63. })
  64. .start();
  65. }
  66. }
  67. }