Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / common / AutoFreezeObject.cs
  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. /// <summary>
  22. /// 冻结次数
  23. /// </summary>
  24. public int FreezeCount { get; private set; }
  25. private bool _playFlag = false;
  26. private float _grey = 0;
  27.  
  28. /// <summary>
  29. /// 冻结时调用
  30. /// </summary>
  31. protected virtual void OnFreeze()
  32. {
  33. }
  34. public override void OnInit()
  35. {
  36. if (!string.IsNullOrEmpty(AnimationName))
  37. {
  38. _playFlag = true;
  39. AnimatedSprite.AnimationFinished += OnAnimationFinished;
  40. AnimatedSprite.Play(AnimationName);
  41. }
  42. }
  43.  
  44. protected override void Process(float delta)
  45. {
  46. //落地静止后将弹壳变为静态贴图
  47. if (!_playFlag &&!IsThrowing && Altitude <= 0 && MoveController.IsMotionless())
  48. {
  49. if (AutoToGrey && _grey < 1)
  50. {
  51. //变灰动画时间, 0.5秒
  52. _grey = Mathf.Min(1, _grey + delta / 0.5f);
  53. Grey = _grey;
  54. return;
  55. }
  56. if (AffiliationArea != null)
  57. {
  58. OnFreeze();
  59. Freeze();
  60. FreezeCount++;
  61. }
  62. else
  63. {
  64. Debug.Log(Name + "投抛到画布外了, 强制消除...");
  65. Destroy();
  66. }
  67. }
  68. }
  69.  
  70. private void OnAnimationFinished()
  71. {
  72. _playFlag = false;
  73. }
  74. }