public void CheckError() { var selectedTransform = Selection.activeTransform; if (selectedTransform == null) { Debug.LogError("No transform is selected"); return; } else { var transformPath = GetGameObjectPath(selectedTransform); Debug.LogFormat("Check DataBinding for {0}", transformPath); } // get all binders var binderList = selectedTransform.GetComponentsInChildren <MonoBehaviour>(true).Where(x => x.GetType().IsBinder()); var usedList = new List <IDataContext>(); // iterate binder list foreach (var item in binderList) { // get data context var dc = BindingUtility.FindDataContext(item.transform); if (dc == null) { continue; } if (!usedList.Contains(dc)) { usedList.Add(dc); } } // get all data context var dataContextList = selectedTransform.GetComponentsInChildren <IDataContext>(true); foreach (var item in dataContextList) { if (!usedList.Contains(item)) { var go = item as MonoBehaviour; string path = GetGameObjectPath(go.transform); string info = string.Format("Find unused DataContext, path={0}", path); Debug.LogWarning(info, go); } } }
private void SetDataContextInfo(Transform root, TreeNode treeNode) { if (!enableExtraInfo) { return; } // get all binders var binderList = root.GetComponentsInChildren <MonoBehaviour>(true).Where(x => x.GetType().IsBinder()); var dictionary = new Dictionary <IDataContext, List <string> >(); // iterate binder list foreach (var item in binderList) { // get data context var dc = BindingUtility.FindDataContext(item.transform); if (dc == null) { continue; } if (!dictionary.ContainsKey(dc)) { // add new entry dictionary.Add(dc, new List <string>()); } var list = dictionary[dc]; var sourceList = GetBindingSourceList(item); foreach (var source in sourceList) { if (list.Contains(source)) { continue; } list.Add(source); } } // get all data context node var nodeList = new List <NodeGUI>(); GetNodeList(treeNode, NodeType.DataContext, nodeList); foreach (var item in nodeList) { var dc = item.target as IDataContext; if (!dictionary.ContainsKey(dc)) { string path = GetGameObjectPath(item.target.transform); string info = string.Format("Find unused DataContext, path={0}", path); Debug.LogWarning(info, item.target); continue; } var sourceList = dictionary[dc]; // set extra info var sourceInfo = CollectSourceInfo(sourceList); item.ExtraInfo = sourceInfo; } }