void LoadFromText() { XmlNode _node = DataMakerXmlUtils.StringToXmlNode(source.text); if (_node == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { DataMakerXmlUtils.XmlStoreNode(_node, storeReference.Value); } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { proxy.InjectXmlNode(_node); } if (!xmlString.IsNone) { xmlString.Value = source.text; } Finish(); }
protected bool SetUpDataMakerXmlNodeListProxyPointer(GameObject aProxyGO, string nameReference) { if (aProxyGO == null) { return(false); } proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlNodeListProxy), aProxyGO, nameReference, false) as DataMakerXmlNodeListProxy; return(proxy != null); }
public override void OnEnter() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go != null) { DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (refreshContentFirst.Value) { proxy.RefreshStringVersion(); } xmlString.Value = proxy.content; } } Finish(); }
public override void OnEnter() { if ((!Application.isEditor) && OnlyInEditor) { Finish(); } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go != null) { DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { proxy.RefreshStringVersion(); } } Finish(); }
public override void OnEnter() { GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (!storeReference.IsNone) { proxy.InjectXmlNode(DataMakerXmlUtils.XmlRetrieveNode(storeReference.Value)); } else if (!xmlSource.IsNone) { proxy.InjectXmlString(xmlSource.Value); } } else { Fsm.Event(errorEvent); } Finish(); }
void ConvertFromJsonString() { string _jsonSource = jsonSource.Value; /* fail to check if json root is a list of a single object... odd * // check if json has unique root or not. * try{ * * System.Object _json = (System.Object)JsonConvert.DeserializeObject(_jsonSource, typeof(System.Object)); * }catch(Exception e) * { * Debug.LogError(e.Message); * Fsm.EventData.StringData = e.Message; * Fsm.Event(errorEvent); * return; * } * * bool jsonHasRoot = _jsonSource.Length==1; * * string ForcedRootName = string.IsNullOrEmpty(rootElementName.Value)?"root":rootElementName.Value; * */ XmlDocument _document = new XmlDocument(); try{ //if(!jsonHasRoot || !string.IsNullOrEmpty(rootElementName.Value) || forceRootElementName.Value) if (!string.IsNullOrEmpty(rootElementName.Value)) { _document = JsonConvert.DeserializeXmlNode(_jsonSource, rootElementName.Value); } else { _document = JsonConvert.DeserializeXmlNode(_jsonSource); } }catch (Exception e) { Debug.LogError(e.Message); Fsm.EventData.StringData = e.Message; Fsm.Event(errorEvent); return; } if (_document == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { //DataMakerXmlUtils.XmlStoreNodeList(_document.DocumentElement as XmlNodeList,storeReference.Value); } else { DataMakerXmlUtils.XmlStoreNode(_document.DocumentElement as XmlNode, storeReference.Value); } } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // proxy.InjectXmlNodeList(_document.DocumentElement as XmlNode); } else { proxy.InjectXmlNode(_document.DocumentElement as XmlNode); } } proxy.RefreshStringVersion(); if (!xmlString.IsNone) { xmlString.Value = proxy.content; } Finish(); }
void ConvertFromCsvString() { CsvData _data; if (!delimiter.IsNone) { _data = CsvReader.LoadFromString(csvSource.Value, hasHeader.Value, delimiter.Value [0]); } else { _data = CsvReader.LoadFromString(csvSource.Value, hasHeader.Value); } XmlDocument _document = new XmlDocument(); XmlNode _root = _document.AppendChild(_document.CreateElement("Root")); try{ if (_data.HasHeader) { _csvHeader = _data.HeaderKeys.ToArray(); } foreach (List <string> _row in _data.Data) { XmlNode _xmlRowNode = _document.CreateElement("Record"); for (int i = 0; i < _row.Count; i++) { XmlNode _Item = _document.CreateElement(_data.HasHeader?_csvHeader[i]:"Field"); _Item.InnerText = _row[i]; _xmlRowNode.AppendChild(_Item); } _root.AppendChild(_xmlRowNode); } }catch (Exception e) { Debug.LogError(e.Message); Fsm.EventData.StringData = e.Message; Fsm.Event(errorEvent); return; } if (_document == null) { Debug.LogError(DataMakerXmlUtils.lastError); Fsm.EventData.StringData = DataMakerXmlUtils.lastError; Fsm.Event(errorEvent); return; } if (!storeReference.IsNone) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // DataMakerXmlUtils.XmlStoreNodeList(_document.DocumentElement as XmlNodeList,storeReference.Value); } else { DataMakerXmlUtils.XmlStoreNode(_document.DocumentElement as XmlNode, storeReference.Value); } } GameObject go = Fsm.GetOwnerDefaultTarget(gameObject); if (go != null) { DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), go, reference.Value, false) as DataMakerXmlProxy; if (proxy != null) { if (_document.DocumentElement.GetType() == typeof(XmlNodeList)) { // proxy.InjectXmlNodeList(_document.DocumentElement as XmlNode); } else { proxy.InjectXmlNode(_document.DocumentElement as XmlNode); } } proxy.RefreshStringVersion(); } if (!xmlString.IsNone) { xmlString.Value = DataMakerXmlUtils.XmlNodeToString(_document.DocumentElement as XmlNode); } Finish(); }
public static bool EditFsmXmlSourceField(Fsm fsm, FsmXmlSource source) { source.sourceSelection = EditorGUILayout.Popup("Source selection", source.sourceSelection, source.sourceTypes); if (source.sourceString == null) { source.sourceString = new FsmString(); } source.sourceString.UseVariable = source.sourceSelection == 2; bool showPreview = false; string preview = ""; if (source.sourceSelection == 0) { source._sourceEdit = EditorGUILayout.Foldout(source._sourceEdit, new GUIContent("Edit")); if (source._sourceEdit) { source.sourceString.Value = EditorGUILayout.TextArea(source.sourceString.Value, GUILayout.Height(200)); } } else if (source.sourceSelection == 1) { source.sourcetextAsset = (TextAsset)EditorGUILayout.ObjectField("TextAsset Object", source.sourcetextAsset, typeof(TextAsset), false); if (source.sourcetextAsset != null) { source._sourcePreview = EditorGUILayout.Foldout(source._sourcePreview, new GUIContent("Preview")); showPreview = source._sourcePreview; preview = source.sourcetextAsset.text; } } else if (source.sourceSelection == 2) { source.sourceString = VariableEditor.FsmStringField(new GUIContent("Fsm String"), fsm, source.sourceString, null); if (!source.sourceString.UseVariable) { source.sourceSelection = 0; return(true); } if (!source.sourceString.IsNone) { source._sourcePreview = EditorGUILayout.Foldout(source._sourcePreview, new GUIContent("Preview")); showPreview = source._sourcePreview; preview = source.sourceString.Value; } } else if (source.sourceSelection == 3) { if (source.sourceProxyGameObject == null) { source.sourceProxyGameObject = new FsmGameObject(); source.sourceProxyReference = new FsmString(); } source.sourceProxyGameObject = VariableEditor.FsmGameObjectField(new GUIContent("GameObject"), fsm, source.sourceProxyGameObject); source.sourceProxyReference = VariableEditor.FsmStringField(new GUIContent("Reference"), fsm, source.sourceProxyReference, null); if (source.sourceProxyGameObject != null) { DataMakerXmlProxy proxy = DataMakerCore.GetDataMakerProxyPointer(typeof(DataMakerXmlProxy), source.sourceProxyGameObject.Value, source.sourceProxyReference.Value, true) as DataMakerXmlProxy; if (proxy != null) { if (proxy.XmlTextAsset != null) { source._sourcePreview = EditorGUILayout.Foldout(source._sourcePreview, new GUIContent("Preview")); showPreview = source._sourcePreview; preview = proxy.XmlTextAsset.text; } else { //oupss... } } else { //oupss.. } } } else if (source.sourceSelection == 4) { if (source.inMemoryReference == null) { source.inMemoryReference = new FsmString(); } source.inMemoryReference = VariableEditor.FsmStringField(new GUIContent("Memory Reference"), fsm, source.inMemoryReference, null); if (!string.IsNullOrEmpty(source.inMemoryReference.Value)) { source._sourcePreview = EditorGUILayout.Foldout(source._sourcePreview, new GUIContent("Preview")); showPreview = source._sourcePreview; preview = DataMakerXmlUtils.XmlNodeToString(DataMakerXmlUtils.XmlRetrieveNode(source.inMemoryReference.Value)); } } if (showPreview) { if (string.IsNullOrEmpty(preview)) { GUILayout.Label("-- empty --"); } else { source._scroll = GUILayout.BeginScrollView(source._scroll, "box", GUILayout.Height(200)); GUI.skin.box.alignment = TextAnchor.UpperLeft; GUILayout.Box(preview, "", null); GUILayout.EndScrollView(); } } return(false); }