Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / common / AutoFreezeObject.cs
@小李xl 小李xl on 21 Nov 2023 1 KB 第二种敌人死亡动画
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 停止移动后自动冻结对象
  6. /// </summary>
  7. [Tool]
  8. public partial class AutoFreezeObject : ActivityObject
  9. {
  10. /// <summary>
  11. /// 自动播放的动画, 物体会等待该动画播完完成后进入冻结状态, 该动画不能是循环动画
  12. /// </summary>
  13. [Export]
  14. public string AnimationName { get; set; }
  15. /// <summary>
  16. /// 在冻结前是否变灰
  17. /// </summary>
  18. [Export]
  19. public bool AutoToGrey { get; set; }
  20.  
  21. private bool _playFlag = false;
  22. private float _grey = 0;
  23.  
  24. public override void OnInit()
  25. {
  26. if (!string.IsNullOrEmpty(AnimationName))
  27. {
  28. _playFlag = true;
  29. AnimatedSprite.AnimationFinished += OnAnimationFinished;
  30. AnimatedSprite.Play(AnimationName);
  31. }
  32. }
  33.  
  34. protected override void Process(float delta)
  35. {
  36. //落地静止后将弹壳变为静态贴图
  37. if (!_playFlag &&!IsThrowing && Altitude <= 0 && MoveController.IsMotionless())
  38. {
  39. if (AutoToGrey && _grey < 1)
  40. {
  41. //变灰动画时间, 0.5秒
  42. _grey = Mathf.Min(1, _grey + delta / 0.5f);
  43. Grey = _grey;
  44. return;
  45. }
  46. if (AffiliationArea != null)
  47. {
  48. Freeze();
  49. }
  50. else
  51. {
  52. Debug.Log(Name + "投抛到画布外了, 强制消除...");
  53. Destroy();
  54. }
  55. }
  56. }
  57.  
  58. private void OnAnimationFinished()
  59. {
  60. _playFlag = false;
  61. }
  62. }