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(); }
void Refresh() { //Debug.Log("refresh"); DataMakerXmlProxy _target = target as DataMakerXmlProxy; _target.isDirty = false; if (_target.xmlNode != null) { /* * if (_target.XmlTextAsset!=null) * { * DataMakerEditorGUILayoutUtils.feedbackLabel("XML DATA CHANGED.",DataMakerEditorGUILayoutUtils.labelFeedbacks.WARNING); * } */ if (node == null || (!node.Equals(_target.xmlNode))) { node = _target.xmlNode; _target.content = DataMakerXmlUtils.XmlNodeToString(_target.xmlNode); empty = string.IsNullOrEmpty(_target.content); //Debug.Log("PARSING XML NODE"); valid = DataMakerXmlUtils.StringToXmlNode(_target.content) != null; } return; } if (_target.XmlTextAsset != null) { empty = string.IsNullOrEmpty(_target.XmlTextAsset.text); if (!empty || _target.content == null || !_target.content.Equals(_target.XmlTextAsset.text)) { _target.content = _target.XmlTextAsset.text; //Debug.Log("PARSING TEXT ASSET: \n"+_target.XmlTextAsset.text); valid = DataMakerXmlUtils.StringToXmlNode(_target.content) != 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); }
public override void OnInspectorGUI() { //DrawDefaultInspector(); DataMakerXmlProxy _target = target as DataMakerXmlProxy; _target.referenceName = EditorGUILayout.TextField(new GUIContent("Reference"), _target.referenceName); _target.FsmEventTarget = EditorGUILayout.ObjectField(new GUIContent("Fsm Event Target"), _target.FsmEventTarget, typeof(PlayMakerFSM), true) as PlayMakerFSM; if (_target.isDirty) { Refresh(); } if (!Application.isPlaying) { if (_target.useSource) { if (GUILayout.Button("Don't use Text Asset")) { _target.content = null; node = null; empty = true; _target.XmlTextAsset = null; _target.useSource = false; } TextAsset _asset = (TextAsset)EditorGUILayout.ObjectField(new GUIContent("Text Asset"), _target.XmlTextAsset, typeof(TextAsset), false); if (_asset != _target.XmlTextAsset) { _target.XmlTextAsset = _asset; Refresh(); } GUILayout.Label("This proxy also accepts runtime xml results."); GUILayout.Label("i.e Use actions like XMlSaveInProxy"); } else { GUILayout.Label("This proxy accepts runtime xml results"); GUILayout.Label("i.e Use actions like XMlSaveInProxy"); GUILayout.Label("But you can also use this proxy as a source"); if (GUILayout.Button("Use Text Asset")) { _target.content = null; node = null; empty = true; _target.useSource = true; } } } else { if (_target.useSource) { TextAsset _asset = (TextAsset)EditorGUILayout.ObjectField(new GUIContent("Text Asset"), _target.XmlTextAsset, typeof(TextAsset), false); if (_asset != _target.XmlTextAsset) { _target.XmlTextAsset = _asset; Refresh(); } } else { empty = _target.xmlNode == null; } } if (empty) { DataMakerEditorGUILayoutUtils.feedbackLabel("No XML data", DataMakerEditorGUILayoutUtils.labelFeedbacks.WARNING); } else { if (!valid) { DataMakerEditorGUILayoutUtils.feedbackLabel("Xml Invalid", DataMakerEditorGUILayoutUtils.labelFeedbacks.ERROR); } else { DataMakerEditorGUILayoutUtils.feedbackLabel("Xml Valid", DataMakerEditorGUILayoutUtils.labelFeedbacks.OK); } _scroll = DataMakerEditorGUILayoutUtils.StringContentPreview(_scroll, _target.content); if (GUILayout.Button("Refresh")) { _target.RefreshStringVersion(); } if (_target.XmlTextAsset != null) { if (GUILayout.Button("Save back to Text Asset file: " + _target.XmlTextAsset.name)) { string assetPath = AssetDatabase.GetAssetPath(_target.XmlTextAsset.GetInstanceID()); string path = Application.dataPath + assetPath.Substring(6); Debug.Log(path + "/n" + _target.content); File.WriteAllText(path, _target.content); AssetDatabase.LoadAssetAtPath(assetPath, typeof(TextAsset)); AssetDatabase.Refresh(); } } } if (GUI.changed) { EditorUtility.SetDirty(target); } }
public override void OnInspectorGUI() { //DrawDefaultInspector(); DataMakerXmlProxy _target = target as DataMakerXmlProxy; _target.referenceName = EditorGUILayout.TextField(new GUIContent("Reference"), _target.referenceName); if (!Application.isPlaying) { if (_target.useSource) { if (GUILayout.Button("Don't use Text Asset")) { content = null; node = null; empty = true; _target.XmlTextAsset = null; _target.useSource = false; } _target.XmlTextAsset = (TextAsset)EditorGUILayout.ObjectField(new GUIContent("Text Asset"), _target.XmlTextAsset, typeof(TextAsset), false); GUILayout.Label("This proxy also accepts runtime xml results."); GUILayout.Label("i.e Use actions like XMlSaveInProxy"); } else { GUILayout.Label("This proxy accepts runtime xml results"); GUILayout.Label("i.e Use actions like XMlSaveInProxy"); GUILayout.Label("But you can also use this proxy as a source"); if (GUILayout.Button("Use Text Asset")) { content = null; node = null; empty = true; _target.useSource = true; } } } else { if (_target.useSource) { _target.XmlTextAsset = (TextAsset)EditorGUILayout.ObjectField(new GUIContent("Text Asset"), _target.XmlTextAsset, typeof(TextAsset), false); } } if (_target.xmlNode != null) { /* * if (_target.XmlTextAsset!=null) * { * DataMakerEditorGUILayoutUtils.feedbackLabel("XML DATA CHANGED.",DataMakerEditorGUILayoutUtils.labelFeedbacks.WARNING); * } */ if (node == null || (!node.Equals(_target.xmlNode))) { node = _target.xmlNode; content = DataMakerXmlUtils.XmlNodeToString(_target.xmlNode); empty = string.IsNullOrEmpty(content); Debug.Log("PARSING XML NODE"); valid = DataMakerXmlUtils.StringToXmlNode(content) != null; } } else if (_target.XmlTextAsset != null) { if (content == null || !content.Equals(_target.XmlTextAsset.text)) { content = _target.XmlTextAsset.text; empty = string.IsNullOrEmpty(content); //Debug.Log("PARSING TEXT ASSET"); valid = DataMakerXmlUtils.StringToXmlNode(content) != null; } } if (empty) { DataMakerEditorGUILayoutUtils.feedbackLabel("No XML data", DataMakerEditorGUILayoutUtils.labelFeedbacks.WARNING); } else { if (!valid) { DataMakerEditorGUILayoutUtils.feedbackLabel("Xml Invalid", DataMakerEditorGUILayoutUtils.labelFeedbacks.ERROR); } else { DataMakerEditorGUILayoutUtils.feedbackLabel("Xml Valid", DataMakerEditorGUILayoutUtils.labelFeedbacks.OK); } _scroll = DataMakerEditorGUILayoutUtils.StringContentPreview(_scroll, content); } if (GUI.changed) { EditorUtility.SetDirty(target); } }