BucketAction.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. public put_pins(pin: PinAction[]) {
  20. pin.forEach(element => {
  21. this.put_pin(element);
  22. });
  23. }
  24. public put_pin(pin: PinAction) {
  25. let target_hole_pos = new Vec3(Tools.random_between(-20,20),Tools.random_between(-30,30),1);
  26. //
  27. let world_pos = pin.node.getWorldPosition();
  28. let target = this.container.getComponent(UITransform).convertToNodeSpaceAR(world_pos);
  29. this.container.addChild(pin.node);
  30. pin.node.setPosition(target);
  31. pin.remove_collider();
  32. tween(pin.node)
  33. .to(0.25, { position: target_hole_pos },Global.our_easing)
  34. .call(() => {
  35. AudioMgr.ins.playSound(Clips.close_screw);
  36. })
  37. .start();
  38. }
  39. public get_pin_arr_by_color_id(color_id:number,pin_arr:PinAction[]){
  40. this.container.children.forEach(element => {
  41. if (element.getComponent(PinAction)) {
  42. let pin_action = element.getComponent(PinAction);
  43. if(pin_action.pin_color&&pin_action.pin_color.id == color_id){
  44. pin_arr.push(pin_action);
  45. }
  46. }
  47. });
  48. }
  49. public get_pin_arr(pin_arr:PinAction[]){
  50. this.container.children.forEach(element => {
  51. if (element.getComponent(PinAction)) {
  52. let pin_action = element.getComponent(PinAction);
  53. if(pin_action.pin_color){
  54. pin_arr.push(pin_action);
  55. }
  56. }
  57. });
  58. }
  59. }