private HapticHandle CreateHandle(SideOfHaptic side) { HapticHandle handle = null; if (TypeOfPlayable == PlayableType.Sequence) { HapticSequence seq = new HapticSequence(); seq.LoadFromAsset(PlayableResourceName); var areaFlag = side == SideOfHaptic.Left ? Where.Mirror() : Where; handle = seq.CreateHandle(areaFlag); } else if (TypeOfPlayable == PlayableType.Pattern) { HapticPattern pat = new HapticPattern(); pat.LoadFromAsset(PlayableResourceName); handle = pat.CreateHandle(); } else if (TypeOfPlayable == PlayableType.Experience) { HapticExperience exp = new HapticExperience(); exp.LoadFromAsset(PlayableResourceName); handle = exp.CreateHandle(); } else if (TypeOfPlayable == PlayableType.Impulse) { return(CreateImpulseHandle(side)); } return(handle); }
/// <summary> /// Attempts to create a haptic experience from the provided json path /// It will create a HDF and then turn the hdf into a HapticExperience. /// </summary> /// <param name="jsonPath">Ex: StreamingAssets/Haptics/NS Demos/experiences/mech_stomp.experience</param> public static HapticExperience CreateExperience(string jsonPath) { var fileName = Path.GetFileNameWithoutExtension(jsonPath); ////If we don't replace . with _, then Unity has serious trouble locating the file HapticExperience exp = null; bool isSeq = IsSequence(jsonPath); bool isPat = IsPattern(jsonPath); bool isExp = IsExperience(jsonPath); if (isExp) { exp = LoadExperienceFromJson(jsonPath); exp.name = CleanName(fileName); } else if (isSeq) { Debug.LogError("Attempted to run a HapticPattern.CreateAsset while providing a sequence at path: " + jsonPath + "\n\t"); } else if (isPat) { Debug.LogError("Attempted to run a HapticPattern.CreateAsset while providing a pattern at path: " + jsonPath + "\n\t"); } return(exp); }
internal static HapticExperience LoadExperienceFromJson(string jsonPath) { HapticDefinitionFile hdf = LoadHDFFromJson(jsonPath); if (hdf.root_effect.type == "experience") { var exp = CodeHapticFactory.CreateExperienceFromHDF(hdf.root_effect.name, hdf); return(exp); } else { Debug.LogError("Error in LoadExperienceFromJson - likely an invalid path was provided\n\t" + hdf.root_effect.name + " is of type " + hdf.root_effect.type + "\n"); return(HapticExperience.CreateNew()); //throw new InvalidOperationException("Unable to load " + hdf.root_effect.name + " as a HapticExperience because it is a " + hdf.root_effect.type); } }
/// <summary> /// Create a HapticExperience from a HapticDefinitionFile /// </summary> /// <param name="key"></param> /// <param name="hdf"></param> /// <returns></returns> public static HapticExperience CreateExperienceFromHDF(string key, HapticDefinitionFile hdf) { string cleanedKey = HapticResources.CleanName(key); HapticExperience exp = ScriptableObject.CreateInstance <HapticExperience>(); var experience_def_array = hdf.experience_definitions[key]; foreach (var element in experience_def_array) { HapticPattern thisPat = CreatePatternFromHDF(element.pattern, hdf); thisPat.name = element.pattern; ParameterizedPattern paraPat = new ParameterizedPattern(thisPat, element.time, element.strength); exp.AddPattern(paraPat); } return(exp); }