Exemplo n.º 1
0
        private static void FetchRules(ValidatorSettings settings = null)
        {
            if (settings == null)
            {
                settings = GetOrCreateSettings();
            }
            var currentRuleFilePaths = RuleUtility.GetRuleFilePaths().ToArray();
            var settingsFilePaths    = settings.rules.Select(rule => rule.FilePath).ToArray();

            // 現在の設定にないものを追加する
            foreach (var filePath in currentRuleFilePaths)
            {
                if (!settingsFilePaths.Contains(filePath))
                {
                    AddRule(settings, filePath);
                }
            }

            // 現在の設定に余分にあるものを削除する
            var deleteRuleIndices = new List <int>();

            foreach (var filePath in settingsFilePaths)
            {
                if (!currentRuleFilePaths.Contains(filePath))
                {
                    var index = Array.IndexOf(currentRuleFilePaths, filePath);
                    deleteRuleIndices.Add(index);
                }
            }

            foreach (int index in deleteRuleIndices.OrderByDescending(x => x))
            {
                settings.rules.RemoveAt(index);
            }
        }
Exemplo n.º 2
0
 private static void AddRule(ValidatorSettings settings, string filePath)
 => settings.rules.Add(new RuleItem
 {
     Name     = RuleUtility.FilePath2RuleName(filePath),
     Enabled  = true,
     FilePath = filePath,
 });
Exemplo n.º 3
0
        private static ValidatorSettings CreateSettings()
        {
            var settings = ScriptableObject.CreateInstance <ValidatorSettings>();

            settings.validateOnUploadAvatar = true;

            var filePaths = RuleUtility.GetRuleFilePaths();

            foreach (var filePath in filePaths)
            {
                AddRule(settings, filePath);
            }

            AssetDatabase.CreateAsset(settings, SETTINGS_FILE_PATH);
            AssetDatabase.SaveAssets();
            return(settings);
        }