protected virtual KeyValuePair <Object, AutoBindFieldInfo> getGenInfoFromFieldInfo(FieldInfo field)
        {
            if (field.FieldType != typeof(GameObject) &&//不是GameObject
                !field.FieldType.IsSubclassOf(typeof(Component))   //也不是组件
                )
            {
                return(default(KeyValuePair <Object, AutoBindFieldInfo>));
            }
            AutoCompoAttribute autoCompoAttr = field.getAttribute <AutoCompoAttribute>();

            if (autoCompoAttr != null)
            {
                //先用InstanceID找
                GameObject gameObject = findGameObjectByInstanceID(_gameObject, autoCompoAttr.instanceID);
                if (gameObject != null)
                {
                    if (field.FieldType != typeof(GameObject))
                    {
                        Component component = gameObject.GetComponent(field.FieldType);
                        if (component != null)
                        {
                            return(new KeyValuePair <Object, AutoBindFieldInfo>(component, new AutoBindFieldInfo(autoCompoAttr.instanceID, autoCompoAttr.path, field.FieldType, null, field.Name)));
                        }
                        return(default(KeyValuePair <Object, AutoBindFieldInfo>));
                    }
                    return(new KeyValuePair <Object, AutoBindFieldInfo>(gameObject, new AutoBindFieldInfo(autoCompoAttr.instanceID, autoCompoAttr.path, field.FieldType, null, field.Name)));
                }
                //再用路径找
                if (!string.IsNullOrEmpty(autoCompoAttr.path))
                {
                    Transform transform = _gameObject.transform.Find(autoCompoAttr.path);
                    if (transform != null)
                    {
                        gameObject = transform.gameObject;
                        if (field.FieldType != typeof(GameObject))
                        {
                            Component component = gameObject.GetComponent(field.FieldType);
                            if (component != null)
                            {
                                return(new KeyValuePair <Object, AutoBindFieldInfo>(component, new AutoBindFieldInfo(autoCompoAttr.instanceID, autoCompoAttr.path, field.FieldType, null, field.Name)));
                            }
                            return(default(KeyValuePair <Object, AutoBindFieldInfo>));
                        }
                        return(new KeyValuePair <Object, AutoBindFieldInfo>(gameObject, new AutoBindFieldInfo(autoCompoAttr.instanceID, autoCompoAttr.path, field.FieldType, null, field.Name)));
                    }
                }
                //存在但是损失的数据
                return(new KeyValuePair <Object, AutoBindFieldInfo>(null, new AutoBindFieldInfo(autoCompoAttr.instanceID, autoCompoAttr.path, field.FieldType, null, field.Name)));
            }
            else
            {
                Component autoComponent = _gameObject.GetComponent(_type);
                if (autoComponent == null)
                {
                    return(default(KeyValuePair <Object, AutoBindFieldInfo>));
                }
                foreach (MonoScript autoScript in _autoScripts)
                {
                    if (autoScript.text.Contains(field.FieldType.Name + " " + field.Name))
                    {
                        //在自动生成的代码中存在字段声明,查找对应的属性
                        foreach (var property in _type.GetProperties())
                        {
                            //类型与名字相同则认为是对应属性
                            if (property.PropertyType != field.FieldType || !field.Name.Equals("_" + property.Name, StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }
                            Object obj = null;
                            try
                            {
                                obj = property.GetValue(autoComponent, new object[0]) as Object;
                            }
                            catch (Exception e)
                            {
                                //存在对应属性,但是对应属性获取不到对应值了
                                Debug.LogError("获取字段" + field.Name + "对应的值时发生异常:" + e);
                                return(new KeyValuePair <Object, AutoBindFieldInfo>(null, new AutoBindFieldInfo(true, null, field.FieldType, null, field.Name)));
                            }
                            if (obj == null)
                            {
                                //存在对应属性,但是对应属性获取不到对应值了
                                return(new KeyValuePair <Object, AutoBindFieldInfo>(null, new AutoBindFieldInfo(true, null, field.FieldType, null, field.Name)));
                            }
                            if (obj is GameObject)
                            {
                                GameObject gameObject = obj as GameObject;
                                return(new KeyValuePair <Object, AutoBindFieldInfo>(gameObject,
                                                                                    new AutoBindFieldInfo(true, _gameObject.transform.getChildPath(gameObject.transform), typeof(GameObject), null, field.Name)));
                            }
                            else if (obj is Component)
                            {
                                Component component = obj as Component;
                                return(new KeyValuePair <Object, AutoBindFieldInfo>(component,
                                                                                    new AutoBindFieldInfo(true, _gameObject.transform.getChildPath(component.transform), field.FieldType, null, field.Name)));
                            }
                        }
                    }
                }
                return(default(KeyValuePair <Object, AutoBindFieldInfo>));
            }
            //return default(KeyValuePair<Object, AutoBindFieldInfo>);
        }
        /// <summary>
        /// 尝试查找当前生成物体上已经存在的自动生成脚本。
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="script"></param>
        /// <param name="willBeOverride"></param>
        /// <returns></returns>
        protected virtual bool tryFindExistScript(GameObject gameObject, out MonoScript script, out bool willBeOverride)
        {
            //对所有脚本进行筛选
            var scripts = AssetDatabase.FindAssets("t:MonoScript")
                          .Select(g => AssetDatabase.GUIDToAssetPath(g))
                          .Select(p => AssetDatabase.LoadAssetAtPath <MonoScript>(p))
                          .Where(s => s != null);
            List <MonoScript> scriptList = new List <MonoScript>();

            foreach (var s in scripts)
            {
                //不是MonoBehaviour则跳过
                Type type = s.GetClass();
                if (type == null)
                {
                    continue;
                }
                AutoCompoAttribute autoCompo = type.getAttribute <AutoCompoAttribute>();
                int instanceID = gameObject.GetInstanceID();
                if (autoCompo != null && autoCompo.instanceID == instanceID)
                {
                    //如果脚本上有AutoCompo特性说明它是该物体的脚本,则返回这个脚本
                    script         = s;
                    willBeOverride = false;
                    return(true);
                }
                if ((type.IsSubclassOf(typeof(MonoBehaviour)) || type.IsSubclassOf(typeof(Component))) &&//如果这个脚本是组件
                    gameObject.GetComponent(type) != null   //并且在当前物体上存在这个脚本的实例
                    )
                {
                    //先添加到列表中,随后选出最适合作为目标脚本的脚本
                    scriptList.Add(s);
                }
            }
            if (scriptList.Count < 1)
            {
                //不存在符合的脚本
                script         = null;
                willBeOverride = false;
                return(false);
            }
            else if (scriptList.Count > 1)
            {
                //存在超过一个脚本,先查找其中自动生成的脚本
                MonoScript autoGenScript = scriptList.FirstOrDefault(s => s.text.Contains("<auto-generated>"));
                if (autoGenScript == null)
                {
                    //不存在自动生成的脚本
                    script         = null;
                    willBeOverride = false;
                    return(false);
                }
                //获取自动生成的类型,优先选择其中不是自动生成的脚本
                Type type = autoGenScript.GetClass();
                script = null;
                foreach (var s in scriptList)
                {
                    Type t = s.GetClass();
                    if (t == type && !s.text.Contains("<auto-generated>"))
                    {
                        script = s;
                        break;
                    }
                }
                if (script == null)
                {
                    //全是自动生成的,则返回第一个
                    script = scriptList[0];
                }
                willBeOverride = true;
                return(true);
            }
            else
            {
                //只有一个脚本,如果是自动生成的则返回这个脚本
                script = scriptList[0];
                if (script.text.Contains("<auto-generated>"))
                {
                    willBeOverride = true;
                    return(true);
                }
                else
                {
                    script         = null;
                    willBeOverride = false;
                    return(false);
                }
            }
        }