public static MissingInfo GetMissingObjectReferenceInPrefab(string path) { var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path); if (prefab == null) { Debug.LogError("预制体路径不存在,无法加载对象。"); return(null); } MissingInfo missingInfo = new MissingInfo(); missingInfo.MissingObject = prefab; missingInfo.Path = path; missingInfo.MissingDatas = new List <MissingData>(); var components = prefab.GetComponentsInChildren <Component>(true); foreach (var component in components) { if (component == null) { Debug.LogError($"Prefab has missing scripts,Name:{prefab.name}."); continue; } SerializedObject serializedObject = new SerializedObject(component); SerializedProperty serializedProperty = serializedObject.GetIterator(); while (serializedProperty.NextVisible(true)) { if (serializedProperty.propertyType == SerializedPropertyType.ObjectReference) { // sheder 需要特殊处理下 if (serializedProperty.displayName == "Shader" && serializedProperty.objectReferenceValue == null) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = serializedProperty.propertyPath, }); Debug.Log($"{component.name} 引用丢失\n路径:{AssetDatabase.GetAssetPath(component)}\n丢失属性:{serializedProperty.propertyPath}"); continue; } //引用对象是null 并且 引用ID不是0 说明丢失了引用 if (serializedProperty.objectReferenceValue == null && serializedProperty.objectReferenceInstanceIDValue != 0) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = serializedProperty.propertyPath, InstanceID = serializedProperty.objectReferenceInstanceIDValue, }); Debug.Log($"{component.name} 引用丢失\n路径:{AssetDatabase.GetAssetPath(component)}\n丢失属性:{serializedProperty.propertyPath}\n引用id:{serializedProperty.objectReferenceInstanceIDValue}"); } } } } return(missingInfo); }
public CciSourceItem(IPrimarySourceLocation location, MissingInfo item, IEnumerable <FrameworkName> unsupportedPlatformNames) { _column = location.StartColumn; _line = location.StartLine; _path = location.SourceDocument.Location; _item = item; _unsupportedPlatforms = unsupportedPlatformNames; }
public static MissingInfo GetMissingObjectReference(string path) { if (path.EndsWith(".prefab")) { return(GetMissingObjectReferenceInPrefab(path)); } else { var findOject = AssetDatabase.LoadAssetAtPath(path, typeof(object)); if (findOject == null) { UnityEngine.Debug.Log(path); return(null); } SerializedObject serializedObject = new SerializedObject(findOject); MissingInfo missingInfo = new MissingInfo(); missingInfo.MissingObject = findOject; missingInfo.Path = path; missingInfo.MissingDatas = new List <MissingData>(); SerializedProperty serializedProperty = serializedObject.GetIterator(); while (serializedProperty.NextVisible(true)) { if (serializedProperty.propertyType == SerializedPropertyType.ObjectReference) { // sheder 需要特殊处理下 if (serializedProperty.displayName == "Shader" && serializedProperty.objectReferenceValue == null) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = serializedProperty.propertyPath, }); Debug.Log($"{findOject.name} 引用丢失\n路径:{AssetDatabase.GetAssetPath(findOject)}\n丢失属性:{serializedProperty.propertyPath}"); continue; } //引用对象是null 并且 引用ID不是0 说明丢失了引用 if (serializedProperty.objectReferenceValue == null && serializedProperty.objectReferenceInstanceIDValue != 0) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = serializedProperty.propertyPath, InstanceID = serializedProperty.objectReferenceInstanceIDValue, }); Debug.Log($"{findOject.name} 引用丢失\n路径:{AssetDatabase.GetAssetPath(findOject)}\n丢失属性:{serializedProperty.propertyPath}\n引用id:{serializedProperty.objectReferenceInstanceIDValue}"); } } } return(missingInfo); } }
public static MissingInfo FindGameObject(GameObject gameObject) { MissingInfo missingInfo = new MissingInfo(); missingInfo.MissingObject = gameObject; missingInfo.MissingDatas = new List <MissingData>(); var components = gameObject.GetComponentsInChildren <Component>(true); foreach (var component in components) { if (component == null) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = "Component missing" }); Debug.LogWarningFormat("Prefab has missing scripts,Name:{0}.", gameObject.name); } else { SerializedObject serializedObject = new SerializedObject(component); SerializedProperty serializedProperty = serializedObject.GetIterator(); while (serializedProperty.NextVisible(true)) { if (serializedProperty.propertyType == SerializedPropertyType.ObjectReference) { //引用对象是null 并且 引用ID不是0 说明丢失了引用 if (serializedProperty.objectReferenceValue == null && serializedProperty.objectReferenceInstanceIDValue != 0) { missingInfo.MissingDatas.Add(new MissingData() { PropertyName = serializedProperty.propertyPath, InstanceID = serializedProperty.objectReferenceInstanceIDValue, }); Debug.LogWarningFormat("{0} 引用丢失\n\n丢失属性:{1}\n引用id:{2}", component.name, serializedProperty.propertyPath, serializedProperty.objectReferenceInstanceIDValue); } } } } } return(missingInfo); }
private IEnumerable <Version> GetTargetStatus(MissingInfo missingInfo) { var memberInfo = missingInfo as MissingMemberInfo; var typeInfo = missingInfo as MissingTypeInfo; if (memberInfo != null) { return(memberInfo.TargetVersionStatus); } else if (typeInfo != null) { return(typeInfo.TargetVersionStatus); } else { Debug.Assert(true, "Unknown MissingInfo type"); return(new List <Version>()); } }
private static string GetName(MissingInfo item) { var memberInfo = item as MissingMemberInfo; var typeInfo = item as MissingTypeInfo; if (memberInfo != null) { return(memberInfo.MemberName); } else if (typeInfo != null) { return(typeInfo.TypeName); } else { Debug.Assert(true, "Unknown MissingInfo type"); return(string.Empty); } }
private ISourceMappedItem GetSourceMappedItem(IPrimarySourceLocation location, MissingInfo memberInfo) { var unsupportedPlatformNames = GetUnsupportedPlatformNames(GetTargetStatus(memberInfo)); return(new CciSourceItem(_assemblyPath, location, memberInfo, unsupportedPlatformNames)); }