private void LoadFile(string fileName)
                {
                    _currentFileName = fileName;

                    StateMachine stateMachine = null;

                    try
                    {
                        stateMachine = Serializer.FromFile <StateMachine>(fileName);
                    }
                    catch (ObjectNotFoundException)
                    {
                        EditorUtility.DisplayDialog("StateMachine Editor", AssetUtils.GetAssetPath(_currentFileName) + " does not contain a valid StateMachine.", "Ok");
                    }
                    catch (CorruptFileException)
                    {
                        EditorUtility.DisplayDialog("StateMachine Editor", AssetUtils.GetAssetPath(_currentFileName) + " is corrupt.", "Ok");
                    }


                    if (stateMachine != null)
                    {
                        if (_editorPrefs._fileName != fileName)
                        {
                            _editorPrefs._fileName = fileName;
                            _editorPrefs._stateId  = -1;
                            SaveEditorPrefs();
                        }

                        SetStateMachine(stateMachine);
                        _timelineEditor.SetTimeline(null);

                        if (_editorPrefs._stateId != -1)
                        {
                            ShowStateDetails(_editorPrefs._stateId);
                        }
                        else
                        {
                            SwitchToStatemachineView();
                        }
                    }
                    else
                    {
                        _editorPrefs._fileName = null;
                        _editorPrefs._stateId  = -1;
                        SaveEditorPrefs();
                    }

                    GetEditorWindow().DoRepaint();
                }
Esempio n. 2
0
                private void LoadFile(string fileName)
                {
                    _currentFileName = fileName;
                    NodeGraph nodeMachine = null;

                    try
                    {
                        nodeMachine = Serializer.FromFile <NodeGraph>(fileName);
                    }
                    catch (ObjectNotFoundException)
                    {
                        EditorUtility.DisplayDialog("Node Graph Editor", AssetUtils.GetAssetPath(_currentFileName) + " does not contain a valid Node Graph.", "Ok");
                    }
                    catch (CorruptFileException)
                    {
                        EditorUtility.DisplayDialog("Node Graph Editor", AssetUtils.GetAssetPath(_currentFileName) + " is corrupt.", "Ok");
                    }

                    if (nodeMachine != null)
                    {
                        if (_editorPrefs._fileName != fileName)
                        {
                            _editorPrefs._fileName = fileName;
                            SaveEditorPrefs();
                        }

                        SetNodeGraph(nodeMachine);
                    }
                    else
                    {
                        _editorPrefs._fileName = null;
                        SaveEditorPrefs();
                    }

                    GetEditorWindow().DoRepaint();
                }
