-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSteamVR_CopyExampleInputFiles.cs
More file actions
68 lines (58 loc) · 2.48 KB
/
SteamVR_CopyExampleInputFiles.cs
File metadata and controls
68 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
using System.Linq;
using System.IO;
namespace Valve.VR
{
public class SteamVR_CopyExampleInputFiles : Editor
{
public const string steamVRInputExampleJSONCopiedKey = "SteamVR_Input_CopiedExamples";
public const string exampleJSONFolderParent = "Input";
public const string exampleJSONFolderName = "ExampleJSON";
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnReloadScripts()
{
EditorApplication.update += Update;
}
private static void Update()
{
EditorApplication.update -= Update;
SteamVR_Input.CheckOldLocation();
CopyFiles();
}
public static void CopyFiles(bool force = false)
{
bool hasCopied = EditorPrefs.GetBool(steamVRInputExampleJSONCopiedKey, false);
if (hasCopied == false || force == true)
{
string actionsFilePath = SteamVR_Input.GetActionsFilePath();
bool exists = File.Exists(actionsFilePath);
if (exists == false)
{
string steamVRFolder = SteamVR.GetSteamVRFolderPath();
string exampleLocation = Path.Combine(steamVRFolder, exampleJSONFolderParent);
string exampleFolderPath = Path.Combine(exampleLocation, exampleJSONFolderName);
string streamingAssetsPath = SteamVR_Input.GetActionsFileFolder();
string[] files = Directory.GetFiles(exampleFolderPath, "*.json");
foreach (string file in files)
{
string filename = Path.GetFileName(file);
string newPath = Path.Combine(streamingAssetsPath, filename);
try
{
File.Copy(file, newPath, false);
Debug.Log("<b>[SteamVR]</b> Copied example input JSON to path: " + newPath);
}
catch
{
Debug.LogError("<b>[SteamVR]</b> Could not copy file: " + file + " to path: " + newPath);
}
}
EditorPrefs.SetBool(steamVRInputExampleJSONCopiedKey, true);
}
}
}
}
}