您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

78 行
1.9 KiB

  1. using System;
  2. using CIG;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISSEngine;
  7. using UnityEngine;
  8. [RequireComponent(typeof(GridTile), typeof(Serializing), typeof(Clickable))]
  9. public class DropChest : MonoBehaviour
  10. {
  11. private void Awake()
  12. {
  13. this._currencyAnimationSource.Init(this._animationSourceObject);
  14. }
  15. private void OnDestroy()
  16. {
  17. if (this._clickable != null)
  18. {
  19. this._clickable.OnClickEvent -= this.Collect;
  20. }
  21. }
  22. public void Collect(GameObject target)
  23. {
  24. if (this.CanCollect() && SingletonMonobehaviour<CIGGameState>.IsAvailable)
  25. {
  26. decimal num = UnityEngine.Random.Range(this._minGoldReward, this._maxGoldReward);
  27. SingletonMonobehaviour<CIGGameState>.Instance.EarnCurrencies(new Currencies("Gold", num), this._animationSourceObject);
  28. Pling pling = this._plingManager.Show(PlingType.Gold, Vector3.zero, Clip.Ping);
  29. pling.Show(Localization.Integer(num));
  30. if (this._clickable != null)
  31. {
  32. this._clickable.OnClickEvent -= this.Collect;
  33. }
  34. IsometricIsland.GetParent(this).builder.DestroyTile(this._tile);
  35. }
  36. }
  37. private bool CanCollect()
  38. {
  39. if (!this._tile.grid.IsWithinBounds(this._tile.index))
  40. {
  41. return true;
  42. }
  43. GridElement gridElement = this._tile.grid[this._tile.index.u, this._tile.index.v];
  44. return gridElement.Type == -1 || gridElement.Unlocked;
  45. }
  46. private void OnDeserialized()
  47. {
  48. this._clickable.OnClickEvent += this.Collect;
  49. }
  50. private const string GoldRewardKey = "chestGoldReward";
  51. [SerializeField]
  52. private Clickable _clickable;
  53. [SerializeField]
  54. private GridTile _tile;
  55. [SerializeField]
  56. private int _minGoldReward;
  57. [SerializeField]
  58. private int _maxGoldReward;
  59. [SerializeField]
  60. private PlingManager _plingManager;
  61. [SerializeField]
  62. private CurrencyAnimationSource _currencyAnimationSource;
  63. private object _animationSourceObject = new object();
  64. }