///////////////////////////////////////////////////////////////////////// // Scriptable Objects Processing ///////////////////////////////////////////////////////////////////////// public static void ProcessScriptableObject(AssetInfo asset, Object scriptableObject) { currentLocation = RecordLocation.Asset; if (missingComponentDetector.TryDetectScriptableObjectIssue(asset.Path, scriptableObject)) { return; } var shouldTraverseProperties = missingReferenceDetector.Enabled; if (shouldTraverseProperties) { var initialInfo = new SerializedObjectTraverseInfo(scriptableObject); CSTraverseTools.TraverseObjectProperties(initialInfo, (info, property) => { if (property.type == "UnityEvent") { missingReferenceDetector.TryDetectScriptableObjectUnityEventIssue(asset.Path, info.TraverseTarget.GetType().Name, property); info.skipCurrentTree = true; return; } missingReferenceDetector.TryDetectScriptableObjectIssue(asset.Path, info.TraverseTarget.GetType().Name, property); }); } currentLocation = RecordLocation.Unknown; }
///////////////////////////////////////////////////////////////////////// // Scenes Processing ///////////////////////////////////////////////////////////////////////// public static void SceneStart(AssetInfo asset) { currentLocation = RecordLocation.Scene; currentAsset = asset; missingReferenceDetector.TryDetectIssuesInSceneSettings(currentAsset); }
private List <ValidationResult> ValidateSingleColumn <T>(IEnumerable <T> table, IList <dynamic> values, string columnName, Type columnType) { var typeName = typeof(T).Name; var valueDict = values.Select((e, i) => (Index: i, Value: e)).GroupBy(e => e.Value).ToDictionary(e => e.Key, e => e); var results = valueDict.Where(e => e.Value.Count() > 1).Select(e => { var result = new ValidationResult(); var value = e.Value.First().Value; var indexes = e.Value.Select(e => e.Index).ToArray(); var location = new RecordLocation() { LocationType = RecordLocationType.Table, DataIndex = indexes[0], //first Index Only TypeName = columnType.Name, ColumnName = columnName, TableName = typeName }; result.Message = buildErrorMessage(indexes, typeName, columnName, columnType.Name, value != null ? value.ToString() : "(null)"); result.Location = location; return(result); }).ToList(); return(results); }
protected GameObjectIssueRecord(IssueKind kind, RecordLocation location, string path, GameObject gameObject, Type componentType, string componentName, int componentIndex, string propertyPath) : this(kind, location, path, gameObject, componentType, componentName, componentIndex) { this.propertyPath = propertyPath; if (propertyPath.EndsWith("].m_MethodName", StringComparison.OrdinalIgnoreCase)) { missingEventMethod = true; } }
protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject, Component component, Type componentType, string componentName, string property) : this(type, location, path, gameObject, component, componentType, componentName) { if (!string.IsNullOrEmpty(property)) { string nicePropertyName = ObjectNames.NicifyVariableName(property); TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; this.property = textInfo.ToTitleCase(nicePropertyName); } }
protected GameObjectIssueRecord(IssueKind kind, RecordLocation location, string path, GameObject gameObject, Type componentType, string componentName, int componentIndex) : this(kind, location, path, gameObject) { this.componentName = componentName; this.componentIndex = componentIndex; if (this.componentIndex > 0 && componentType != null && gameObject.GetComponents(componentType).Length > 1) { componentNamePostfix = " (#" + this.componentIndex + ")"; } }
public bool TryDetectIssue(RecordLocation location, string assetPath, GameObject target, Type componentType, string componentName, int orderIndex, SerializedProperty property) { if (!enabled || !IsPropertyHasMissingReference(property)) { return(false); } AddIssue(location, assetPath, target, componentType, componentName, orderIndex, property.propertyPath); return(true); }
protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject, Component component, Type componentType, string componentName) : this(type, location, path, gameObject) { this.componentName = componentName; componentId = CSObjectTools.GetLocalIdentifierInFileForObject(component); if (componentId > 0 && gameObject.GetComponents(componentType).Length > 1) { this.componentName += " (ID: " + componentId + ")"; } }
protected GameObjectIssueRecord(IssueKind kind, RecordLocation location, string path, GameObject gameObject) : base(kind, location, path) { var transform = gameObject.transform; transformPath = CSEditorTools.GetFullTransformPath(transform); if (kind != IssueKind.MissingPrefab) { objectId = CSObjectTools.GetUniqueObjectId(gameObject); } }
internal static void SelectGameObject(GameObject go, RecordLocation location) { if (location == RecordLocation.Scene) { Selection.activeTransform = go == null ? null : go.transform; } else { Selection.activeGameObject = go; } }
private string buildErrorMessagePrefix(RecordLocation location) { switch (location.LocationType) { case RecordLocationType.Table: return($"Error: InvalidRecord. Constraint: NotBlank Index: {location.DataIndex} TableName: {location.TableName}, ColumnName: {location.ColumnName}"); case RecordLocationType.SingleRecord: default: return($"Error: InvalidRecord. Constraint: NotBlank. TableName: {location.TableName}, ColumnName: {location.ColumnName}"); } }
public void TryDetectIssue(RecordLocation location, string assetPath, GameObject target, Type componentType, string componentName, int orderIndex) { foreach (var duplicateInfo in existingData) { if (duplicateInfo.hash == newHash) { var issue = GameObjectIssueRecord.Create(IssueKind.DuplicateComponent, location, assetPath, target, componentType, componentName, orderIndex); issues.Add(issue); break; } } }
protected List <ValidationResult> ValidateUintValue(RecordLocation location, uint value) { var results = new List <ValidationResult>(); if (value < 1) { var result = new ValidationResult(); result.Message = $"{buildErrorMessagePrefix(location)} Value: {value}"; result.Location = location; results.Add(result); } return(results); }
protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject) : base(type, location) { this.path = path; gameObjectPath = CSEditorTools.GetFullTransformPath(gameObject.transform); objectId = CSObjectTools.GetLocalIdentifierInFileForObject(gameObject); #if UNITY_5_3_PLUS if (location == RecordLocation.Scene) { this.path = gameObject.scene.path; } #endif }
public bool TryDetectIssue(RecordLocation location, string assetPath, GameObject target) { if (!CSPrefabTools.IsMissingPrefabInstance(target)) { return(false); } if (enabled) { issues.Add(GameObjectIssueRecord.Create(IssueKind.MissingPrefab, location, assetPath, target)); } return(true); }
public void TryDetectIssue(RecordLocation location, string assetPath, GameObject target) { if (!enabled) { return; } if (IsTransformHasHugePosition(target.transform)) { var record = GameObjectIssueRecord.Create(IssueKind.HugePosition, location, assetPath, target, CSReflectionTools.transformType, "Transform", 0, "Position"); issues.Add(record); } }
public void TryDetectIssue(RecordLocation location, string assetPath, GameObject target) { #if UNITY_2019_1_OR_NEWER missingComponentsCount = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(target); #endif if (missingComponentsCount <= 0 || !enabled) { return; } var record = GameObjectIssueRecord.Create(IssueKind.MissingComponent, location, assetPath, target, null, null, -1); record.headerFormatArgument = missingComponentsCount; issues.Add(record); }
private void AddIssue(RecordLocation location, string assetPath, GameObject target, Type componentType, string componentName, int orderIndex, string propertyPath) { IssueRecord record; if (location != RecordLocation.Asset) { record = GameObjectIssueRecord.Create(IssueKind.MissingReference, location, assetPath, target, componentType, componentName, orderIndex, propertyPath); } else { record = ScriptableObjectIssueRecord.Create(IssueKind.MissingReference, assetPath, componentName, propertyPath); } issues.Add(record); }
protected List <ValidationResult> ValidateStringValue(RecordLocation location, string value) { var results = new List <ValidationResult>(); if (value == null || value.Length < 1) { var result = new ValidationResult(); var parsedValue = value == null ? "Null" : value; result.Message = $"{buildErrorMessagePrefix(location)} Value: {parsedValue}"; result.Location = location; results.Add(result); } return(results); }
protected List <ValidationResult> ValidateEnumValue(RecordLocation location, int value) { var results = new List <ValidationResult>(); // 0 is default if (value == 0) { var result = new ValidationResult(); result.Message = $"{buildErrorMessagePrefix(location)} Value: {value}"; result.Location = location; results.Add(result); } return(results); }
///////////////////////////////////////////////////////////////////////// // Settings Assets Processing ///////////////////////////////////////////////////////////////////////// public static void ProcessSettingsAsset(AssetInfo asset) { currentLocation = RecordLocation.Asset; var kind = asset.SettingsKind; missingReferenceDetector.TryDetectIssuesInSettingsAsset(asset, kind); if (kind == AssetSettingsKind.TagManager) { duplicateLayersDetector.TryDetectIssue(); } currentLocation = RecordLocation.Unknown; }
protected GameObjectIssueRecord(RecordType type, RecordLocation location, string path, GameObject gameObject, Component component, Type componentType, string componentName) : this(type, location, path, gameObject) { if (component == null) { return; } this.component = componentName; if (gameObject.GetComponents(componentType).Length > 1) { long id = CSObjectTools.GetLocalIdentifierInFileForObject(component); if (id != 0) { this.component += " (ID: " + id + ")"; } } }
public void TryDetectIssue(RecordLocation currentLocation, string assetPath, GameObject target) { if (!enabled) { return; } if (terrainChecked && terrainColliderChecked && terrainColliderTerrainData != terrainTerrainData) { issues.Add(GameObjectIssueRecord.Create(IssueKind.InconsistentTerrainData, currentLocation, assetPath, target, componentType, componentName, componentIndex)); } terrainChecked = false; terrainColliderChecked = false; terrainTerrainData = null; terrainColliderTerrainData = null; }
public void TryDetectIssue(RecordLocation location, string assetPath, GameObject target) { if (!enabled) { return; } var layerIndex = target.layer; if (!string.IsNullOrEmpty(LayerMask.LayerToName(layerIndex))) { return; } var issue = GameObjectIssueRecord.Create(IssueKind.UnnamedLayer, location, assetPath, target); issue.headerExtra = "(index: " + layerIndex + ")"; issues.Add(issue); }
public List <ValidationResult> Validate(RecordLocation location, dynamic value, Type type, TypeCode dataTypeCode) { switch (dataTypeCode) { case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: return(ValidateUintValue(location, (uint)value)); case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: return(type.IsEnum ? ValidateEnumValue(location, Convert.ToInt32(value)) : ValidateIntValue(location, (int)value)); case TypeCode.Double: return(ValidateDoubleValue(location, (double)value)); case TypeCode.String: return(ValidateStringValue(location, (string)value)); default: return(new List <ValidationResult>()); } }
// ---------------------------------------------------------------------------- // fix missing reference // ---------------------------------------------------------------------------- public static FixResult FixMissingReference(Object unityObject, string propertyPath, RecordLocation location) { var so = new SerializedObject(unityObject); var sp = so.FindProperty(propertyPath); if (MissingReferenceDetector.IsPropertyHasMissingReference(sp)) { sp.objectReferenceInstanceIDValue = 0; var fileId = sp.FindPropertyRelative("m_FileID"); if (fileId != null) { fileId.intValue = 0; } // fixes dirty scene flag after batch issues fix // due to the additional undo action so.ApplyModifiedPropertiesWithoutUndo(); if (location == RecordLocation.Scene) { CSSceneTools.MarkSceneDirty(); } else { if (unityObject != null) { EditorUtility.SetDirty(unityObject); } } } return(new FixResult(true)); }
internal static GameObjectIssueRecord Create(IssueKind type, RecordLocation location, string path, GameObject gameObject, Type componentType, string componentName, int componentIndex, string propertyPath) { return(new GameObjectIssueRecord(type, location, path, gameObject, componentType, componentName, componentIndex, propertyPath)); }
internal static GameObjectIssueRecord Create(IssueKind type, RecordLocation location, string path, GameObject gameObject) { return(new GameObjectIssueRecord(type, location, path, gameObject)); }
protected RecordBase(RecordLocation location) { Location = location; }
// ---------------------------------------------------------------------------- // base constructors // ---------------------------------------------------------------------------- protected CleanerRecord(RecordType type, RecordLocation location) : base(location) { this.type = type; }