static void AddActionWindow() { if (editingEvent == null) { addActionClicked = false; Debug.LogWarning("The event you are trying to add to is null"); } else if (editingEvent.eventName == null) { addActionClicked = false; Debug.LogWarning("The event you are trying to add to is null"); } GUILayout.Label("Add Action", "boldLabel"); List <string> options = new List <string>(); List <System.Type> types = ActionTracker.FindActions(); foreach (System.Type type in types) { options.Add(type.Name); } selectedNewAction = EditorGUILayout.Popup("Action to Add", selectedNewAction, options.ToArray()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Cancel")) { addActionClicked = false; } if (GUILayout.Button("Add Action")) { addActionClicked = false; Action newAction = null; //TODO: automatically create the object? newAction = (Action)AssetDatabase.LoadAssetAtPath(EventSaver.TOOL_DATA_DIR + options[selectedNewAction] + ".asset", typeof(ScriptableObject)); if (newAction == null) { Debug.LogError("Could not load asset at: " + EventSaver.TOOL_DATA_DIR + options[selectedNewAction]); } newAction = ScriptableObject.Instantiate(newAction);//DISCUSS: memory leak or auto-collected? editingEvent.AddAction(newAction); Debug.Log("Created Action: " + newAction.ToString()); EventSaver.SaveEventAsObject(editingEvent); } GUILayout.EndHorizontal(); }
public static Event LoadEventAsXML(string fileName) { Debug.Log("Attempting to Load: " + fileName); Event _loadedEvent = (SpellCreator.Event)ScriptableObject.CreateInstance(typeof(SpellCreator.Event)); _loadedEvent.eventName = fileName; _loadedEvent.name = _loadedEvent.eventName; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(SAVED_DATA_DIR + fileName + ".xml"); foreach (XmlNode action in xmlDocument.FirstChild.ChildNodes) { Action newAction = null; System.Type actionType = null; string actionName = action.FirstChild.InnerText; actionName = actionName.Replace("(Clone)", ""); newAction = (Action)AssetDatabase.LoadAssetAtPath(TOOL_DATA_DIR + actionName + ".asset", typeof(Action)); if (newAction == null) { Debug.LogError("Could not load action: " + TOOL_DATA_DIR + actionName); return(null); } actionType = newAction.GetType(); if (actionType == null) { Debug.LogError("Action Type Not Recognized: " + actionName); break; } newAction = ScriptableObject.Instantiate(newAction); _loadedEvent.AddAction(newAction); foreach (XmlNode actionInfo in action.ChildNodes) { if (actionInfo != actionInfo.FirstChild) { if (actionInfo.Name != "Modifier" && actionInfo.Name != "ActionName") { //Reflection //f i x more parsing types FieldInfo fieldinfo = actionType.GetField(actionInfo.Name); object o = System.Convert.ChangeType(actionInfo.InnerText, fieldinfo.FieldType); fieldinfo.SetValue(newAction, o); } else { foreach (XmlNode modifierInfo in actionInfo.ChildNodes) { //DO: Modifier Loading Logic } } } } } return(_loadedEvent); }