Adjust_values.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using static UnityEditor.Progress;
  6. public class Adjust_values : MonoBehaviour
  7. {
  8. public List<Button> JiabtnList = new List<Button>();
  9. public List<Button> JianbtnList = new List<Button>();
  10. public List<Text> valueTextList = new List<Text>();
  11. public List<int> values = new List<int>();
  12. public Text valueText;
  13. public Button randomBtn;
  14. public Button startNewLifeBtn;
  15. void Start()
  16. {
  17. for (int j = 0; j < 4; j++)
  18. {
  19. values.Add(0);
  20. }
  21. foreach (var item in valueTextList)
  22. {
  23. item.text = 0.ToString();
  24. }
  25. for (int i = 0; i < JiabtnList.Count; i++)
  26. {
  27. int index = i;
  28. JiabtnList[i].onClick.AddListener(() =>
  29. {
  30. int sum = 0;
  31. for (int j = 0; j < values.Count; j++)
  32. {
  33. sum += values[j];
  34. }
  35. if (sum < 20)
  36. {
  37. values[index]++;
  38. valueTextList[index].text = values[index].ToString();
  39. }
  40. int tempSum = 0;
  41. for (int j = 0; j < values.Count; j++)
  42. {
  43. tempSum += values[j];
  44. }
  45. valueText.text = (20 - tempSum).ToString();
  46. });
  47. }
  48. for (int i = 0; i < JianbtnList.Count; i++)
  49. {
  50. int index = i;
  51. JianbtnList[i].onClick.AddListener(() =>
  52. {
  53. if (values[index] > 0)
  54. {
  55. values[index]--;
  56. valueTextList[index].text = values[index].ToString();
  57. }
  58. int sum = 0;
  59. foreach (var item in values)
  60. {
  61. sum += item;
  62. }
  63. valueText.text = (20 - sum).ToString();
  64. });
  65. }
  66. randomBtn.onClick.AddListener(() =>
  67. {
  68. for (int i = 0; i < 4; i++)
  69. {
  70. values[i] = 0;
  71. }
  72. for (int i = 0; i < 20; i++)
  73. {
  74. int index = Random.Range(0, values.Count);
  75. values[index]++;
  76. valueTextList[index].text = values[index].ToString();
  77. }
  78. valueText.text = 0.ToString();
  79. });
  80. startNewLifeBtn.onClick.AddListener(() =>
  81. {
  82. int sum = 0;
  83. for (int j = 0; j < values.Count; j++)
  84. {
  85. sum += values[j];
  86. }
  87. if (sum != 20)
  88. {
  89. Debug.Log("请分配属性到20点");
  90. }
  91. else
  92. {
  93. PlayerData.intance.CHR = values[0];
  94. PlayerData.intance.INT = values[1];
  95. PlayerData.intance.STR = values[2];
  96. PlayerData.intance.MNY = values[3];
  97. Debug.Log("祝你生活愉快");
  98. }
  99. });
  100. }
  101. void Update()
  102. {
  103. }
  104. }