public static void BeginGeneration() { generating = true; fileChanged = false; string currentPath = Application.dataPath; int lastIndex = currentPath.LastIndexOf('/'); currentPath = currentPath.Remove(lastIndex, currentPath.Length - lastIndex); SteamVR_Input_EditorWindow.SetProgressBarText("Beginning generation...", 0); GenerationStep_CreateActionSetClasses(); GenerationStep_CreateHelperClasses(); GenerationStep_CreateInitClass(); GenerationStep_CreateAssemblyDefinition(); DeleteUnusedScripts(); if (fileChanged) { EditorPrefs.SetBool(generationNeedsReloadKey, true); } AssetDatabase.Refresh(); SteamVR_Input_EditorWindow.ClearProgressBar(); generating = false; }
public static void ReopenWindow() { instance = GetOpenWindow(); if (instance != null) { instance.ForceClose(); Thread.Sleep(100); } ShowWindow(); }
private static void GenerationStep_CreateHelperClasses() { SteamVR_Input_EditorWindow.SetProgressBarText("Generating actions and actionsets classes...", 0.5f); GenerateActionHelpers(steamVRInputActionsClass); GenerateActionSetsHelpers(steamVRInputActionSetsClass); string actionsFullpath = Path.Combine(GetClassPath(), steamVRInputActionsClass + ".cs"); string actionSetsFullpath = Path.Combine(GetClassPath(), steamVRInputActionSetsClass + ".cs"); Debug.LogFormat("<b>[SteamVR Input]</b> Created input script main classes: {0} and {1}", actionsFullpath, actionSetsFullpath); }
private static void GenerationStep_CreateActionSetClasses() { SteamVR_Input_EditorWindow.SetProgressBarText("Generating action set classes...", 0.25f); SteamVR_Input.InitializeFile(); CreateActionsSubFolder(); setClasses = GenerateActionSetClasses(); Debug.LogFormat("<b>[SteamVR Input]</b> Created input script set classes: {0}", setClasses.Count); }
private void DrawRefreshButton() { EditorGUILayout.BeginHorizontal(); bool refresh = GUILayout.Button("Refresh"); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (refresh) { SteamVR_Input_EditorWindow.ReopenWindow(); } }
public static void Refresh() { instance = GetOpenWindow(); if (instance != null) { instance.selectedActionIndex = -1; instance.selectedAction = null; instance.selectedActionSet = -1; instance.selectedLocalizationIndex = -1; instance.scrollPosition = Vector2.zero; SteamVR_Input.InitializeFile(true); instance.InitializeLists(); } }
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); }
public static void BeginGeneration() { generating = true; fileChanged = false; SteamVR_Input_EditorWindow.SetProgressBarText("Beginning generation...", 0); GenerationStep_CreateActionSetClasses(); GenerationStep_CreateHelperClasses(); GenerationStep_CreateInitClass(); GenerationStep_CreateAssemblyDefinition(); DeleteUnusedScripts(); if (fileChanged) { EditorPrefs.SetBool(generationNeedsReloadKey, true); } AssetDatabase.Refresh(); SteamVR_Input_EditorWindow.ClearProgressBar(); generating = false; }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (SteamVR_Input.actions == null || SteamVR_Input.actions.Length == 0) { EditorGUI.BeginProperty(position, label, property); EditorGUI.LabelField(position, "Please generate SteamVR Input actions"); EditorGUI.EndProperty(); return; } if (enumItems == null || enumItems.Length == 0) { Awake(); } // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); SerializedProperty actionPathProperty = property.FindPropertyRelative("actionPath"); string currentPath = null; if (actionPathProperty != null) { currentPath = actionPathProperty.stringValue; if (string.IsNullOrEmpty(currentPath) == false) { SteamVR_Action existingAction = SteamVR_Action.FindExistingActionForPartialPath(currentPath); if (existingAction != null) { if (currentPath != existingAction.GetPath()) { actionPathProperty.stringValue = existingAction.GetPath(); property.serializedObject.ApplyModifiedProperties(); } currentPath = existingAction.GetPath(); } for (int actionsIndex = 0; actionsIndex < actions.Length; actionsIndex++) { if (actions[actionsIndex].fullPath == currentPath) { selectedIndex = actionsIndex + 1; // account for none option break; } } } } if (selectedIndex == notInitializedIndex) { selectedIndex = 0; } Rect labelPosition = position; labelPosition.width = EditorGUIUtility.labelWidth; EditorGUI.LabelField(labelPosition, label); Rect fieldPosition = position; fieldPosition.x = (labelPosition.x + labelPosition.width); fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5; if (selectedIndex == 0 && string.IsNullOrEmpty(currentPath) == false) { if (defaultPathLabel == null) { defaultPathLabel = string.Format(defaultPathTemplate, currentPath); } Rect defaultLabelPosition = position; defaultLabelPosition.y = position.y + fieldPosition.height / 2f; if (defaultPathLabel == null) { defaultPathLabel = string.Format(defaultPathTemplate, actionPathProperty.stringValue); } EditorGUI.LabelField(defaultLabelPosition, defaultPathLabel); } bool showInputWindow = false; int wasSelected = selectedIndex; selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems); if (selectedIndex != wasSelected) { if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex) { selectedIndex = noneIndex; actionPathProperty.stringValue = null; } else if (selectedIndex == addIndex) { selectedIndex = wasSelected; // don't change the index showInputWindow = true; } else { int actionIndex = selectedIndex - 1; // account for none option actionPathProperty.stringValue = actions[actionIndex].GetPath(); //property.objectReferenceValue = actions[actionIndex]; } property.serializedObject.ApplyModifiedProperties(); } EditorGUI.EndProperty(); if (showInputWindow) { SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add a new action } }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (enumItems == null || enumItems.Length == 0) { Awake(); } // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); if (property.objectReferenceValue != null) { var actionSet = (SteamVR_ActionSet)property.objectReferenceValue; if (string.IsNullOrEmpty(actionSet.fullPath) == false) { for (var actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++) { if (actionSets[actionSetIndex].fullPath == actionSet.fullPath) { selectedIndex = actionSetIndex + 1; break; } } } } if (selectedIndex == notInitializedIndex) { selectedIndex = 0; } var labelPosition = position; labelPosition.width = EditorGUIUtility.labelWidth; EditorGUI.LabelField(labelPosition, label); var fieldPosition = position; fieldPosition.x = (labelPosition.x + labelPosition.width); fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5 - 16; var objectRect = position; objectRect.x = fieldPosition.x + fieldPosition.width + 15; objectRect.width = 10; if (property.objectReferenceValue != null) { var selectObject = EditorGUI.Foldout(objectRect, false, GUIContent.none); if (selectObject) { Selection.activeObject = property.objectReferenceValue; } } var wasSelected = selectedIndex; selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems); if (selectedIndex != wasSelected) { if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex) { selectedIndex = noneIndex; property.objectReferenceValue = null; } else if (selectedIndex == addIndex) { selectedIndex = wasSelected; // don't change the index SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add one } else { property.objectReferenceValue = actionSets[selectedIndex - 1]; } } EditorGUI.EndProperty(); }
public static void ShowWindow() { instance = GetWindow <SteamVR_Input_EditorWindow>(false, "SteamVR Input", true); }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (SteamVR_Input.actions == null || SteamVR_Input.actions.Length == 0) { EditorGUI.BeginProperty(position, label, property); EditorGUI.LabelField(position, "Please generate SteamVR Input actions"); EditorGUI.EndProperty(); return; } if (enumItems == null || enumItems.Length == 0) { Awake(); } // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); SerializedProperty actionPathProperty = property.FindPropertyRelative("actionSetPath"); if (actionPathProperty != null) { string currentPath = actionPathProperty.stringValue; if (string.IsNullOrEmpty(currentPath) == false) { for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++) { if (actionSets[actionSetIndex].fullPath == currentPath) { selectedIndex = actionSetIndex + 1; // account for none option break; } } } } if (selectedIndex == notInitializedIndex) { selectedIndex = 0; } Rect labelPosition = position; labelPosition.width = EditorGUIUtility.labelWidth; EditorGUI.LabelField(labelPosition, label); Rect fieldPosition = position; fieldPosition.x = (labelPosition.x + labelPosition.width); fieldPosition.width = EditorGUIUtility.currentViewWidth - (labelPosition.x + labelPosition.width) - 5 - 16; Rect objectRect = position; objectRect.x = fieldPosition.x + fieldPosition.width + 15; objectRect.width = 10; bool showInputWindow = false; int wasSelected = selectedIndex; selectedIndex = EditorGUI.Popup(fieldPosition, selectedIndex, enumItems); if (selectedIndex != wasSelected) { if (selectedIndex == noneIndex || selectedIndex == notInitializedIndex) { selectedIndex = noneIndex; actionPathProperty.stringValue = ""; } else if (selectedIndex == addIndex) { selectedIndex = wasSelected; // don't change the index showInputWindow = true; } else { actionPathProperty.stringValue = actionSets[selectedIndex - 1].fullPath; //property.objectReferenceValue = actionSets[selectedIndex - 1]; } property.serializedObject.ApplyModifiedProperties(); } EditorGUI.EndProperty(); if (showInputWindow) { SteamVR_Input_EditorWindow.ShowWindow(); //show the input window so they can add a new actionset } }