void OnInspectorUpdate()
        {
            Repaint();

#if UNITY_2017_1_OR_NEWER
            if (EditorApplication.isCompiling == false)
            {
                SteamVR_Input_Generator.OnEditorUpdate();
            }
#endif
        }
        private void SaveFile()
        {
            SteamVR_Input.actionFile.SaveHelperLists();

            SteamVR_Input.actionFile.Save(SteamVR_Input.GetActionsFilePath());

            SteamVR_Input_ActionManifest_Manager.CleanBindings(true);

            Debug.Log("<b>[SteamVR Input]</b> Saved actions manifest successfully.");

            SteamVR_Input_Generator.BeginGeneration();
        }
        private void OnGUI()
        {
            SteamVR_Input.InitializeFile();

            EditorGUILayout.LabelField(string.Format("File path: {0}", SteamVR_Input.actionsFilePath));


            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            DrawOverwriteOption();

            DrawDeleteUnusedActions();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            bool delete = GUILayout.Button("Delete input classes");

            GUILayout.FlexibleSpace();
            bool deleteActions = GUILayout.Button("Delete input actions");

            GUILayout.FlexibleSpace();
            bool showSettings = GUILayout.Button("SteamVR Settings");

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

            if (delete)
            {
                bool confirm = EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to delete the input code files? This may make your project unable to compile.", "Delete", "Cancel");
                if (confirm)
                {
                    SteamVR_Input_Generator.DeleteActionClassFiles();
                }
            }

            if (deleteActions)
            {
                bool confirm = EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to delete the input action files? This will remove all references in your project to these actions.", "Delete", "Cancel");
                if (confirm)
                {
                    SteamVR_Input_Generator.DeleteActionObjects("*.asset");
                }
            }

            if (showSettings)
            {
                Selection.activeObject = SteamVR_Settings.instance;
            }
        }
 private void UpdateProgressBar()
 {
     UpdateProgressBarTextFromPrefs();
     if (string.IsNullOrEmpty(progressBarText) == false)
     {
         bool cancel = EditorUtility.DisplayCancelableProgressBar(progressBarTitle, progressBarText, progressBarAmount);
         if (cancel)
         {
             SteamVR_Input_Generator.CancelGeneration();
             ClearProgressBar();
         }
     }
 }
