コード例 #1
0
        public bool Open(string filePath)
        {
            m_State    = GetComponent <State>();
            m_RuleBase = GetComponent <RuleBase>();


            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);
        }
コード例 #2
0
        public void ShowGUI()
        {
            GUI.backgroundColor = new Color(0.7f, 0.7f, 0.7f);

            GUI.backgroundColor = new Color(0.8f, 0.8f, 1);

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Open", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false)))
            {
                string filePath = EditorUtility.OpenFilePanel("Choose RuleBase", Application.dataPath, "xml");
                if (filePath != null)
                {
                    Open(filePath);
                }
            }

            if (GUILayout.Button("Save", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false)))
            {
                if (m_RuleBaseFilePath == String.Empty)
                {
                    string filePath = EditorUtility.SaveFilePanel("Save RuleBase As", Application.dataPath, m_RuleBaseFilePath, "xml");

                    if (filePath != String.Empty)
                    {
                        m_RuleBaseFilePath = filePath;
                        m_RuleBase.DebugMessage("Saving to " + filePath);
                        Save(filePath);
                    }
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Save new Rulebase " + m_RuleBaseFilePath, "Are you sure?", "Yes", "No"))
                    {
                        Save(m_RuleBaseFilePath);
                    }
                }
            }

            if (GUILayout.Button("Save As..", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false)))
            {
                string filePath = EditorUtility.SaveFilePanel("Save RuleBase As", Application.dataPath, m_RuleBaseFilePath, "xml");

                if (filePath != String.Empty)
                {
                    m_RuleBaseFilePath = filePath;
                    m_RuleBase.DebugMessage("Saving to " + filePath);
                    Save(filePath);
                }
            }

            if (GUILayout.Button("New", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false)))
            {
                m_RuleBaseFilePath = String.Empty;
                m_State.Clear();
                m_RuleBase.Clear();
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUI.color = Color.yellow;
            GUILayout.Label("RuleBase", GUILayout.MaxWidth(100), GUILayout.ExpandWidth(false));
            GUI.color          = Color.white;
            m_RuleBaseFilePath = GUILayout.TextField(m_RuleBaseFilePath, GUILayout.MaxWidth(100), GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("RuleBase Tick (ms):", GUILayout.MaxWidth(120), GUILayout.ExpandWidth(false));
            m_RuleBaseTick = EditorGUILayout.IntSlider(m_RuleBaseTick, 0, 5000, GUILayout.MaxWidth(50), GUILayout.ExpandWidth(false));
            GUILayout.EndHorizontal();
        }
コード例 #3
0
		public bool Open(string filePath)
		{
			m_State = GetComponent<State>();
			m_RuleBase = GetComponent<RuleBase>();
			
			
			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;
			
			
		}