コード例 #1
0
ファイル: IssuesDetector.cs プロジェクト: s1gurd/W-Hub
        /////////////////////////////////////////////////////////////////////////
        // 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;
        }
コード例 #2
0
ファイル: IssuesDetector.cs プロジェクト: s1gurd/W-Hub
        /////////////////////////////////////////////////////////////////////////
        // Scenes Processing
        /////////////////////////////////////////////////////////////////////////

        public static void SceneStart(AssetInfo asset)
        {
            currentLocation = RecordLocation.Scene;
            currentAsset    = asset;

            missingReferenceDetector.TryDetectIssuesInSceneSettings(currentAsset);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 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 + ")";
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
ファイル: GameObjectIssueRecord.cs プロジェクト: rfHu/poker
        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 + ")";
            }
        }
コード例 #9
0
        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);
            }
        }
コード例 #10
0
 internal static void SelectGameObject(GameObject go, RecordLocation location)
 {
     if (location == RecordLocation.Scene)
     {
         Selection.activeTransform = go == null ? null : go.transform;
     }
     else
     {
         Selection.activeGameObject = go;
     }
 }
コード例 #11
0
        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}");
            }
        }
コード例 #12
0
 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;
         }
     }
 }
コード例 #13
0
        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);
        }
コード例 #14
0
        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
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: HugePositionDetector.cs プロジェクト: s1gurd/W-Hub
        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);
            }
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
ファイル: IssuesDetector.cs プロジェクト: s1gurd/W-Hub
        /////////////////////////////////////////////////////////////////////////
        // 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;
        }
コード例 #22
0
        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 + ")";
                }
            }
        }
コード例 #23
0
        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;
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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>());
            }
        }
コード例 #26
0
        // ----------------------------------------------------------------------------
        // 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));
        }
コード例 #27
0
 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));
 }
コード例 #28
0
 internal static GameObjectIssueRecord Create(IssueKind type, RecordLocation location, string path, GameObject gameObject)
 {
     return(new GameObjectIssueRecord(type, location, path, gameObject));
 }
コード例 #29
0
ファイル: RecordBase.cs プロジェクト: Pinkpanterus/DPND
 protected RecordBase(RecordLocation location)
 {
     Location = location;
 }
コード例 #30
0
        // ----------------------------------------------------------------------------
        // base constructors
        // ----------------------------------------------------------------------------

        protected CleanerRecord(RecordType type, RecordLocation location) : base(location)
        {
            this.type = type;
        }