private void AssignTable(RSRuleTableData inTable) { if (m_Table == inTable) { return; } if (m_Table != null) { m_Entity.Manager?.DeregisterTriggers(m_Entity, m_Table.UniqueTriggers); } m_Table = inTable; StopAll(); if (m_Table != null) { int length = m_Table.Rules != null ? m_Table.Rules.Length : 0; Array.Resize(ref m_States, length); Array.Resize(ref m_Routines, length); for (int i = 0; i < length; ++i) { RSRuleData rule = m_Table.Rules[i]; m_States[i] = rule.Enabled ? 0 : RuleState.Disabled; } m_Entity.Manager?.RegisterTriggers(m_Entity, m_Table.UniqueTriggers); } else { m_States = null; m_Routines = null; } }
/// <summary> /// Prompts the user to load a table from disk. /// </summary> static private RSRuleTableData LoadTable(string inInitialPath) { string filePath = EditorUtility.OpenFilePanelWithFilters("Load Rule Table", inInitialPath ?? Application.dataPath, FILE_FILTERS); if (string.IsNullOrEmpty(filePath)) { return(null); } try { RSRuleTableData ruleTableData = null; bool bSuccess = Serializer.ReadFile(ref ruleTableData, filePath); if (!bSuccess) { EditorUtility.DisplayDialog("Error while reading table", "See console for details", "Okay"); return(null); } return(ruleTableData); } catch (Exception e) { Debug.LogException(e); EditorUtility.DisplayDialog("Error while reading table", "Exception encountered; see console for details", "Okay"); return(null); } }
static internal void ValidateTable(RSRuleTableData inTable, RSValidationState ioState, RSValidationContext inContext) { if (inContext.Library == null) { ioState.Error("No library provided"); return; } else if (!inContext.Library.IsLoaded()) { ioState.Error("Library not fully loaded"); return; } if (inTable == null || inTable.Rules == null || inTable.Rules.Length == 0) { return; } for (int i = 0; i < inTable.Rules.Length; ++i) { ioState.PushContext("Rule {0}: {1}", i, inTable.Rules[i]?.Name); ValidateRule(inTable.Rules[i], ioState, inContext); ioState.PopContext(); } }
/// <summary> /// Attempts to validate the given table. /// </summary> static public RSValidationState Validate(RSRuleTableData inRuleTable, RSValidationContext inContext) { RSValidationState state = new RSValidationState(inRuleTable?.Name ?? "Rule Table"); ValidationLogic.ValidateTable(inRuleTable, state, inContext); state.Finish(); return(state); }
private void ConfigureRuleList(RSRuleTableData inTable, ref RSReorderableList <RSRuleData> ioList) { ioList = new RSReorderableList <RSRuleData>(inTable.Rules); ioList.drawElementCallback = RenderRuleListElement; ioList.drawNoneElementCallback = RenderNoRulesElement; ioList.drawHeaderCallback = RenderRulesHeaderElement; ioList.onAddCallback = OnAddNewRule; ioList.onRemoveCallback = OnRemoveRule; ioList.onSelectCallback = OnSelectRule; ioList.onWillReorderCallback = OnWillReorder; ioList.onReorderCallback = OnRuleReorder; ioList.index = m_SelectionState.RuleIndex; SyncAllowedListOperations(ioList); }
private void ConfigGUI() { using (new EditorGUI.DisabledScope(m_SelectionState.Table == null)) { { bool bFilterSelections = EditorGUILayout.Toggle(EditorGUIUtility.TrTextContent("Filter Selections", "If unchecked, all triggers, queries, and actions will be presented for all entities."), m_FilterSelections); if (bFilterSelections != m_FilterSelections) { m_SelfUndoTarget.MarkDirty("Changed filter mode"); m_FilterSelections = bFilterSelections; } } EditorGUILayout.Space(); using (new GUILayout.HorizontalScope()) { if (GUILayout.Button("Export")) { SaveTable(m_SelectionState.Table, m_SerializationFormat, null); } if (GUILayout.Button("Import")) { RSRuleTableData table = LoadTable(null); if (table != null) { SelectAction(-1); SelectCondition(-1); SelectRule(-1); m_TargetState.UndoTarget.MarkDirty("Reloaded Table", true); m_SelectionState.Table.CopyFrom(table); } } Serializer.Format newFormat = ListGUILayout.Popup(m_SerializationFormat, RSEditorUtility.s_SerializeFormats, GUILayout.Width(60)); if (newFormat != m_SerializationFormat) { m_SelfUndoTarget.MarkDirty("Changed Serialization Format"); m_SerializationFormat = newFormat; } } } }
public void Refresh() { if (Source == null) { ClearSelections(); return; } if (Source.TableData == null) { Table = null; ClearSelections(); return; } Table = Source.TableData; Rule = Select(Table?.Rules, RuleIndex); Condition = Select(Rule?.Conditions, ConditionIndex); Action = Select(Rule?.Actions, ActionIndex); }
/// <summary> /// Prompts the user to save a table to disk. /// </summary> static private bool SaveTable(RSRuleTableData inData, Serializer.Format inFormat, string inInitialPath) { string filePath = EditorUtility.SaveFilePanel("Save Rule Table", inInitialPath ?? Application.dataPath, inData.Name, "rule"); if (string.IsNullOrEmpty(filePath)) { return(false); } try { Serializer.WriteFile(inData, filePath, OutputOptions.PrettyPrint, inFormat); return(true); } catch (Exception e) { Debug.LogException(e); EditorUtility.DisplayDialog("Error while writing table", "Exception encountered; see console for details", "Okay"); return(false); } }
public void Initialize(RSRuleTableData inTable) { Data = inTable; }
/// <summary> /// Renders editor for rule info. Does not include conditions or actions. /// </summary> static public void RuleData(UndoTarget inUndo, RSRuleData ioRule, RSRuleTableData ioTable, RSValidationFlags inFlags, RSValidationContext inContext) { string preview = ioRule.GetPreviewString(null, inContext.Library); GUILayout.Label(preview, RSGUIStyles.RuleHeaderStyle); EditorGUILayout.Space(); string newName = EditorGUILayout.TextField(Content.RuleNameLabel, ioRule.Name); if (newName != ioRule.Name) { inUndo.MarkDirty("Changed Rule Name"); ioRule.Name = newName; } RSTriggerId newTriggerId; if (inFlags.Has(RSValidationFlags.FilterSelection) && inContext.Entity != null) { newTriggerId = LibraryGUILayout.TriggerSelector(Content.RuleTriggerLabel, ioRule.TriggerId, inContext.Entity, inContext.Library); } else { newTriggerId = LibraryGUILayout.TriggerSelector(Content.RuleTriggerLabel, ioRule.TriggerId, inContext.Library); } if (newTriggerId != ioRule.TriggerId) { inUndo.MarkDirty("Changed Rule Trigger", true); ioRule.TriggerId = newTriggerId; TableUtils.UpdateUniqueRuleTriggers(ioTable); } if (newTriggerId != RSTriggerId.Null) { RSTriggerInfo info = inContext.Library.GetTrigger(newTriggerId); if (info != null && info.ParameterType != null) { using (new EditorGUI.IndentLevelScope()) { EditorGUILayout.LabelField(Content.RuleParameterLabel, EditorGUIUtility.TrTextContent(info.ParameterType.ToStringWithoutDefault(), info.ParameterType.Tooltip)); } } } EditorGUILayout.Space(); // Enabled bool bEnabled = EditorGUILayout.Toggle(Content.RuleEnabledLabel, ioRule.Enabled); if (bEnabled != ioRule.Enabled) { inUndo.MarkDirty("Changed Rule Enabled"); ioRule.Enabled = bEnabled; } bool bOnlyOnce = EditorGUILayout.Toggle(Content.RuleOnlyOnceLabel, ioRule.OnlyOnce); if (bOnlyOnce != ioRule.OnlyOnce) { inUndo.MarkDirty("Changed Rule OnlyOnce"); ioRule.OnlyOnce = bOnlyOnce; } bool bDontInterrupt = EditorGUILayout.Toggle(Content.RuleDontInterruptLabel, ioRule.DontInterrupt); if (bDontInterrupt != ioRule.DontInterrupt) { inUndo.MarkDirty("Changed Rule DontInterrupt"); ioRule.DontInterrupt = bDontInterrupt; } EditorGUILayout.Space(); string newGroup = EditorGUILayout.TextField(Content.RuleGroupLabel, ioRule.RoutineGroup); if (newGroup != ioRule.RoutineGroup) { inUndo.MarkDirty("Changed Rule Group"); ioRule.RoutineGroup = newGroup; } }
public void ClearAll() { ClearSelections(); Table = null; }