示例#1
0
        KeyValuePair <string, string> getJsonFromPath(string path)
        {
            //If they clicked away from the file dialog, we won't have a valid path
            if (path == "")
            {
                return(new KeyValuePair <string, string>("NSVR_EMPTY_PATH", "NSVR_FAILED"));
            }

            //Attempt to get json of the haptic definition file from the tool
            var json = "";

            try
            {
                json = _assetTool.GetHapticDefinitionFileJson(path);
            }
            catch (InvalidOperationException e)
            {
                //The filename was not set. This could be if the registry key was not found
                Debug.LogError("[NSVR] Could not locate the HapticAssetTools.exe program, make sure the NSVR Service was installed. Try reinstalling if the problem persists.");
                return(new KeyValuePair <string, string>("NSVR_NO_HAT", "NSVR_FAILED"));
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                Debug.LogError("[NSVR] Could not open the HapticAssetTools.exe program (was it renamed? Does it exist within the service install directory?): " + e.Message);
                return(new KeyValuePair <string, string>("NSVR_NO_OPEN", "NSVR_FAILED"));
            }


            //If the asset tool succeeded in running, but returned nothing, it's an error
            if (json == "")
            {
                Debug.LogWarning("[NSVR] Unable to load " + path + " it's probably malformed");
                return(new KeyValuePair <string, string>("NSVR_EMPTY_RESPONSE", "NSVR_FAILED"));
            }

            return(new KeyValuePair <string, string>(path, json));
        }
示例#2
0
        private void CreateHapticAsset(string path)
        {
            //If they clicked away from the file dialog, we won't have a valid path
            if (path == "")
            {
                return;
            }

            //Attempt to get json of the haptic definition file from the tool
            var json = "";

            try
            {
                json = _assetTool.GetHapticDefinitionFileJson(path);
            } catch (InvalidOperationException e)
            {
                //The filename was not set. This could be if the registry key was not found
                Debug.LogError("[NSVR] Could not locate the HapticAssetTools.exe program, make sure the NSVR Service was installed. Try reinstalling if the problem persists.");
                return;
            } catch (System.ComponentModel.Win32Exception e)
            {
                Debug.LogError("[NSVR] Could not open the HapticAssetTools.exe program (was it renamed? Does it exist within the service install directory?): " + e.Message);
                return;
            }


            //If the asset tool succeeded in running, but returned nothing, it's an error
            if (json == "")
            {
                Debug.LogError("[NSVR] Unable to communicate with HapticAssetTools.exe");
                return;
            }

            //Create our simple json holder. Later, this could be a complex object
            var asset = CreateInstance <JsonAsset>();

            asset.SetJson(json);

            var fileName = System.IO.Path.GetFileNameWithoutExtension(path);

            //If we don't replace . with _, then Unity has serious trouble locating the file
            var newAssetName = fileName.Replace('.', '_') + ".asset";


            //This is where we'd want to change the default location of new haptic assets
            if (!AssetDatabase.IsValidFolder("Assets/Resources/Haptics"))
            {
                if (!AssetDatabase.IsValidFolder("Assets/Resources"))
                {
                    AssetDatabase.CreateFolder("Assets", "Resources");
                }
                AssetDatabase.CreateFolder("Assets/Resources", "Haptics");
            }

            var newAssetPath = "Assets/Resources/Haptics/" + newAssetName;

            asset.name = newAssetName;

            AssetDatabase.CreateAsset(asset, newAssetPath);
            Undo.RegisterCreatedObjectUndo(asset, "Create " + asset.name);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            Selection.activeObject = asset;
        }