EasyController.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, director } from 'cc';
  2. export class EasyControllerEvent{
  3. /**
  4. * Dispatched when camera rotating
  5. * @params rx: horizontal rotation
  6. * @params ry: vertical rotation.
  7. */
  8. public static CAMERA_ROTATE:string = 'EasyControllerEvent.CAMERA_ROTATE';
  9. /**
  10. * Dispatched when camera zooming
  11. * @params delta: amount of camera zoom
  12. */
  13. public static CAMERA_ZOOM:string = 'EasyControllerEvent.CAMERA_ZOOM';
  14. /**
  15. * Dispatched when the movement controller is moving
  16. * @param degree: direction in degrees, with positive X-axis as 0, increasing in a counter-clockwise direction.
  17. * @param strength: movement strength, [0.0, 1.0], can be used for fine-tuning the movement speed.
  18. */
  19. public static MOVEMENT:string = 'EasyControllerEvent.MOVEMENT';
  20. /**
  21. * Dispatched when the movement controller stops moving
  22. */
  23. public static MOVEMENT_STOP:string = 'EasyControllerEvent.MOVEMENT_STOP';
  24. /**
  25. * Dispatched when one of the buttons is pressed.
  26. * @param buttonName: string, indicates which button is pressed.
  27. */
  28. public static BUTTON:string = 'EasyControllerEvent.BUTTON';
  29. }
  30. export class EasyController{
  31. public static on(type:string,callback:Function,target?:any){
  32. director.getScene().on(type,callback,target);
  33. }
  34. public static off(type:string,callback?:Function,target?:any){
  35. director.getScene()?.off(type,callback,target);
  36. }
  37. }