private void UpdateStateName() { _editorStateName = "<none>"; switch (_editorLinkType) { case eType.External: { if (_file._editorAsset != null) { TimelineStateMachine stateMachines = SerializeConverter.FromTextAsset <TimelineStateMachine>(_file._editorAsset); TimelineState[] states = stateMachines._states; foreach (TimelineState state in states) { if (state._stateId == _stateId) { _editorStateName = _file._editorAsset.name + ":" + StringUtils.GetFirstLine(state.GetDescription()); break; } } } } break; case eType.Internal: { if (GetTimelineState() != null) { _editorStateName = StringUtils.GetFirstLine(_timelineState.GetDescription()); } } break; } }
public void Save() { if (!string.IsNullOrEmpty(_currentFileName)) { //If we're in state view first need to apply state changes to state machine view if (_currentMode == eMode.ViewingState) { _editedState.GetEditableObject()._timeline = _stateEditor.ConvertToTimeline(); } //Update state machine name to reflect filename TimelineStateMachine stateMachine = ConvertToTimelineStateMachine(); stateMachine._name = System.IO.Path.GetFileNameWithoutExtension(_currentFileName); //Save to file SerializeConverter.ToFile(stateMachine, _currentFileName); ClearDirtyFlag(); _stateEditor.ClearDirtyFlag(); GetEditorWindow().DoRepaint(); //Hack, save string on save scene Localisation.SaveStrings(); } else { SaveAs(); } }
protected override Node CreateCopyFrom(SerializedObjectEditorGUI <Node> editorGUI) { Node newNode = SerializeConverter.CreateCopy(editorGUI.GetEditableObject()); newNode._nodeId = GenerateNewNodeId(); newNode._editorDescription = editorGUI.GetEditableObject()._editorDescription + " (Copy)"; return(newNode); }
public NodeGraph LoadNodeGraph() { if (_file != null) { return(SerializeConverter.FromTextAsset <NodeGraph>(_file)); } return(null); }
public void Test___Method_Convert___Object() { var testee = new SerializeConverter(); Assert.AreEqual("{\"a\":10,\"b\":20}", testee.Convert(new Dictionary <string, int>() { { "a", 10 }, { "b", 20 } })); }
private static bool ValidateMenuLoadTimeline() { TextAsset asset = Selection.activeObject as TextAsset; if (asset != null && !asset.name.StartsWith("TextConv")) { return(SerializeConverter.DoesAssetContainObject <TimelineStateMachine>(asset)); } return(false); }
private static bool ValidateMenuLoadTimeline() { TextAsset asset = Selection.activeObject as TextAsset; if (asset != null) { return(SerializeConverter.DoesAssetContainObject <NodeGraph>(asset)); } return(false); }
private bool DrawStateNamePopUps() { TimelineState[] states = null; switch (_editorLinkType) { case eType.External: { TimelineStateMachine stateMachines = SerializeConverter.FromFile <TimelineStateMachine>(AssetDatabase.GetAssetPath(_file._editorAsset)); states = stateMachines._states; } break; case eType.Internal: { if (_stateMachine != null) { states = _stateMachine._states; } } break; } if (states != null && states.Length > 0) { string[] stateNames = new string[states.Length + 1]; int index = 0; stateNames[0] = "<none>"; for (int i = 0; i < states.Length; i++) { stateNames[i + 1] = "State" + states[i]._stateId + " (" + StringUtils.GetFirstLine(states[i].GetDescription()) + ")"; if (states[i]._stateId == _stateId) { index = i + 1; } } EditorGUI.BeginChangeCheck(); index = EditorGUILayout.Popup("Timeline", index, stateNames); if (EditorGUI.EndChangeCheck()) { _stateId = index == 0 ? -1 : (int)states[index - 1]._stateId; _timelineState = null; _editorStateName = null; return(true); } } return(false); }
public static TimelineStateMachine FromTextAsset(TextAsset asset, GameObject sourceObject = null) { TimelineStateMachine timelineStateMachine = SerializeConverter.FromTextAsset <TimelineStateMachine>(asset); if (sourceObject != null) { GameObjectRef.FixupGameObjectRefs(sourceObject, timelineStateMachine); } return(timelineStateMachine); }
public void Init(string title, IEditorWindow editorWindow, string editorPrefsTag) { _title = title; _editorPrefsTag = editorPrefsTag; string editorPrefsText = EditorPrefs.GetString(_editorPrefsTag, ""); _editorPrefs = SerializeConverter.FromString <NodeGraphEditorPrefs>(editorPrefsText); if (_editorPrefs == null) { _editorPrefs = new NodeGraphEditorPrefs(); } SetEditorWindow(editorWindow); CreateViews(); }
protected override TimelineState CreateCopyFrom(SerializedObjectEditorGUI <TimelineState> editorGUI) { TimelineStateEditorGUI timeLineGUI = (TimelineStateEditorGUI)editorGUI; TimelineState newState = SerializeConverter.CreateCopy(timeLineGUI.GetEditableObject()); if (timeLineGUI.IsNote) { newState._editorDescription = timeLineGUI.GetEditorDescrition(); } else { newState._editorDescription = timeLineGUI.GetEditorDescrition() + " (Copy)"; newState._stateId = GenerateNewStateId(); } return(newState); }
public static void LoadStrings() { _localisationMap = null; TextAsset asset = Resources.Load(kDefaultLocalisationFilePath) as TextAsset; if (asset != null) { _localisationMap = SerializeConverter.FromTextAsset <LocalisationMap>(asset); } else { _localisationMap = new LocalisationMap(); } #if UNITY_EDITOR RefreshEditorKeys(); #endif }
public static void SaveStrings() { if (_localisationMap != null) { string path; TextAsset asset = Resources.Load(kDefaultLocalisationFilePath) as TextAsset; if (asset != null) { path = AssetDatabase.GetAssetPath(asset); } else { path = Application.dataPath + "/Resources/" + kDefaultLocalisationFilePath + ".xml"; } SerializeConverter.ToFile(_localisationMap, path); } }
private void UndoRedoCallback() { if (this != null) { if (!string.IsNullOrEmpty(_undoObjectXml) && _editableObject != null) { _editableObject = (T)SerializeConverter.FromString(_editableObject.GetType(), _undoObjectXml); if (_editableObject == null) { throw new Exception(); } _undoObjectXml = null; GetEditor().SetNeedsRepaint(); MarkAsDirty(true); } } }
public void RenderProperties() { if (_editableObject == null) { throw new Exception(); } //If store an undo command on a temp string representing event, then on undo performed callback recreate event from string. string undoObjectXml = SerializeConverter.ToString(_editableObject); if (RenderObjectProperties(GUIContent.none)) { _undoObjectXml = undoObjectXml; Undo.RegisterCompleteObjectUndo(this, GetEditableObject().GetType().Name + " changed"); SaveUndoState(); GetEditor().SetNeedsRepaint(); MarkAsDirty(true); } }
public void Init(string title, IEditorWindow editorWindow, string editorPrefsTag, Type[] allowedTypes, TimelineStateMachineEditorStyle style, TimelineScrollArea.eTimeFormat timeFormat = TimelineScrollArea.eTimeFormat.Seconds) { _title = title; _editorPrefsTag = editorPrefsTag; _allowedEvents = allowedTypes; _style = style; _timeFormat = timeFormat; string editorPrefsText = EditorPrefs.GetString(_editorPrefsTag, ""); _editorPrefs = SerializeConverter.FromString <TimelineStateMachineEditorPrefs>(editorPrefsText); if (_editorPrefs == null) { _editorPrefs = new TimelineStateMachineEditorPrefs(); } SetEditorWindow(editorWindow); CreateViews(); }
public void Save() { if (!string.IsNullOrEmpty(_currentFileName)) { //Save to file NodeGraph nodeGraph = ConvertToNodeGraph(); SerializeConverter.ToFile(nodeGraph, _currentFileName); ClearDirtyFlag(); foreach (NodeEditorGUI node in _editableObjects) { node.MarkAsDirty(false); } GetEditorWindow().DoRepaint(); } else { SaveAs(); } }
private void LoadFile(string fileName) { _currentFileName = fileName; TimelineStateMachine stateMachine = SerializeConverter.FromFile <TimelineStateMachine>(fileName); if (stateMachine != null) { if (_editorPrefs._fileName != fileName) { _editorPrefs._fileName = fileName; _editorPrefs._stateId = -1; SaveEditorPrefs(); } SetStateMachine(stateMachine); _stateEditor.SetTimeline(null); if (_editorPrefs._stateId != -1) { SwitchToStateView(_editorPrefs._stateId); } else { SwitchToStatemachineView(); } } else { _editorPrefs._fileName = null; _editorPrefs._stateId = -1; SaveEditorPrefs(); } GetEditorWindow().DoRepaint(); }
private void LoadFile(string fileName) { _currentFileName = fileName; NodeGraph nodeMachine = SerializeConverter.FromFile <NodeGraph>(fileName); if (nodeMachine != null) { if (_editorPrefs._fileName != fileName) { _editorPrefs._fileName = fileName; SaveEditorPrefs(); } SetNodeGraph(nodeMachine); } else { _editorPrefs._fileName = null; SaveEditorPrefs(); } GetEditorWindow().DoRepaint(); }
private void SaveEditorPrefs() { string prefsXml = SerializeConverter.ToString(_editorPrefs); EditorPrefs.SetString(_editorPrefsTag, prefsXml); }
public void SaveUndoState() { _undoObjectXml = SerializeConverter.ToString(_editableObject); }
protected override Event CreateCopyFrom(SerializedObjectEditorGUI <Event> editorGUI) { return(SerializeConverter.CreateCopy(editorGUI.GetEditableObject())); }
public void Test___Method_Convert___Array() { var testee = new SerializeConverter(); Assert.AreEqual("[10,20]", testee.Convert(new int[] { 10, 20 })); }