/// <summary> /// Method called when the action dropdown changes selected option /// </summary> /// <param name="actionId">Selected action id</param> public void OnActionChange(int actionId) { var undo = new Action <Tuple <string, string> >(previous => { var previousActionId = actionDropdown.options.FindIndex(option => option.text == previous.Item1); actionDropdown.SetValueWithoutNotify(previousActionId); ActionChanged(previous.Item1); switch (previous.Item1) { case "state": var value = valueDropdown.options.FindIndex(option => option.text == previous.Item2); valueDropdown.SetValueWithoutNotify(value); break; default: UpdatePolicy(previous.Item2); break; } }); var revertActionDropdown = new GenericUndo <Tuple <string, string> >(new Tuple <string, string>(Action, Value), "Undo policy action selection", undo); ScenarioManager.Instance.GetExtension <ScenarioUndoManager>().RegisterRecord(revertActionDropdown); ActionChanged(actionDropdown.options[actionId].text); }
/// <summary> /// Add a single policy entry to this edit panel, registers the undo record /// </summary> public void AddPolicyEntryWithUndo() { var newEntry = ScenarioManager.Instance.prefabsPools.GetInstance(policyEntryPrefab.gameObject) .GetComponent <PolicyEntry>(); var undoRecord = new GenericUndo <PolicyEntry>(newEntry, "Undo adding a policy entry", RemovePolicyEntry); ScenarioManager.Instance.GetExtension <ScenarioUndoManager>().RegisterRecord(undoRecord); AddPolicyEntry(newEntry); }
/// <summary> /// Method called when the value dropdown changes selected option /// </summary> /// <param name="valueId">Selected value option id</param> public void OnValueDropdownChange(int valueId) { var undo = new Action <string>(previousValue => { var id = valueDropdown.options.FindIndex(option => option.text == previousValue); valueDropdown.SetValueWithoutNotify(id); UpdatePolicy(previousValue); }); var revertValueDropdown = new GenericUndo <string>(Value, "Undo policy value selection", undo); ScenarioManager.Instance.GetExtension <ScenarioUndoManager>().RegisterRecord(revertValueDropdown); UpdatePolicy(valueDropdown.options[valueId].text); }
/// <summary> /// Remove the policy entry from this edit panel, registers the undo record /// </summary> /// <param name="entry">Policy entry to be removed</param> public void RemovePolicyEntryWithUndo(PolicyEntry entry) { var undo = new Action<PolicyEntry>(revertedEntry => { entry.gameObject.SetActive(true); entries.Add(entry); UpdatePolicy(); UnityUtilities.LayoutRebuild(transform as RectTransform); }); var dispose = new Action<PolicyEntry>(disposedEntry => { ScenarioManager.Instance.prefabsPools.ReturnInstance(disposedEntry.gameObject); }); var undoRecord = new GenericUndo<PolicyEntry>(entry, "Undo removing a policy entry", undo, dispose); ScenarioManager.Instance.GetExtension<ScenarioUndoManager>().RegisterRecord(undoRecord); RemovePolicyEntry(entry); }