UINode.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 bool IsNewNode;
  23. public ActiveType activeType = ActiveType.Default;
  24. public bool GetValue(string key, out bool value)
  25. {
  26. value = false;
  27. for (int i = 0; i < keys.Count; i++)
  28. {
  29. if (keys[i] == key)
  30. {
  31. value = values[i];
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. public void SetValue(string key, bool value)
  38. {
  39. for (int i = 0; i < keys.Count; i++)
  40. {
  41. if (keys[i] == key)
  42. {
  43. values[i] = value;
  44. return;
  45. }
  46. }
  47. keys.Add(key);
  48. values.Add(value);
  49. }
  50. public void RemoveKeyValue(string key, bool value)
  51. {
  52. int removeindex = -1;
  53. for (int i = 0; i < keys.Count; ++i)
  54. {
  55. if (keys[i] == key)
  56. {
  57. removeindex = i;
  58. break;
  59. }
  60. }
  61. if (removeindex != -1)
  62. {
  63. keys.RemoveAt(removeindex);
  64. values.RemoveAt(removeindex);
  65. }
  66. }
  67. public bool HasType(Type type)
  68. {
  69. for (int i = 0; i < keys.Count; i++)
  70. {
  71. if (keys[i] == type.FullName)
  72. {
  73. return values[i];
  74. }
  75. }
  76. return false;
  77. }
  78. string trimName(string name)
  79. {
  80. string trim = name.Replace(" ", "");
  81. trim = trim.Replace("\r", "");
  82. trim = trim.Replace("\n", "");
  83. trim = trim.Replace("\t", "");
  84. return trim;
  85. }
  86. string getComponentArgNameWithName(string str)
  87. {
  88. return str.Substring(0, 1).ToLower() + str.Substring(1, str.Length - 1);
  89. }
  90. void PackageUINodeGOPath(ref string path)
  91. {
  92. if (UIName == string.Empty)
  93. {
  94. UIName = getComponentArgNameWithName(trimName(gameObject.name));
  95. }
  96. path = "." + path;
  97. path = UIName + path;
  98. if (depObjs.Length > 0)
  99. {
  100. UINode node1 = depObjs[0];
  101. if (node1 != null)
  102. node1.PackageUINodeGOPath(ref path);
  103. else
  104. path = path.Substring(0, path.Length - 1);
  105. }
  106. else
  107. {
  108. path = path.Substring(0, path.Length - 1);
  109. }
  110. }
  111. public void FindUINodeGOPath(ref string path)
  112. {
  113. PackageUINodeGOPath(ref path);
  114. }
  115. }