public void ShowRulesGUI() { GUI.backgroundColor = new Color(0.8f, 0.8f, 1); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Rule", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { RuleType xmlRule = new RuleType(); int counter = 0; string newName = "New Rule "; List <Rule> newRules = m_Rules.FindAll(x => x.m_Name.Contains(newName)); foreach (Rule rule in newRules) { string numberPart = rule.m_Name.TrimStart(newName.ToCharArray()); if (Convert.ToInt32(numberPart) > counter) { counter = Convert.ToInt32(numberPart); } } newName += ++counter; xmlRule.AddName(new Altova.Types.SchemaString(newName)); Rule newRule = new Rule(xmlRule); newRule.SetContext(m_Context); m_Rules.Add(newRule); RuleInspector ruleInspector = new RuleInspector(newRule, gameObject); ruleInspector.ShowEditor(); } GUILayout.FlexibleSpace(); //Set layout passed this point to align to the right EditorGUIUtility.labelWidth = 80; m_DebugMode = EditorGUILayout.Toggle("DebugMode: ", m_DebugMode, GUILayout.MaxWidth(95)); GUILayout.EndHorizontal(); if (m_Rules.Count != 0) { GUILayout.BeginHorizontal(); GUI.color = Color.yellow; GUILayout.Label("Rule", GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); GUI.color = Color.white; GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("There are no rules in this rule base. Add some with the Add Rule button", MessageType.Info); } foreach (Rule rule in m_Rules.ToArray()) { if (rule != null) { GUILayout.BeginHorizontal(); if (!Application.isPlaying) { GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f, 0.3f); rule.m_Name = EditorGUILayout.TextField(rule.m_Name, GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); if (GUI.changed == true) { rule.m_Rule.ReplaceNameAt(new Altova.Types.SchemaString(rule.m_Name), 0); } } else { GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f); GUI.color = new Color(0.8f, 0.8f, 1f); GUILayout.Label(rule.m_Name, GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!Application.isPlaying) { GUI.backgroundColor = new Color(0.6f, 1f, 0.6f); if (GUILayout.Button("E", GUILayout.MaxWidth(20))) { RuleInspector ruleInspector = new RuleInspector(rule, gameObject); ruleInspector.ShowEditor(); } GUI.backgroundColor = new Color(1, 0.6f, 0.6f); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (EditorUtility.DisplayDialog("Delete Rule " + rule.m_Name, "Are you sure?", "Yes", "No")) { RemoveRule(rule.m_Name); } } } GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f); GUILayout.EndHorizontal(); } } GUI.backgroundColor = Color.white; GUI.color = Color.white; }
public void ShowRulesGUI() { GUI.backgroundColor = new Color(0.8f,0.8f,1); GUILayout.BeginHorizontal (); if (GUILayout.Button("Add Rule", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false))) { RuleType xmlRule = new RuleType(); int counter = 0; string newName = "New Rule "; List<Rule> newRules = m_Rules.FindAll(x => x.m_Name.Contains(newName)); foreach ( Rule rule in newRules) { string numberPart = rule.m_Name.TrimStart(newName.ToCharArray()); if (Convert.ToInt32(numberPart) > counter) counter = Convert.ToInt32(numberPart); } newName += ++counter; xmlRule.AddName(new Altova.Types.SchemaString(newName)); Rule newRule = new Rule(xmlRule); newRule.SetContext(m_Context); m_Rules.Add(newRule); RuleInspector ruleInspector = new RuleInspector(newRule, gameObject); ruleInspector.ShowEditor(); } GUILayout.FlexibleSpace(); //Set layout passed this point to align to the right EditorGUIUtility.labelWidth = 80; m_DebugMode = EditorGUILayout.Toggle("DebugMode: ", m_DebugMode, GUILayout.MaxWidth(95)); GUILayout.EndHorizontal (); if (m_Rules.Count != 0) { GUILayout.BeginHorizontal(); GUI.color = Color.yellow; GUILayout.Label("Rule", GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); GUI.color = Color.white; GUILayout.EndHorizontal(); } else { EditorGUILayout.HelpBox("There are no rules in this rule base. Add some with the Add Rule button", MessageType.Info); } foreach (Rule rule in m_Rules.ToArray()) { if (rule != null) { GUILayout.BeginHorizontal(); if (!Application.isPlaying) { GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f, 0.3f); rule.m_Name = EditorGUILayout.TextField(rule.m_Name, GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); if (GUI.changed == true) { rule.m_Rule.ReplaceNameAt(new Altova.Types.SchemaString(rule.m_Name), 0); } } else { GUI.backgroundColor = new Color(0.7f,0.7f,0.7f); GUI.color = new Color(0.8f,0.8f,1f); GUILayout.Label(rule.m_Name, GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true)); } GUI.color = Color.white; GUI.backgroundColor = Color.white; if (!Application.isPlaying) { GUI.backgroundColor = new Color(0.6f, 1f, 0.6f); if (GUILayout.Button("E", GUILayout.MaxWidth(20))) { RuleInspector ruleInspector = new RuleInspector(rule, gameObject); ruleInspector.ShowEditor(); } GUI.backgroundColor = new Color(1,0.6f,0.6f); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (EditorUtility.DisplayDialog("Delete Rule " + rule.m_Name, "Are you sure?", "Yes", "No")) RemoveRule(rule.m_Name); } } GUI.backgroundColor = new Color(0.7f,0.7f,0.7f); GUILayout.EndHorizontal(); } } GUI.backgroundColor = Color.white; GUI.color = Color.white; }