Esempio n. 3
0
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical();
                    {
                        //Load save
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                                UpdateKeys();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._tableFontSize, kMinFontSize, kMaxFontSize);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                            }

                            if (_editorPrefs._tableFontSize != fontSize)
                            {
                                _editorPrefs._tableFontSize = fontSize;
                                _textStyle.fontSize         = _editorPrefs._tableFontSize;
                                _selectedTextStyle.fontSize = _editorPrefs._tableFontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter, EditorStyles.toolbarSearchField);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                                UpdateKeys();
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                UpdateKeys();
                                SelectKey(_editorPrefs._selectedKeys);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");

                                if (!string.IsNullOrEmpty(folder))
                                {
                                    LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                    AssetDatabase.SaveAssets();
                                    Localisation.ReloadStrings(true);
                                    _needsRepaint = true;
                                }
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                        {
                            float keyWidth           = _editorPrefs._keyWidth - (kResizerWidth * 0.5f);
                            float firstLanguageWidth = _editorPrefs._firstLanguageWidth - kResizerWidth;
                            float secondLangWidth    = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            keyWidth -= _scrollPosition.x;

                            //Key
                            if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.Width(Mathf.Max(keyWidth, 0f))))
                            {
                                _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                            }

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Current Language
                            string label = "Current Language (" + Localisation.GetCurrentLanguage().ToString() + ")";
                            if (GUILayout.Button(label, EditorStyles.toolbarButton, GUILayout.Width(firstLanguageWidth)))
                            {
                                GenericMenu menu = new GenericMenu();

                                foreach (SystemLanguage lang in Enum.GetValues(typeof(SystemLanguage)))
                                {
                                    menu.AddItem(new GUIContent(lang.ToString()), false, OnChangeCurrentLanguage, lang);
                                }

                                menu.ShowAsContext();
                            }

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            EditorGUI.BeginChangeCheck();
                            SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarPopup, GUILayout.Width(secondLangWidth));
                            if (EditorGUI.EndChangeCheck())
                            {
                                //Unload the strings if second language is not current
                                if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                }

                                _editorPrefs._secondLanguage = language;

                                //If new language isn't current load strings
                                if (language != Localisation.GetCurrentLanguage())
                                {
                                    Localisation.LoadStrings(language);
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                private void RenderTitleBar()
                {
                    EditorGUILayout.BeginVertical(GUILayout.Height(kToolBarHeight));
                    {
                        //Title
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            string titleText = kWindowTitle + " - <b>Localisation.xml</b>";

                            if (Localisation.HasUnsavedChanges())
                            {
                                titleText += "<b>*</b>";
                            }

                            EditorGUILayout.LabelField(titleText, _titleStyle);
                        }
                        EditorGUILayout.EndHorizontal();

                        //Load save
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            if (GUILayout.Button("Save", EditorStyles.toolbarButton))
                            {
                                Localisation.SaveStrings();
                            }

                            if (GUILayout.Button("Reload", EditorStyles.toolbarButton))
                            {
                                Localisation.ReloadStrings();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Scale", EditorStyles.toolbarButton);

                            int fontSize = EditorGUILayout.IntSlider(_editorPrefs._fontSize, 8, 16);

                            if (GUILayout.Button("Reset Scale", EditorStyles.toolbarButton))
                            {
                                fontSize = kDefaultFontSize;
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (_editorPrefs._fontSize != fontSize)
                            {
                                _editorPrefs._fontSize = fontSize;
                                _keyStyle.fontSize     = _editorPrefs._fontSize;
                                _textStyle.fontSize    = _editorPrefs._fontSize;
                                SaveEditorPrefs();
                            }

                            EditorGUILayout.Separator();

                            GUILayout.Button("Font", EditorStyles.toolbarButton);

                            Font currentFont = _editorPrefs._font.GetAsset();
                            Font font        = (Font)EditorGUILayout.ObjectField(currentFont, typeof(Font), false);

                            if (currentFont != font)
                            {
                                _editorPrefs._font = new EditorAssetRef <Font>(font);

                                if (font == null)
                                {
                                    _textStyle.font = _keyStyle.font;
                                }
                                else
                                {
                                    _textStyle.font = font;
                                }

                                SaveEditorPrefs();
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Filters
                        EditorGUILayout.BeginHorizontal(_toolbarStyle);
                        {
                            GUILayout.Button("Filter", EditorStyles.toolbarButton);

                            EditorGUI.BeginChangeCheck();
                            _filter = EditorGUILayout.TextField(_filter);
                            if (EditorGUI.EndChangeCheck())
                            {
                                _needsRepaint = true;
                            }

                            if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                            {
                                _filter = "";
                                EditorGUI.FocusTextInControl(string.Empty);
                            }

                            if (GUILayout.Button("Choose Localisation Folder", EditorStyles.toolbarButton))
                            {
                                string folder = LocalisationProjectSettings.Get()._localisationFolder;
                                folder = EditorUtility.OpenFolderPanel("Choose Localisation Folder", folder, "");
                                LocalisationProjectSettings.Get()._localisationFolder = AssetUtils.GetAssetPath(folder);
                                AssetDatabase.SaveAssets();
                                Localisation.ReloadStrings(true);
                                _needsRepaint = true;
                            }

                            GUILayout.FlexibleSpace();
                        }
                        EditorGUILayout.EndHorizontal();

                        //Headers
                        EditorGUILayout.BeginHorizontal();
                        {
                            //Key
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._keyWidth - 3));
                            {
                                if (GUILayout.Button("Key", EditorStyles.toolbarButton, GUILayout.ExpandWidth(true)))
                                {
                                    _sortOrder = _sortOrder == eKeySortOrder.Desc ? eKeySortOrder.Asc : eKeySortOrder.Desc;
                                }
                            }
                            EditorGUILayout.EndHorizontal();

                            //Keys Resizer
                            RenderResizer(ref _keysResizerRect);

                            //Text
                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(_editorPrefs._firstLanguageWidth - 3));
                            {
                                //First Language
                                GUILayout.Button(Localisation.GetCurrentLanguage().ToString(), EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
                            }
                            EditorGUILayout.EndHorizontal();

                            //Language Resizer
                            RenderResizer(ref _languageResizerRect);

                            //Second Language
                            float secondLangWidth = position.width - _editorPrefs._keyWidth - _editorPrefs._firstLanguageWidth;

                            EditorGUILayout.BeginHorizontal(_toolbarStyle, GUILayout.Width(secondLangWidth));
                            {
                                EditorGUI.BeginChangeCheck();
                                SystemLanguage language = (SystemLanguage)EditorGUILayout.EnumPopup(_editorPrefs._secondLanguage, EditorStyles.toolbarButton);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (_editorPrefs._secondLanguage != Localisation.GetCurrentLanguage())
                                    {
                                        Localisation.UnloadStrings(_editorPrefs._secondLanguage);
                                    }

                                    _editorPrefs._secondLanguage = language;
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
Esempio n. 5
0
 public void OnQuit()
 {
     if (HasChanges())
     {
         if (EditorUtility.DisplayDialog("Node Machine Has Been Modified", "Do you want to save the changes you made to the node machine:\n\n" + AssetUtils.GetAssetPath(_currentFileName) + "\n\nYour changes will be lost if you don't save them.", "Save", "Don't Save"))
         {
             Save();
         }
     }
 }
Esempio n. 6
0
                private bool ShowOnLoadSaveChangesDialog()
                {
                    if (HasChanges())
                    {
                        int option = EditorUtility.DisplayDialogComplex("Node Machine Has Been Modified", "Do you want to save the changes you made to the node machine:\n\n" + AssetUtils.GetAssetPath(_currentFileName) + "\n\nYour changes will be lost if you don't save them.", "Save", "Don't Save", "Cancel");

                        switch (option)
                        {
                        //Save
                        case 0: Save(); return(true);

                        //Don't save
                        case 1: return(true);

                        //Cancel load
                        default:
                        case 2: return(false);
                        }
                    }

                    return(true);
                }
Esempio n. 7
0
 public string GetAssetFilePath()
 {
     return(AssetUtils.GetAssetPath(_filePath));
 }