BucketAction.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { _decorator, Component, Node, tween, UITransform, Vec3 } from 'cc';
  2. import { PinAction } from './PinAction';
  3. import { AudioMgr } from './AudioMgr';
  4. import { Clips } from './Enums';
  5. import { Tools } from './Tools';
  6. import { Global } from './Global';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('BucketAction')
  9. export class BucketAction extends Component {
  10. @property({type:Node})
  11. container:Node
  12. start() {
  13. }
  14. update(deltaTime: number) {
  15. }
  16. clear_container(){
  17. this.container.removeAllChildren();
  18. }
  19. /**
  20. *
  21. * @param pin
  22. */
  23. public put_pins(pin: PinAction[]) {
  24. pin.forEach(element => {
  25. this.put_pin(element);
  26. });
  27. }
  28. /**
  29. *
  30. * @param pin
  31. */
  32. public put_pin(pin: PinAction) {
  33. let target_hole_pos = new Vec3(Tools.random_between(-20,20),Tools.random_between(-30,30),1);
  34. //
  35. let world_pos = pin.node.getWorldPosition();
  36. let target = this.container.getComponent(UITransform).convertToNodeSpaceAR(world_pos);
  37. this.container.addChild(pin.node);
  38. pin.node.setPosition(target);
  39. pin.remove_collider();
  40. tween(pin.node)
  41. .to(0.25, { position: target_hole_pos },Global.our_easing)
  42. .call(() => {
  43. AudioMgr.ins.playSound(Clips.close_screw);
  44. })
  45. .start();
  46. }
  47. /**
  48. *
  49. * @param color_id
  50. * @param pin_arr
  51. */
  52. public get_pin_arr_by_color_id(color_id:number,pin_arr:PinAction[]){
  53. this.container.children.forEach(element => {
  54. if (element.getComponent(PinAction)) {
  55. let pin_action = element.getComponent(PinAction);
  56. if(pin_action.pin_color&&pin_action.pin_color.id == color_id){
  57. pin_arr.push(pin_action);
  58. }
  59. }
  60. });
  61. }
  62. /**
  63. *
  64. * @param pin_arr
  65. */
  66. public get_pin_arr(pin_arr:PinAction[]){
  67. this.container.children.forEach(element => {
  68. if (element.getComponent(PinAction)) {
  69. let pin_action = element.getComponent(PinAction);
  70. if(pin_action.pin_color){
  71. pin_arr.push(pin_action);
  72. }
  73. }
  74. });
  75. }
  76. }