//Make this return a bool and it'll mark the LibraryElement as broken.
        public bool ExecuteLibraryElement()
        {
            if (FileHasBeenModified())
            {
                MarkElementChanged();
            }

            //Debug.Log("File has been modified since load: [" + FileHasBeenModified() + "]\n");
            try
            {
                if (LibraryManager.Inst.LastPlayed != null && LibraryManager.Inst.StopLastPlaying)
                {
                    LibraryManager.Inst.LastPlayed.Stop();
                    //Todo: implement dispose again
                    //	LibraryManager.Inst.LastPlayed
                }

                Action <HapticHandle> playHandleAndSetLastPlayed = delegate(HapticHandle h)
                {
                    LibraryManager.Inst.LastPlayed = h;

                    if (LibraryManager.Inst.LastPlayed != null)
                    {
                        LibraryManager.Inst.LastPlayed.Play();
                    }
                };

                //Get the file path
                if (myType == LibraryElementType.Sequence)
                {
                    //Debug.Log(fileAndExt + "  " + fullFilePath + "\n");
                    GetHapticDefinitionAsync(fullFilePath,
                                             //Success Delegate
                                             delegate(HapticDefinitionFile hdf)
                    {
                        var seq = CodeHapticFactory.CreateSequence(hdf.rootEffect.name, hdf);
                        //If sequence, use the specific pads selected (unsupported atm)
                        AreaFlag flag = LibraryManager.Inst.GetActiveAreas();
                        LibraryManager.Inst.SetTriggerSequence(seq, hdf.rootEffect.name);

                        playHandleAndSetLastPlayed(seq.CreateHandle(flag));
                    },
                                             //Failure delegate
                                             delegate(Exception except)
                    {
                        ToMarkAsBroken = true;
                        //Make the file red to show it's broken.
                        //Highlight the edit button.
                        //Some sort of error reporting.
                    });
                }
                if (myType == LibraryElementType.Pattern)
                {
                    GetHapticDefinitionAsync(fullFilePath,
                                             //Success Delegate
                                             delegate(HapticDefinitionFile hdf)
                    {
                        var pat = CodeHapticFactory.CreatePattern(hdf.rootEffect.name, hdf);

                        playHandleAndSetLastPlayed(pat.CreateHandle());
                    },
                                             //Failure Delegate
                                             delegate(Exception except)
                    {
                        ToMarkAsBroken = true;
                        //Make the file red to show it's broken.
                        //Highlight the edit button.
                        //Some sort of error reporting.
                    });
                }
                if (myType == LibraryElementType.Experience)
                {
                    GetHapticDefinitionAsync(fullFilePath,
                                             //Success Delegate
                                             delegate(HapticDefinitionFile hdf)
                    {
                        var exp = CodeHapticFactory.CreateExperience(hdf.rootEffect.name, hdf);

                        playHandleAndSetLastPlayed(exp.CreateHandle());
                    },
                                             //Failure delegate
                                             delegate(Exception except)
                    {
                        ToMarkAsBroken = true;
                        //Make the file red to show it's broken.
                        //Highlight the edit button.
                        //Some sort of error reporting.
                    });
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to play haptic [" + fullFilePath + "]" + "\n" + e.Message);
                return(false);
            }
            return(true);
        }
示例#2
0
        //Make this return a bool and it'll mark the LibraryElement as broken.
        public bool ExecuteLibraryElement()
        {
            if (FileHasBeenModified())
            {
                MarkElementChanged();
            }

            //Debug.Log("File has been modified since load: [" + FileHasBeenModified() + "]\n");
            try
            {
                HapticHandle newHandle = null;
                if (LibraryManager.Inst.LastPlayed != null && LibraryManager.Inst.StopLastPlaying)
                {
                    LibraryManager.Inst.LastPlayed.Stop();
                    //Todo: implement dispose again
                    //	LibraryManager.Inst.LastPlayed
                }

                Action <HapticHandle> playHandleAndSetLastPlayed = delegate(HapticHandle h)
                {
                    LibraryManager.Inst.LastPlayed = h;

                    if (LibraryManager.Inst.LastPlayed != null)
                    {
                        LibraryManager.Inst.LastPlayed.Play();
                    }
                };

                //Get the file path
                //Debug.Log("[" + myNamespace + "] [" + fileName + "]\n" + myNamespace + "" + fileName);
                if (myType == LibraryElementType.Sequence)
                {
                    GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf) {
                        var seq = CodeHapticFactory.CreateSequence(hdf.rootEffect.name, hdf);
                        //If sequence, use the specific pads selected (unsupported atm)
                        AreaFlag flag = LibraryManager.Inst.GetActiveAreas();
                        LibraryManager.Inst.SetTriggerSequence(myNamespace + fileName);

                        playHandleAndSetLastPlayed(seq.CreateHandle(flag));
                    });
                }
                if (myType == LibraryElementType.Pattern)
                {
                    GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf)
                    {
                        var pat = CodeHapticFactory.CreatePattern(hdf.rootEffect.name, hdf);

                        playHandleAndSetLastPlayed(pat.CreateHandle());
                    });
                }
                if (myType == LibraryElementType.Experience)
                {
                    GetHapticDefinitionAsync(fullFilePath, delegate(HapticDefinitionFile hdf)
                    {
                        var exp = CodeHapticFactory.CreateExperience(hdf.rootEffect.name, hdf);

                        playHandleAndSetLastPlayed(exp.CreateHandle());
                    });
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Failed to play haptic [" + fullFilePath + "]" + "\n" + e.Message);
                return(false);
            }
            return(true);
        }