private static void AddGameObjectToLink() { UnityEngine.GameObject select = Selection.activeGameObject; if (select == null) { return; } if (!select.activeInHierarchy) { Debug.LogError(string.Format("【NGUILink】自动添加对象失败:请先激活需要添加的对象和NGUILink对象", select.name), select); return; } NGUILink link = FindInParents <NGUILink>(select.transform); if (link == null) { Debug.LogError(string.Format("【NGUILink】自动添加对象失败:{0}父节点无NGUILink组件", select.name), select); return; } if (link.gameObject == select && select.transform.parent != null) { link = FindInParents <NGUILink>(select.transform.parent); } if (link == null) { Debug.LogError(string.Format("【NGUILink】自动添加对象失败:{0}父节点无NGUILink组件", select.name), select); return; } link.ReBuildLinkMap(); if (link.Get(select.name) == null) { NGUILink.UILink item = new NGUILink.UILink(); item.Name = select.name; item.LinkObj = select; link.Links.Add(item); Debug.Log(string.Format("【NGUILink】自动添加对象成功:{0} NGUILink:{1}", select.name, link.name), link); } else { Debug.LogError(string.Format("【NGUILink】自动添加对象失败:已经存在重复名字{0}的对象 NGUILink:{1}", select.name, link.name), link); } }