TileRaycastReceiver.re.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as RE from 'rogue-engine';
  2. import RaycastReceiver from './RaycastReceiver.re';
  3. import * as THREE from 'three'
  4. export default class TileRaycastReceiver extends RaycastReceiver {
  5. @RE.props.vector2() tileSize = new THREE.Vector2(1.0, 1.0)
  6. isHovered = false
  7. onMouseOver(intersect) {
  8. this.isHovered = true
  9. RE.Runtime.rogueDOMContainer.style.cursor = "pointer"
  10. }
  11. onMouseOut(){
  12. if(this.isHovered) {
  13. this.isHovered = false
  14. RE.Runtime.rogueDOMContainer.style.cursor = "default"
  15. }
  16. }
  17. getPosition() {
  18. return this.object3d.position
  19. }
  20. awake() {
  21. }
  22. start() {
  23. }
  24. update() {
  25. if(!this.isHovered) {
  26. return
  27. }
  28. if(RE.Input.mouse.getButtonDown(0) || RE.Input.touch.touches.length == 1) {
  29. let target = RE.App.currentScene.getObjectByName("CameraTarget")
  30. if(!target) {
  31. RE.Debug.logWarning("didn't find CameraTarget Object3D")
  32. return
  33. }
  34. target.position.set(this.object3d.position.x, this.object3d.position.y, this.object3d.position.z)
  35. }
  36. }
  37. }
  38. RE.registerComponent(TileRaycastReceiver);