56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
| import { _decorator, Component, EventMouse, Node } from 'cc';
 | |
| const { ccclass, property } = _decorator;
 | |
| 
 | |
| @ccclass('BaseButtonAction')
 | |
| export class BaseButtonAction extends Component {
 | |
| 
 | |
|     onMouseUp?: Function;
 | |
|     onMouseLeftUp?: Function;
 | |
|     onMouseRightUp?: Function;
 | |
| 
 | |
|     onMouseDown?: Function;
 | |
|     onMouseLeftDown?: Function;
 | |
|     onMouseRightDown?: Function;
 | |
| 
 | |
|     start() {
 | |
|         this.node.on(Node.EventType.MOUSE_UP,this._onMouseUp,this);
 | |
|         this.node.on(Node.EventType.MOUSE_DOWN,this._onMouseDown,this);
 | |
|     }
 | |
| 
 | |
|     private _onMouseUp(event:EventMouse){
 | |
|         if (this.onMouseUp) this.onMouseUp();
 | |
| 
 | |
|         switch (event.getButton()) {
 | |
|             case EventMouse.BUTTON_LEFT:
 | |
|                 if (this.onMouseLeftUp) this.onMouseLeftUp();
 | |
|                 break;
 | |
|             case EventMouse.BUTTON_RIGHT:
 | |
|                 if (this.onMouseRightUp) this.onMouseRightUp();
 | |
|                 break;
 | |
|             default:
 | |
|                 break;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private _onMouseDown(event:EventMouse){
 | |
|         if (this.onMouseDown) this.onMouseDown();
 | |
| 
 | |
|         switch (event.getButton()) {
 | |
|             case EventMouse.BUTTON_LEFT:
 | |
|                 if (this.onMouseLeftDown) this.onMouseLeftDown();
 | |
|                 break;
 | |
|             case EventMouse.BUTTON_RIGHT:
 | |
|                 if (this.onMouseRightDown) this.onMouseRightDown();
 | |
|                 break;
 | |
|             default:
 | |
|                 break;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     update(deltaTime: number) {
 | |
|         
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 |