private static void CheckAndCopyDefaults()
        {
            if (OpenVRHelpers.IsUsingSteamVRInput())
            {
                return; //don't copy if we're using steamvr input
            }
            OpenVRSettings settings = OpenVRSettings.GetSettings();

            if (settings != null)
            {
                if (settings.HasCopiedDefaults)
                {
                    return; //already copied
                }
            }

            string folderPath = OpenVRSettings.GetStreamingSteamVRPath();

            string[] filesToCopy = GetFiles();

            foreach (string file in filesToCopy)
            {
                FileInfo fileInfo = new FileInfo(file);
                string   newPath  = Path.Combine(folderPath, fileInfo.Name);
                if (File.Exists(newPath) == false)
                {
                    File.Copy(fileInfo.FullName, newPath);
                }
            }

            if (settings != null)
            {
                settings.HasCopiedDefaults = true;
            }
        }
Beispiel #2
0
        public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
        {
            if (target != BuildTarget.StandaloneLinux64 && target != BuildTarget.StandaloneWindows)
            {
                return;
            }

            OpenVRSettings settings  = OpenVRSettings.GetSettings();
            bool           needsSave = false;

            if (OpenVRHelpers.IsUsingSteamVRInput())
            {
                bool wasLegacy = settings.IsLegacy;
                settings.IsLegacy = false;

                if (settings.IsLegacy != wasLegacy)
                {
                    needsSave = true;
                }
            }

            bool saved = settings.InitializeActionManifestFileRelativeFilePath();

            string settingsAssetPath = AssetDatabase.GetAssetPath(settings);

            if (string.IsNullOrEmpty(settingsAssetPath))
            {
                CreatePath(defaultAssetPath);
                UnityEditor.AssetDatabase.CreateAsset(settings, defaultAssetPath);
                settingsAssetPath = AssetDatabase.GetAssetPath(settings);
            }
            else if (needsSave)
            {
                UnityEditor.EditorUtility.SetDirty(settings);
                UnityEditor.AssetDatabase.SaveAssets();
            }


            FileInfo      buildPath      = new FileInfo(pathToBuiltProject);
            string        buildName      = buildPath.Name.Replace(buildPath.Extension, "");
            DirectoryInfo buildDirectory = buildPath.Directory;

            string dataDirectory = Path.Combine(buildDirectory.FullName, buildName + "_Data");

            if (Directory.Exists(dataDirectory) == false)
            {
                string vsDebugDataDirectory = Path.Combine(buildDirectory.FullName, "build/bin/" + buildName + "_Data");
                if (Directory.Exists(vsDebugDataDirectory) == false)
                {
                    Debug.LogError("<b>[OpenVR]</b> Could not find data directory at: " + dataDirectory + ". Also checked vs debug at: " + vsDebugDataDirectory);
                }
                else
                {
                    dataDirectory = vsDebugDataDirectory;
                }
            }

            string streamingAssets = Path.Combine(dataDirectory, "StreamingAssets");

            if (Directory.Exists(streamingAssets) == false)
            {
                Directory.CreateDirectory(streamingAssets);
            }

            string streamingSteamVR = Path.Combine(streamingAssets, "SteamVR");

            if (Directory.Exists(streamingSteamVR) == false)
            {
                Directory.CreateDirectory(streamingSteamVR);
            }

            Debug.Log("settingsAssetPath: " + settingsAssetPath);

            FileInfo currentSettingsPath = new FileInfo(settingsAssetPath);
            FileInfo newSettingsPath     = new FileInfo(Path.Combine(streamingSteamVR, "OpenVRSettings.asset"));

            if (newSettingsPath.Exists)
            {
                newSettingsPath.IsReadOnly = false;
                newSettingsPath.Delete();
            }

            File.Copy(currentSettingsPath.FullName, newSettingsPath.FullName);

            Debug.Log("Copied openvr settings to build directory: " + newSettingsPath.FullName);
        }