public bool Open(string filePath) { m_State = GetComponent<State>(); m_RuleBase = GetComponent<RuleBase>(); if (File.Exists(filePath)) { XMLRulesType root; try { XMLRulesDoc doc = new XMLRulesDoc(); root = new XMLRulesType(doc.Load(filePath)); } catch (Exception e) { Debug.Log("Error on Open " + e.ToString()); return false; } m_State.Clear(); m_RuleBase.Clear(); m_RuleBaseFilePath = filePath; m_RuleBase.SetContext(this); m_RuleBase.Load(root.GetRuleBase()); m_State.Load(root.GetRuleBase()); return true; } return false; }
void Awake() { // For some reason scripts instantiated during load never get destroyed // in the switch between edit and playmode. This bit of hack here destroys // any lingering scripts as they will be reloaded in the Open call. BaseScript[] scripts = gameObject.GetComponents<BaseScript>(); foreach (BaseScript script in scripts) GameObject.DestroyImmediate(script); m_State = GetComponent<State>(); m_RuleBase = GetComponent<RuleBase>(); m_RuleBase.SetContext(this); Debug.Log("RuleBase: " + m_RuleBaseFilePath); if (m_RuleBaseFilePath.Length != 0) { Open(m_RuleBaseFilePath); } }
public GraphToRule(State state) { m_State = state; }