1
0

SteamVR_CopyExampleInputFiles.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. using System;
  5. using System.Linq;
  6. using System.IO;
  7. namespace Valve.VR
  8. {
  9. public class SteamVR_CopyExampleInputFiles : Editor
  10. {
  11. public const string steamVRInputExampleJSONCopiedKey = "SteamVR_Input_CopiedExamples";
  12. public const string exampleJSONFolderParent = "Input";
  13. public const string exampleJSONFolderName = "ExampleJSON";
  14. [UnityEditor.Callbacks.DidReloadScripts]
  15. private static void OnReloadScripts()
  16. {
  17. SteamVR_Input.CheckOldLocation();
  18. CopyFiles();
  19. }
  20. public static void CopyFiles(bool force = false)
  21. {
  22. bool hasCopied = EditorPrefs.GetBool(steamVRInputExampleJSONCopiedKey, false);
  23. if (hasCopied == false || force == true)
  24. {
  25. string actionsFilePath = SteamVR_Input.GetActionsFilePath();
  26. bool exists = File.Exists(actionsFilePath);
  27. if (exists == false)
  28. {
  29. string steamVRFolder = SteamVR.GetSteamVRFolderPath();
  30. string exampleLocation = Path.Combine(steamVRFolder, exampleJSONFolderParent);
  31. string exampleFolderPath = Path.Combine(exampleLocation, exampleJSONFolderName);
  32. string streamingAssetsPath = SteamVR_Input.GetActionsFileFolder();
  33. string[] files = Directory.GetFiles(exampleFolderPath, "*.json");
  34. foreach (string file in files)
  35. {
  36. string filename = Path.GetFileName(file);
  37. string newPath = Path.Combine(streamingAssetsPath, filename);
  38. try
  39. {
  40. File.Copy(file, newPath, false);
  41. Debug.Log("<b>[SteamVR]</b> Copied example input JSON to path: " + newPath);
  42. }
  43. catch
  44. {
  45. Debug.LogError("<b>[SteamVR]</b> Could not copy file: " + file + " to path: " + newPath);
  46. }
  47. }
  48. EditorPrefs.SetBool(steamVRInputExampleJSONCopiedKey, true);
  49. }
  50. }
  51. }
  52. }
  53. }