• cocos鼠标选装


    1. import { _decorator, Component, Node, input, Input, EventMouse, Vec3, v2, Camera, } from 'cc';
    2. const { ccclass, property } = _decorator;
    3. @ccclass('NewComponent')
    4. export class NewComponent extends Component {
    5. private _currotate = new Vec3();
    6. private _speed: number = 0;
    7. private IsMouseDown: boolean = false;
    8. @property(Node)
    9. private headNode: Node = null!;
    10. start() {
    11. input.on(Input.EventType.MOUSE_DOWN, this.MouseDown, this);
    12. input.on(Input.EventType.MOUSE_UP, this.MouseUp, this);
    13. input.on(Input.EventType.MOUSE_WHEEL, this.MouseWheel, this);
    14. input.on(Input.EventType.MOUSE_MOVE, this.OnMove, this);
    15. }
    16. MouseDown(event:EventMouse) {
    17. this.IsMouseDown = true;
    18. }
    19. MouseUp(event: EventMouse) {
    20. this.IsMouseDown = false;
    21. }
    22. MouseWheel(event: EventMouse) {
    23. //console.log(event.getScrollX);
    24. //console.log(event.getScrollY);
    25. //console.log(event.setScrollData);
    26. let length: number = event.getScrollY();
    27. let distance: Number = 1;
    28. console.log(length);
    29. if (length > 0) {
    30. let abc = new Vec3();
    31. abc = this.headNode.getPosition();
    32. this.headNode.setPosition(abc.x, abc.y, abc.z - 1);
    33. //console.log(this.headNode.position);
    34. }
    35. if (length < 0) {
    36. let abc = new Vec3();
    37. abc = this.headNode.getPosition();
    38. this.headNode.setPosition(abc.x, abc.y, abc.z + 1);
    39. }
    40. //this.headNode.getComponent<Camera>()
    41. }
    42. OnMove(event: EventMouse) {
    43. if (!this.IsMouseDown) return;
    44. let angle_speed = 2;
    45. let delat = event.getDelta();
    46. //console.log(delat);
    47. if (event.getButton() == 1) {
    48. let campos = new Vec3();
    49. campos = this.headNode.getPosition();
    50. if (delat.x > 0) {
    51. console.log(this.headNode.position);
    52. let camposx: number = campos.x - delat.x * 0.01;
    53. this.headNode.position = new Vec3(camposx, campos.y, campos.z);
    54. }
    55. else if (delat.x < 0) {
    56. let camposx: number = campos.x - delat.x * 0.01;
    57. this.headNode.position = new Vec3(camposx, campos.y, campos.z);
    58. }
    59. else if (delat.y<0) {
    60. let camposy: number = campos.y - delat.y * 0.01;
    61. this.headNode.position = new Vec3(campos.x, camposy, campos.z);
    62. }
    63. else if (delat.y > 0) {
    64. let camposy: number = campos.y - delat.y * 0.01;
    65. this.headNode.position = new Vec3(campos.x, camposy, campos.z);
    66. }
    67. }
    68. if (event.getButton() == 0) {
    69. if (delat.x < 0) {
    70. let angle = this.node.eulerAngles;
    71. let angleY = angle.y + angle_speed;
    72. this.node.eulerAngles = new Vec3(angle.x, angleY, angle.z);
    73. } else if (delat.x > 0) {
    74. let angle = this.node.eulerAngles;
    75. let angleY = angle.y - angle_speed;
    76. this.node.eulerAngles = new Vec3(angle.x, angleY, angle.z);
    77. } else if (delat.y > 0) {
    78. let angle = this.node.eulerAngles;
    79. let angleX = angle.x + angle_speed;
    80. this.node.eulerAngles = new Vec3(angleX, angle.y, angle.z);
    81. } else if (delat.y < 0) {
    82. let angle = this.node.eulerAngles;
    83. let angleX = angle.x - angle_speed;
    84. this.node.eulerAngles = new Vec3(angleX, angle.y, angle.z);
    85. }
    86. }
    87. }
    88. }

  • 相关阅读:
    前端经典面试题 | 闭包的作用和原理
    探讨C#、C++和Java这三门语言在嵌入式的地位
    pycharm简易使用码云gitee
    Spring源码分析(二):底层架构核心概念解析
    Qt实战 数据统计柱状图显示
    深入实践 Spring Boot PDF 百度云盘下载
    基于Android的校园社团管理
    CMake日志与变量操作
    OMS1664_ OMS1654_ OMS1644_ OMS1634_马可尼 2.5G-10Gb/s
    can通信注意事项
  • 原文地址:https://blog.csdn.net/weixin_46430763/article/details/134422748