CraftingProgress.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace SoftKitty.InventoryEngine
  6. {
  7. public class CraftingProgress : MonoBehaviour
  8. {
  9. [Header("Assign the InventoryHolder")]
  10. public InventoryHolder Holder;
  11. #region Variables
  12. [Header("References")]
  13. public RectTransform Progress;
  14. public Text NumberText;
  15. public ItemIcon ResultItem;
  16. public Animation ResultPop;
  17. public CanvasGroup Root;
  18. private float FadeTime = 0F;
  19. #endregion
  20. #region Internal Method
  21. void Update()
  22. {
  23. if (Holder.isCrafting())
  24. {
  25. if (FadeTime < 1F)
  26. {
  27. FadeTime = 1F;
  28. Root.alpha = FadeTime;
  29. Root.gameObject.SetActive(true);
  30. ResultItem.SetAppearance(ItemManager.itemDic[Holder.GetCraftingItemId()], true, false);
  31. ResultItem.SetItemId(Holder.GetCraftingItemId());
  32. }
  33. Progress.localScale = new Vector3(Holder.GetCraftingProgress(),1F,1F);
  34. if (Holder.GetCraftingProgress() >= 1F)
  35. {
  36. if (Holder.GetCraftingFailed())
  37. {
  38. NumberText.text = "Failed!";
  39. }
  40. else
  41. {
  42. ResultPop.Stop();
  43. ResultPop.Play();
  44. }
  45. }
  46. else
  47. {
  48. NumberText.text = Holder.GetCraftedItemNumber().ToString() + "/" + Holder.GetCraftingItemNumber().ToString();
  49. }
  50. }
  51. else
  52. {
  53. FadeTime = Mathf.MoveTowards(FadeTime,0F,Time.deltaTime);
  54. if (FadeTime > 0F)
  55. {
  56. NumberText.text = "Done!";
  57. Root.alpha = FadeTime;
  58. }
  59. else if (Root.gameObject.activeSelf)
  60. {
  61. Root.gameObject.SetActive(false);
  62. }
  63. }
  64. }
  65. #endregion
  66. }
  67. }