CombatChipStore.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using GadgetCore.API;
  2. using System;
  3. using UnityEngine;
  4. namespace CombatChipChest
  5. {
  6. public class CombatChipStore
  7. {
  8. public CombatChipStore(int size, string id)
  9. {
  10. m_ChipIDs = new int[size];
  11. _id = id;
  12. }
  13. private string _id;
  14. private int[] m_ChipIDs;
  15. public int[] ChipIDs
  16. {
  17. get { return m_ChipIDs; }
  18. set { m_ChipIDs = value; }
  19. }
  20. public void Save()
  21. {
  22. for (int i = 0; i < m_ChipIDs.Length; i++)
  23. {
  24. PreviewLabs.PlayerPrefs.SetInt("customChipsStore:" + _id + ":" + i, m_ChipIDs[i]);
  25. }
  26. }
  27. public void Load()
  28. {
  29. for (int i = 0; i < m_ChipIDs.Length; i++)
  30. {
  31. m_ChipIDs[i] = PreviewLabs.PlayerPrefs.GetInt("customChipsStore:" + _id + ":" + i, 0);
  32. }
  33. }
  34. public void UpdateLatestUI()
  35. {
  36. UpdateUI(lastUsed);
  37. }
  38. private GameObject lastUsed;
  39. public void UpdateUI(GameObject menu)
  40. {
  41. lastUsed = menu;
  42. var gameScript = (GameScript)Camera.main.GetComponent("GameScript");
  43. try
  44. {
  45. for (int i = 0; i < menu.transform.childCount; i++)
  46. {
  47. var obj = menu.transform.GetChild(i).gameObject;
  48. int number;
  49. if (obj.name.Length > "combat_storage_slot".Length && int.TryParse(obj.name.Substring("combat_storage_slot".Length), out number))
  50. {
  51. obj.GetComponent<Renderer>().material = (Material)Resources.Load("cc/cc" + m_ChipIDs[number]);
  52. }
  53. }
  54. }
  55. catch (Exception e)
  56. {
  57. Core.logger.LogConsole(e.Message);
  58. }
  59. }
  60. public void UpdateText(int id)
  61. {
  62. if (lastUsed != null)
  63. {
  64. var txtChipName = lastUsed.transform.FindChild("txtTitle").gameObject.GetComponent<TextMesh>();
  65. txtChipName.text = GadgetCoreAPI.GetChipName(id);
  66. var txtDesc = lastUsed.transform.FindChild("txtDesc").gameObject.GetComponent<TextMesh>();
  67. txtDesc.text = GadgetCoreAPI.GetChipDesc(id);
  68. var gameScript = (GameScript)Camera.main.GetComponent("GameScript");
  69. var txtCost = lastUsed.transform.FindChild("txtCost").gameObject.GetComponent<TextMesh>();
  70. int chipCost = gameScript.GetChipCost(id);
  71. if (chipCost == -1 && txtChipName.text != string.Empty)
  72. txtCost.text = "Passive";
  73. else if (chipCost > 0)
  74. txtCost.text = chipCost + " Mana";
  75. else
  76. txtCost.text = string.Empty;
  77. }
  78. }
  79. }
  80. }