void OnDestroy() { if (_machine != null) { _machine.Dispose(); } _machine = null; }
private UMachine RestoreFlow(string[] state, Dictionary <string, UMachine> machines) { // Corrupted state; early out int len = state?.Length ?? 0; if (len < 1) { return(null); } DirectedGraph <UStateNode> graph; string[] stateStr = state[0].Split('#'); // Couldn't find graph; early out if (stateStr.Length < 1 || !_flows.TryGetValue(stateStr[0], out graph)) { return(null); } string machineID = stateStr[0]; int[] init = new int[len - 1]; Dictionary <int, UMachine> subflows = new Dictionary <int, UMachine>(); UMachine machine; UMachine result = Instantiate(machineID); for (int i = 0; i < len - 1; ++i) { stateStr = state[i + 1].Split(':'); init[i] = int.Parse(stateStr[0]); if (stateStr.Length > 1) { // subflows are states that contain other machines // subflows need to be rebuilt before flows that depend on them if (machines.TryGetValue(stateStr[1], out machine)) { machine._Flow = result; machine.ID = graph.Nodes[init[i]].ID; subflows[init[i]] = machine; } else { return(null); // Not all machines instantiated; early out } } } if (result.RestoreStates(state, subflows)) { return(result); } result.Dispose(); return(null); }