Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / Cursor.cs
@小李xl 小李xl on 3 Nov 2022 1 KB 像素化后解决ui问题
  1. using Godot;
  2.  
  3. /// <summary>
  4. /// 鼠标指针
  5. /// </summary>
  6. public class Cursor : Node2D
  7. {
  8. private Sprite lt;
  9. private Sprite lb;
  10. private Sprite rt;
  11. private Sprite rb;
  12.  
  13. public override void _Ready()
  14. {
  15. lt = GetNode<Sprite>("LT");
  16. lb = GetNode<Sprite>("LB");
  17. rt = GetNode<Sprite>("RT");
  18. rb = GetNode<Sprite>("RB");
  19. }
  20.  
  21. public override void _Process(float delta)
  22. {
  23. var targetGun = GameApplication.Instance.Room.Player?.Holster.ActiveWeapon;
  24. if (targetGun != null)
  25. {
  26. SetScope(targetGun.CurrScatteringRange, targetGun);
  27. }
  28. else
  29. {
  30. SetScope(0, targetGun);
  31. }
  32. SetCursorPos();
  33. }
  34.  
  35. public Vector2 GetPos()
  36. {
  37. return Vector2.Zero;
  38. }
  39.  
  40. /// <summary>
  41. /// 设置光标半径范围
  42. /// </summary>
  43. private void SetScope(float scope, Weapon targetGun)
  44. {
  45. if (targetGun != null)
  46. {
  47. var tunPos = GameApplication.Instance.ViewToGlobalPosition(targetGun.GlobalPosition);
  48. var len = GlobalPosition.DistanceTo(tunPos);
  49. if (targetGun.Attribute != null)
  50. {
  51. len = Mathf.Max(0, len - targetGun.Attribute.FirePosition.x);
  52. }
  53. scope = len / GameConfig.ScatteringDistance * scope;
  54. }
  55. lt.Position = new Vector2(-scope, -scope);
  56. lb.Position = new Vector2(-scope, scope);
  57. rt.Position = new Vector2(scope, -scope);
  58. rb.Position = new Vector2(scope, scope);
  59. }
  60.  
  61. private void SetCursorPos()
  62. {
  63. GlobalPosition = GetGlobalMousePosition();
  64. }
  65. }