public static void AddRule(ImporterRule rule) { if (rules == null) { Load(); } rules.Add(rule); Save(); }
public static ImporterRule OpenWindow(ImporterRule rule = null) { activeRule = rule; wnd = GetWindow <ImporterRulesEditorWindow>(false, "Rules Editor", true); tempRule = new ImporterRule(); if (rule != null) { tempRule.CopyFrom(rule); } return(tempRule); }
public static void SetRuleIndex(ImporterRule rule, int index) { if (index < 0 || index > countRules - 1) { return; } int oldIndex = rules.IndexOf(rule); rules.Remove(rule); if (index > oldIndex) { index--; } rules.Insert(index, rule); }
private void OnGUI() { if (tempRule == null) { return; } tempRule.DrawEditor(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { if (tempRule.pathComparer == ImporterRulesPathComparer.regex && !string.IsNullOrEmpty(tempRule.pattern)) { try { new Regex(tempRule.pattern); } catch (Exception) { Debug.LogWarning("Regex pattern contains an error."); return; } } if (activeRule != null) { activeRule.CopyFrom(tempRule); } else { ImporterRulesWindow.AddRule(tempRule); } ImporterRulesWindow.Save(); ImporterRulesWindow.RedrawWindow(); Close(); } if (GUILayout.Button("Cancel")) { activeRule = null; Close(); } GUILayout.EndHorizontal(); }
public static void DuplicateRule(ImporterRule rule) { ImporterRule newRule = ImporterRulesEditorWindow.OpenWindow(); newRule.CopyFrom(rule); string name = newRule.name; Regex regex = new Regex(@"\d+$", RegexOptions.IgnoreCase); if (regex.IsMatch(name)) { newRule.name = regex.Replace(name, match => (int.Parse(match.Value) + 1).ToString()); } else { newRule.name += " 2"; } }