slide.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { _decorator, Component, Node, Size, UITransform } from 'cc';
  2. import { config } from '../config';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('slide')
  5. export class slide extends Component {
  6. @property(Node) left:Node = null;
  7. @property(Node) right:Node = null;
  8. @property(Node) up:Node = null;
  9. @property(Node) down:Node = null;
  10. public updateDistance(dir:number,distance:number){
  11. if(dir===config.slide_type.down||dir===config.slide_type.up||dir===config.slide_type.up_down){
  12. this.node.getComponent(UITransform).contentSize = new Size( this.node.getComponent(UITransform).contentSize.width, distance)
  13. }else{
  14. this.node.getComponent(UITransform).contentSize = new Size( distance, this.node.getComponent(UITransform).contentSize.height)
  15. }
  16. this.updateDir(dir)
  17. }
  18. public updateDir(dir:number){
  19. this.left.active = false;
  20. this.right.active = false;
  21. this.up.active = false;
  22. this.down.active = false;
  23. switch(dir){
  24. case config.slide_type.down:
  25. this.down.active = true;
  26. break;
  27. case config.slide_type.up:
  28. this.up.active = true;
  29. break;
  30. case config.slide_type.left:
  31. this.left.active = true;
  32. break;
  33. case config.slide_type.right:
  34. this.right.active = true;
  35. break;
  36. case config.slide_type.up_down:
  37. this.down.active = true;
  38. this.up.active = true;
  39. break;
  40. case config.slide_type.left_right:
  41. this.left.active = true;
  42. this.right.active = true;
  43. break;
  44. }
  45. }
  46. }