void ReferencedLineWrite(GameObject selection) { List <ReferenceInfo> list = new List <ReferenceInfo>(); foreach (var refs in referencedByList) { if (ReferenceExplorerData.IsOpenComponentList.Contains(refs.type) == false) { list.AddRange(refs.referenceInfoList); } } var collection = list .Where(item => ReferenceExplorerUtility.GetGameObject(item.referenceTarget) == selection) .Select(item => item.fromObject); ReferenceExplorerUtility.WriteLine(collection, selection, Color.blue, new Color(0, 0, 0.5f, 0.06f), 0.04f); }
void OnGUIReferencedBy(IEnumerable <ReferenceViewerClassbase> referencedByList) { foreach (var type in referencedByList.Select(item => item.type).Distinct()) { var referendedByItems = referencedByList.Where(item => item.type == type); EditorGUI.indentLevel = 1; using (var itemLayout = new GUILayout.VerticalScope("box")) { var isShow = !ReferenceExplorerData.IsOpenComponentList.Contains(type); if (EditorGUILayout.Foldout(isShow, type.FullName) != isShow) { if (isShow) { ReferenceExplorerData.IsOpenComponentList.Add(type); } else { ReferenceExplorerData.IsOpenComponentList.Remove(type); } } if (isShow) { EditorGUI.indentLevel = 2; var monoscript = ReferenceExplorerData.allMonoscript.Find(item => item.GetClass() == type); EditorGUILayout.ObjectField("script", monoscript, typeof(MonoScript), true); foreach (var referenceItem in referendedByItems) { foreach (var component in referenceItem.referenceInfoList) { var fromObject = ReferenceExplorerUtility.GetGameObject(component.fromObject); EditorGUILayout.ObjectField(component.referenceName, fromObject, typeof(Object), true); } } } } } }
public static void UpdateSelectedComponentList() { if (localSelectedCollectionTime == UnityEditor.EditorApplication.timeSinceStartup) { return; } GameObject[] objects = Selection.gameObjects; allSelectedComponent.Clear(); if (objects == null) { allSelectedComponent.AddRange(allComponents); } allSelectedComponent = allComponents .Where(item => objects.Contains(ReferenceExplorerUtility.GetGameObject(item))) .ToList(); localSelectedCollectionTime = UnityEditor.EditorApplication.timeSinceStartup; }
public static bool IsFamilly(object obj, GameObject target, bool isParent) { var gameObj = ReferenceExplorerUtility.GetGameObject(obj); if (gameObj == null) { return(false); } if (isParent) { if (gameObj == target) { return(true); } return(IsFamilly(gameObj.transform.parent, target, true)); } else { if (gameObj == target) { return(true); } var childCount = gameObj.transform.childCount; for (int i = 0; i < childCount; i++) { bool result = IsFamilly(gameObj.transform.GetChild(i), target, false); if (result == true) { return(true); } } } return(false); }
public static void DisappearObjectsWithFamillyReference() { ReferenceExplorerData.RestoreAllData(); ReferenceExplorerData.RestoreComponentReferenceData(); var objects = ReferenceExplorerData.allObjects; foreach (var obj in objects) { obj.hideFlags = HideFlags.HideInHierarchy; } foreach (var component in ReferenceExplorerData.allReferenceInfo) { var fromObject = ReferenceExplorerUtility.GetGameObject(component.fromObject); var referencetarget = ReferenceExplorerUtility.GetGameObject(component.referenceTarget); if (fromObject != null) { if (fromObject.transform.GetComponentsInChildren <Component> ().Any(item => item.gameObject == referencetarget) == false && fromObject.transform.GetComponentsInParent <Component> ().Any(item => item.gameObject == referencetarget) == false) { Appear(fromObject.transform); } } if (referencetarget != null) { if (referencetarget.transform.GetComponentsInChildren <Component> ().Any(item => item.gameObject == fromObject) == false && referencetarget.transform.GetComponentsInParent <Component> ().Any(item => item.gameObject == fromObject) == false) { Appear(referencetarget.transform); } } } }
public static IEnumerable <ReferenceViewerClassbase> AllReferencedByComponent(GameObject[] currentObjects, ReferenceIgnoreType ignoreType, string search = null) { var list = new List <ReferenceViewerClassbase> (); foreach (var currentObject in currentObjects) { var referencedByList = allReferenceInfo .Where(item => currentObject == ReferenceExplorerUtility.GetGameObject(item.referenceTarget)); if (string.IsNullOrEmpty(search) == false) { var dic = ReferenceExplorerUtility.GetTExtCommand(search); if (dic.ContainsKey("type")) { var typeText = dic ["type"]; referencedByList = referencedByList .Where(item => item.referenceName.ToLower().IndexOf(typeText) != -1 || item.referenceTarget.GetType().FullName.ToLower().IndexOf(typeText) != -1 || item.fromObject.GetType().FullName.ToLower().IndexOf(typeText) != -1 || ReferenceExplorerUtility.GetGameObject(item.fromObject).name.ToLower().IndexOf(typeText) != -1); } if (dic.ContainsKey("obj")) { var objName = dic ["obj"]; referencedByList = referencedByList .Where(item => ReferenceExplorerUtility.GetGameObject(item.fromObject).name.ToLower().IndexOf(objName) != -1); } if (dic.ContainsKey("param")) { var param = dic ["param"]; referencedByList = referencedByList .Where(item => item.referenceName.IndexOf(param) != -1); } } if (ignoreType == ReferenceIgnoreType.IgnoreSelf) { referencedByList = referencedByList.Where(item => currentObject != ReferenceExplorerUtility.GetGameObject(item.fromObject)) .Where(item => currentObjects.Contains(ReferenceExplorerUtility.GetGameObject(item.fromObject)) == false); } else if (ignoreType == ReferenceIgnoreType.IgnoreFamilly) { referencedByList = referencedByList.Where(item => ReferenceExplorerUtility.IsFamilly(item.fromObject, currentObject) == false) .Where(item => currentObjects.Contains(ReferenceExplorerUtility.GetGameObject(item.fromObject)) == false); } var allComponentType = referencedByList .Select(item => item.fromObject.GetType()) .Distinct().OrderBy(item => item.FullName); foreach (var uniqueComponentType in allComponentType) { var componentItme = new ReferenceViewerClassbase(); componentItme.type = uniqueComponentType; componentItme.referenceInfoList = referencedByList .Where(item => item.fromObject.GetType() == uniqueComponentType) .OrderBy(item => ReferenceExplorerUtility.GetGameObject(item.fromObject).name) .ToList(); list.Add(componentItme); } } return(list.Where(item => item.referenceInfoList.Count > 0)); }
public static void ExportObjectReference(bool isContainFamilly, bool isContainCallbacks) { try{ ReferenceExplorerData.RestoreAllData(); EditorUtility.DisplayProgressBar("Export GameObject Graph", "get all objects", 0); var objectNames = ReferenceExplorerData.allReferenceInfo .Where(item => ReferenceExplorerUtility.GetGameObject(item.referenceTarget) != null && ReferenceExplorerUtility.GetGameObject(item.referenceTarget) != null) .SelectMany(item => new GameObject[] { ReferenceExplorerUtility.GetGameObject(item.referenceTarget), ReferenceExplorerUtility.GetGameObject(item.fromObject) }).Distinct(); EditorUtility.DisplayProgressBar("Export GameObject Graph", "check reference", 0.2f); List <ReferenceInfoObject> referenceInfoList = new List <ReferenceInfoObject>(); foreach (var referenceInfo in ReferenceExplorerData.allReferenceInfo) { var fromObject = ReferenceExplorerUtility.GetGameObject(referenceInfo.fromObject); var targetObject = ReferenceExplorerUtility.GetGameObject(referenceInfo.referenceTarget); if (targetObject == null || fromObject == null) { continue; } if (isContainFamilly == false && ReferenceExplorerUtility.IsFamilly(fromObject, targetObject)) { continue; } if (referenceInfoList.Any(item => ReferenceExplorerUtility.GetGameObject(item.fromObject) == fromObject || ReferenceExplorerUtility.GetGameObject(item.targetObject) == targetObject) == true || fromObject == targetObject) { continue; } referenceInfoList.Add(new ReferenceInfoObject() { targetObject = fromObject, fromObject = targetObject, }); } EditorUtility.DisplayProgressBar("Export GameObject Graph", "exporting", 0.7f); StringBuilder exportBuilder = new StringBuilder(); exportBuilder.AppendLine("graph"); exportBuilder.AppendLine("["); foreach (var objName in objectNames) { if (referenceInfoList.Any(item => item.fromObject == objName || item.targetObject == objName) == false) { continue; } var isPrefab = PrefabUtility.GetPrefabObject(objName) == null; exportBuilder.AppendLine(" node"); exportBuilder.AppendLine(" ["); exportBuilder.AppendLine(" id "+ objName.GetHashCode()); exportBuilder.AppendLine(" label \""+ objName.name + "\""); exportBuilder.AppendLine(" graphics"); exportBuilder.AppendLine(" ["); if (isPrefab) { exportBuilder.AppendLine(" fill \"#FFFF99\""); } exportBuilder.AppendLine(" w "+ objName.name.Length * 10); exportBuilder.AppendLine(" ]"); exportBuilder.AppendLine(" ]"); } foreach (var referenceInfo in referenceInfoList) { exportBuilder.AppendLine(" edge"); exportBuilder.AppendLine(" ["); exportBuilder.AppendLine(" target "+ referenceInfo.fromObject.GetHashCode()); exportBuilder.AppendLine(" source "+ referenceInfo.targetObject.GetHashCode()); exportBuilder.AppendLine(" ]"); } exportBuilder.AppendLine("]"); EditorUtility.DisplayProgressBar("Export GameObject Graph", "done", 0.7f); System.IO.File.WriteAllText(System.DateTime.Now.ToFileTime() + ".gml", exportBuilder.ToString()); }finally{ EditorUtility.ClearProgressBar(); } }