UINode.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. public enum ActiveType
  7. {
  8. Default,
  9. Active,
  10. Inactive,
  11. }
  12. public class UINode : MonoBehaviour
  13. {
  14. public string UIName;
  15. [HideInInspector]
  16. //[SerializeField]
  17. public List<string> keys;
  18. [HideInInspector]
  19. //[SerializeField]
  20. public List<bool> values;
  21. public UINode[] depObjs;
  22. public ActiveType activeType = ActiveType.Default;
  23. public bool GetValue(string key, out bool value)
  24. {
  25. value = false;
  26. for (int i = 0; i < keys.Count; i++)
  27. {
  28. if (keys[i] == key)
  29. {
  30. value = values[i];
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. public void SetValue(string key, bool value)
  37. {
  38. for (int i = 0; i < keys.Count; i++)
  39. {
  40. if (keys[i] == key)
  41. {
  42. values[i] = value;
  43. return;
  44. }
  45. }
  46. keys.Add(key);
  47. values.Add(value);
  48. }
  49. public void RemoveKeyValue(string key, bool value)
  50. {
  51. int removeindex = -1;
  52. for (int i = 0; i < keys.Count; ++i)
  53. {
  54. if (keys[i] == key)
  55. {
  56. removeindex = i;
  57. break;
  58. }
  59. }
  60. if (removeindex != -1)
  61. {
  62. keys.RemoveAt(removeindex);
  63. values.RemoveAt(removeindex);
  64. }
  65. }
  66. public bool HasType(Type type)
  67. {
  68. for (int i = 0; i < keys.Count; i++)
  69. {
  70. if (keys[i] == type.FullName)
  71. {
  72. return values[i];
  73. }
  74. }
  75. return false;
  76. }
  77. string trimName(string name)
  78. {
  79. string trim = name.Replace(" ", "");
  80. trim = trim.Replace("\r", "");
  81. trim = trim.Replace("\n", "");
  82. trim = trim.Replace("\t", "");
  83. return trim;
  84. }
  85. string getComponentArgNameWithName(string str)
  86. {
  87. return str.Substring(0, 1).ToLower() + str.Substring(1, str.Length - 1);
  88. }
  89. void PackageUINodeGOPath(ref string path)
  90. {
  91. if (UIName == string.Empty)
  92. {
  93. UIName = getComponentArgNameWithName(trimName(gameObject.name));
  94. }
  95. path = "." + path;
  96. path = UIName + path;
  97. if (depObjs.Length > 0)
  98. {
  99. UINode node1 = depObjs[0];
  100. if (node1 != null)
  101. node1.PackageUINodeGOPath(ref path);
  102. else
  103. path = path.Substring(0, path.Length - 1);
  104. }
  105. else
  106. {
  107. path = path.Substring(0, path.Length - 1);
  108. }
  109. }
  110. public void FindUINodeGOPath(ref string path)
  111. {
  112. PackageUINodeGOPath(ref path);
  113. }
  114. }