Пример #5
0
        protected static void ImportPartialBinding(SteamVR_PartialInputBindings partialBinding)
        {
            SteamVR_Input.InitializeFile();
            SteamVR_Input_ActionFile currentActionsFile = SteamVR_Input.actionFile;

            SteamVR_Input_ActionFile newActionsFile =
                ReadJson <SteamVR_Input_ActionFile>(partialBinding.GetActionsPath());

            /*
             * int sets = ImportActionSets(currentActionsFile, newActionsFile);
             * int locs = ImportLocalization(currentActionsFile, newActionsFile, partialBinding);
             * int actions = ImportActions(currentActionsFile, newActionsFile);
             */

            ImportActionSets(currentActionsFile, newActionsFile);
            ImportLocalization(currentActionsFile, newActionsFile, partialBinding);
            ImportActions(currentActionsFile, newActionsFile);

            if (SteamVR_Input.HasFileInMemoryBeenModified())
            {
                SteamVR_Input.actionFile.Save(SteamVR_Input.actionsFilePath);

                Debug.Log("<b>[SteamVR]</b> Saved new actions file: " + SteamVR_Input.actionsFilePath);
            }

            ImportBindings(currentActionsFile, newActionsFile, partialBinding.GetDirectory());

            partialBinding.imported = true;
            partialBinding.Save();

            SteamVR_Input.InitializeFile(true);
            SteamVR_Input_EditorWindow.ReopenWindow();

            //todo: ask first?

            /*string dialogText = string.Format("{0} new action sets, {1} new actions, and {2} new localization strings have been added. Would you like to regenerate SteamVR Input code files?", sets, actions, locs);
             *
             * bool confirm = EditorUtility.DisplayDialog("SteamVR Input", dialogText, "Generate", "Cancel");
             * if (confirm)
             *  SteamVR_Input_Generator.BeginGeneration();
             */

            SteamVR_Input_Generator.BeginGeneration();

            Debug.Log("<b>[SteamVR]</b> Reloaded actions file with additional actions from " + partialBinding.name);
        }
        protected static void ReplaceBinding(SteamVR_PartialInputBindings partialBinding)
        {
            SteamVR_Input.DeleteManifestAndBindings();

            string newActionsFilePath = partialBinding.GetActionsPath();

            if (File.Exists(newActionsFilePath))
            {
                File.Copy(newActionsFilePath, SteamVR_Input.GetActionsFilePath());
            }

            string bindingsFolder = SteamVR_Input.GetActionsFileFolder();

            SteamVR_Input_ActionFile newActionsFile = ReadJson <SteamVR_Input_ActionFile>(SteamVR_Input.GetActionsFilePath());
            string partialBindingDirectory          = partialBinding.GetDirectory();

            foreach (var newDefaultPath in newActionsFile.default_bindings)
            {
                string bindingPath    = Path.Combine(partialBindingDirectory, newDefaultPath.binding_url);
                string newBindingPath = Path.Combine(bindingsFolder, newDefaultPath.binding_url);
                File.Copy(bindingPath, newBindingPath, true);
            }

            partialBinding.imported = true;
            partialBinding.Save();

            SteamVR_Input.InitializeFile(true);
            SteamVR_Input_EditorWindow.ReopenWindow();

            //todo: ask first?

            /*string dialogText = string.Format("{0} new action sets, {1} new actions, and {2} new localization strings have been added. Would you like to regenerate SteamVR Input code files?", sets, actions, locs);
             *
             * bool confirm = EditorUtility.DisplayDialog("SteamVR Input", dialogText, "Generate", "Cancel");
             * if (confirm)
             *  SteamVR_Input_Generator.BeginGeneration();
             */

            SteamVR_Input_Generator.BeginGeneration();

            Debug.Log("<b>[SteamVR Input]</b> Reloaded with new actions from " + partialBinding.name);
        }
        private void SaveFile()
        {
            FileInfo existingActionsFile = new FileInfo(SteamVR_Input.actionsFilePath);

            if (existingActionsFile.Exists)
            {
                existingActionsFile.IsReadOnly = false;
            }

            SteamVR_Input.actionFile.SaveHelperLists();

            //SanitizeActionFile(); //todo: shouldn't we be doing this?

            string json = JsonConvert.SerializeObject(SteamVR_Input.actionFile, Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            File.WriteAllText(SteamVR_Input.actionsFilePath, json);

            Debug.Log("[SteamVR Input] Saved actions manifest successfully.");

            SteamVR_Input_Generator.BeginGeneration();
        }
        private void OnGUI()
        {
            if (headerLabelStyle == null)
            {
                headerLabelStyle = new GUIStyle(EditorStyles.boldLabel);
            }
            if (multiLineStyle == null)
            {
                multiLineStyle = new GUIStyle(EditorStyles.wordWrappedLabel);
            }
            if (smallMultiLineStyle == null)
            {
                smallMultiLineStyle           = new GUIStyle(EditorStyles.wordWrappedLabel);
                smallMultiLineStyle.fontSize  = EditorStyles.miniLabel.fontSize;
                smallMultiLineStyle.fontStyle = FontStyle.Italic;
            }

            SteamVR_Input.InitializeFile();
            EditorGUILayout.Space();


            EditorGUILayout.LabelField("Actions manifest", headerLabelStyle);
            EditorGUILayout.LabelField(string.Format("Path: {0}", SteamVR_Input.GetActionsFilePath(true)));

            DrawRefreshButton();


            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            DrawPartial();


            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            DrawOverwriteOption();

            DrawDeleteUnusedActions();

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            bool delete = GUILayout.Button("Delete generated input folder");

            GUILayout.FlexibleSpace();
            bool showSettings = GUILayout.Button("SteamVR Settings");

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

            if (delete)
            {
                bool confirm = EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to delete the input code files? This may make your project unable to compile.", "Delete", "Cancel");
                if (confirm)
                {
                    SteamVR_Input_Generator.DeleteGeneratedFolder();
                }
            }

            if (showSettings)
            {
                Selection.activeObject = SteamVR_Settings.instance;
            }
        }
        private void OnGUI()
        {
            if (headerLabelStyle == null)
            {
                headerLabelStyle = new GUIStyle(EditorStyles.boldLabel);
            }

            CheckFileInitialized();

            UpdateProgressBar();

            if (Application.isPlaying == false && (SteamVR_Input_Generator.IsGenerating() == true || string.IsNullOrEmpty(progressBarText) == false))
            {
                EditorGUI.LabelField(new Rect(0, 0, 200, 20), "Generating SteamVR Input...");

                bool cancel = GUI.Button(new Rect(50, 20, 100, 20), "Cancel");
                if (cancel)
                {
                    SteamVR_Input_Generator.CancelGeneration();
                    ClearProgressBar();
                }

                return;
            }

#if UNITY_2017_1_OR_NEWER
            if (EditorApplication.isCompiling)
            {
                EditorGUI.LabelField(new Rect(0, 0, 100, 20), "Compiling...");
                return; //ongui gets more fussy after 2017
            }
#endif
            CheckInitialized();

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

            EditorGUILayout.Space();

            DrawTop();

            EditorGUILayout.Space();

            DrawSets();

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (selectedActionSet == -1)
            {
                DrawNoSetSelected();
            }
            else
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
                DrawActions();
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical();
                if (selectedActionIndex == -1)
                {
                    DrawNoActionSelected();
                }
                else
                {
                    DrawDetails();
                }

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.Space();

                DrawSave();
            }

            EditorGUILayout.EndScrollView();
        }