public bool TryGetValue(string uid, out ViewComData comData)
 {
     foreach (var viewComData in components)
     {
         if (viewComData.uid == uid)
         {
             comData = viewComData;
             return(true);
         }
     }
     comData = null;
     return(false);
 }
    private void DrawExportListView()
    {
        EditorUIDrawer.DrawHeader("ExportList");
        GUILayout.BeginHorizontal();
        GUILayout.Space(3f);
        GUILayout.BeginVertical();
        exportViewPos = EditorGUILayout.BeginScrollView(exportViewPos);
        if (_viewRefData != null)
        {
            int removeIndex = -1;
            for (var index = 0; index < _viewRefData.components.Count; index++)
            {
                var comInfo = _viewRefData.components[index];
                GUILayout.Space(-1f);
                bool      highlight = _curComInfo == comInfo;
                Transform node      = _prefabRoot.Find(comInfo.path);
                if (node == null || (comInfo.comType != "GameObject" && node.GetComponent(comInfo.comType) == null))
                {
                    GUI.backgroundColor = Color.red;
                }
                else
                {
                    GUI.backgroundColor = highlight ? Color.white : new Color(0.8f, 0.8f, 0.8f);
                }

                GUILayout.BeginHorizontal("TextArea", GUILayout.MinHeight(20f));

                GUI.backgroundColor = Color.white;
                GUILayout.Label(index.ToString(), GUILayout.Width(20f));

                if (GUILayout.Button(comInfo.GetName(), "Label", GUILayout.Height(20f)))
                {
                    _curComInfo = comInfo;
                    Selection.activeTransform = _prefabRoot.Find(_curComInfo.path);
                }

                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    removeIndex = index;
                }

                GUILayout.EndHorizontal();
            }

            if (removeIndex != -1)
            {
                _viewRefData.components.RemoveAt(removeIndex);
            }
        }
        EditorGUILayout.EndScrollView();
        GUILayout.EndVertical();
        GUILayout.Space(3f);
        GUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("SaveViewConfig", GUILayout.Width(120f), GUILayout.Height(40f)))
        {
            SaveViewConfig(_viewRefData);
        }

        if (GUILayout.Button("GenerateViewCode", GUILayout.Width(120f), GUILayout.Height(40f)))
        {
            GenerateViewCode();
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(10f);
    }
    private void DrawSelectionComponentView()
    {
        EditorGUILayout.BeginVertical(GUILayout.MinWidth(150f));
        if (EditorUIDrawer.DrawHeader("Node Components"))
        {
            selectionViewPos = EditorGUILayout.BeginScrollView(selectionViewPos, "TextField");

            //根节点只显示除GameObject、Transform以外的组件
            var target   = Selection.activeTransform;
            var nodeType = ValidateSelection(target);
            if (nodeType != PrefabNodeType.Error)
            {
                if (nodeType != PrefabNodeType.Root && GUILayout.Button("---GameObject---"))
                {
                    string      comUID = ViewComData.GenerateUID(target, _prefabRoot, typeof(GameObject));
                    ViewComData comInfo;
                    if (_viewRefData.TryGetValue(comUID, out comInfo))
                    {
                        _curComInfo = comInfo;
                    }
                    else
                    {
                        if (EditorUtility.DisplayDialog("提示", "是否添加该组件到配置中?\nUID:" + comUID, "确定", "取消"))
                        {
                            var newComInfo = new ViewComData(target, _prefabRoot, typeof(GameObject));
                            _viewRefData.components.Add(newComInfo);
                            _curComInfo = newComInfo;
                        }
                    }

                    EditorGUIUtility.editingTextField = false;
                }
                GUILayout.Space(3f);

                GUILayout.Label("ComponentList");
                Component[] comList = target.GetComponents <Component>();
                foreach (Component com in comList)
                {
                    var comType = com.GetType();
                    if (GUILayout.Button(comType.Name))
                    {
                        string      comUID = ViewComData.GenerateUID(target, _prefabRoot, comType);
                        ViewComData comInfo;
                        if (_viewRefData.TryGetValue(comUID, out comInfo))
                        {
                            _curComInfo           = comInfo;
                            comInfo.fulleTypeName = string.IsNullOrEmpty(comInfo.fulleTypeName)
                                ? comType.FullName
                                : comInfo.fulleTypeName;
                        }
                        else
                        {
                            if (EditorUtility.DisplayDialog("提示", "是否添加该组件到配置中?\nUID:" + comUID, "确定", "取消"))
                            {
                                var newComInfo = new ViewComData(target, _prefabRoot, comType);
                                _viewRefData.components.Add(newComInfo);
                                _curComInfo = newComInfo;
                            }
                        }

                        EditorGUIUtility.editingTextField = false;
                    }
                    GUILayout.Space(3f);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("This is not a node of UIPrefab", MessageType.Info);
            }
            EditorGUILayout.EndScrollView();
        }

        EditorGUILayout.EndVertical();
    }
 private void CleanUp()
 {
     _prefabRoot  = null;
     _viewRefData = null;
     _curComInfo  = null;
 }