using System; using System.Collections.Generic; using UnityEngine; public class UIWindowProperty : MonoBehaviour { [System.Serializable] public struct NodeElement { public string Key; public GameObject Object; } [System.Serializable] public struct NodeElement2 { public string Key; public List ObjectList; } // public enum AutoBindType // { // GameObject = 0, // Transform = 1, // Btn = 2, // Image = 3 // } [System.Serializable] public struct NodeElementAuto { public string Key; public GameObject Object; public UIAutoBindRuleHelper.AutoBindType type; } [System.Serializable] public struct ValueElement { public string Key; public float Value; } public List GameObjectList = new List(); public List GameObjectList2 = new List(); public List AutoGameObjectList = new List(); // public List ValueList = new List(); // public string ClassName; public float GetValue(string key, float defaultValue) { for (int iter = 0; iter < ValueList.Count; ++iter) { ValueElement iterElement = ValueList[iter]; if (string.Compare(iterElement.Key, key, true) == 0) { return iterElement.Value; } } // return defaultValue; } //+++++++++++++++++++++++++++++++++++++++++++++++++++ public GameObject GetGameObject(string key) { return GetGameObject(key, true); } public GameObject GetGameObject(string key, bool logMessage) { for (int iter = 0; iter < GameObjectList.Count; ++iter) { NodeElementAuto iterElement = GameObjectList[iter]; if (string.Compare(iterElement.Key, key, true) == 0) { return iterElement.Object; } } for (int iter = 0; iter < AutoGameObjectList.Count; ++iter) { NodeElementAuto iterElement = AutoGameObjectList[iter]; if (string.Compare(iterElement.Key, key, true) == 0) { return iterElement.Object; } } if (logMessage) { ViDebuger.Error("WindowProperty[" + name + "].GameObject[" + key + "] not exist!"); } return null; } public T GetComponent(string key) where T : Component { return GetComponent(key, true); } public T GetComponent(string key, bool logMessage) where T : Component { GameObject obj = GetGameObject(key, logMessage); if (obj != null) { T component = obj.GetComponent(); if (System.Object.ReferenceEquals(component, null)) { ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!"); } return component; } else { return null; } } public T GetComponentInChildren(string key) where T : Component { GameObject obj = GetGameObject(key); if (obj != null) { T component = obj.GetComponentInChildren(); if (System.Object.ReferenceEquals(component, null)) { ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!"); } return component; } else { return null; } } public T GetComponentInChildren(string key, bool includeInactive) where T : Component { GameObject obj = GetGameObject(key); if (obj != null) { T component = obj.GetComponentInChildren(includeInactive); if (System.Object.ReferenceEquals(component, null)) { ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!"); } return component; } else { return null; } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public List GetGameObjectList(string key) { for (int iter = 0; iter < GameObjectList2.Count; ++iter) { NodeElement2 iterElement = GameObjectList2[iter]; if (string.Compare(iterElement.Key, key, true) == 0) { return iterElement.ObjectList; } } ViDebuger.Error("WindowProperty[" + name + "].GameObjectList[" + key + "] not exist!"); return null; } public void GetComponentList(string key, List resultList) where T : Component { List objList = GetGameObjectList(key); if (objList != null) { for (int iter = 0; iter < objList.Count; ++iter) { GameObject iterObj = objList[iter]; if (iterObj != null) { T component = iterObj.GetComponent(); if (System.Object.ReferenceEquals(component, null)) { ViDebuger.Error("WindowProperty[" + name + "].GameObject[" + iterObj.name + "]." + typeof(T).Name + "[" + key + "] not exist!"); } resultList.Add(component); } } } } }