Newer
Older
DungeonShooting / DungeonShooting_Godot / src / common / NodeExtend.cs
@小李xl 小李xl on 4 Aug 2022 1 KB 拾取同类型枪支的子弹
  1. using Godot;
  2. using System;
  3.  
  4. public static class NodeExtend
  5. {
  6.  
  7. public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate)
  8. {
  9. return StartThrow<ThrowNode>(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate);
  10. }
  11.  
  12. public static T StartThrow<T>(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate) where T : ThrowNode
  13. {
  14. StartThrow<T>(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, null);
  15. T inst = Activator.CreateInstance<T>();
  16. inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node);
  17. return inst;
  18. }
  19.  
  20. public static ThrowNode StartThrow(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget)
  21. {
  22. return StartThrow<ThrowNode>(node, size, start, startHeight, direction, xSpeed, ySpeed, rotate, shadowTarget);
  23. }
  24.  
  25. public static T StartThrow<T>(this Node2D node, Vector2 size, Vector2 start, float startHeight, float direction, float xSpeed, float ySpeed, float rotate, Sprite shadowTarget) where T : ThrowNode
  26. {
  27. T inst = Activator.CreateInstance<T>();
  28. inst.StartThrow(size, start, startHeight, direction, xSpeed, ySpeed, rotate, node, shadowTarget);
  29. return inst;
  30. }
  31.  
  32. public static ThrowNode PutDown(this Node2D node, Sprite shadowTarget)
  33. {
  34. return StartThrow(node, Vector2.Zero, node.Position, 0, 0, 0, 0, 0, shadowTarget);
  35. }
  36.  
  37. public static bool Pickup(this Node2D node)
  38. {
  39. ThrowNode parent = node.GetParentOrNull<ThrowNode>();
  40. if (parent != null) {
  41. parent.StopThrow();
  42. return true;
  43. }
  44. return false;
  45. }
  46. }