Ejemplo n.º 1
0
        /// <summary>
        /// Converts a AHAP string into a MMNRumbleWaveForm
        /// </summary>
        /// <param name="AHAPasString"></param>
        /// <returns></returns>
        public static MMNVRumbleWaveForm AHAPtoRumbleWaveForm(string AHAPasString, float intensityMultiplier, float sharpnessMultiplier)
        {
            MMNVAHAP ahap = JsonConvert.DeserializeObject <MMNVAHAP>(AHAPasString);

            List <long> patterns           = new List <long>();
            List <int>  lowFreqAmplitudes  = new List <int>();
            List <int>  highFreqAmplitudes = new List <int>();

            double totalTimeStamp    = 0f;
            double previousTimeStamp = 0f;

            foreach (MMNVAHAPPattern pattern in ahap.Pattern)
            {
                if (pattern.ParameterCurve != null)
                {
                    if (pattern.ParameterCurve.ParameterID == "HapticIntensityControl")
                    {
                        foreach (MMNVAHAPParameterCurveControlPoint point in pattern.ParameterCurve.ParameterCurveControlPoints)
                        {
                            double timeStamp = point.Time - previousTimeStamp;
                            totalTimeStamp += timeStamp;
                            patterns.Add((long)(timeStamp * 1000));

                            float originalIntensity = (float)point.ParameterValue * intensityMultiplier;
                            int   intensity         = (int)Remap(originalIntensity, 0f, 1f, 0f, 255f);
                            lowFreqAmplitudes.Add(intensity);

                            previousTimeStamp = point.Time;
                        }
                    }
                    if (pattern.ParameterCurve.ParameterID == "HapticSharpnessControl")
                    {
                        foreach (MMNVAHAPParameterCurveControlPoint point in pattern.ParameterCurve.ParameterCurveControlPoints)
                        {
                            double timeStamp = point.Time - previousTimeStamp;
                            totalTimeStamp += timeStamp;
                            patterns.Add((long)(timeStamp * 1000));

                            float originalIntensity = (float)point.ParameterValue * sharpnessMultiplier;
                            int   intensity         = (int)Remap(originalIntensity, 0f, 1f, 0f, 255f);
                            highFreqAmplitudes.Add(intensity);

                            previousTimeStamp = point.Time;
                        }
                    }
                }
            }

            MMNVRumbleWaveForm returnWaveForm = new MMNVRumbleWaveForm();

            returnWaveForm.LowFrequencyAmplitudes  = lowFreqAmplitudes.ToArray();
            returnWaveForm.HighFrequencyAmplitudes = highFreqAmplitudes.ToArray();
            returnWaveForm.Pattern = patterns.ToArray();

            return(returnWaveForm);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// On inspector GUI, we draw an extra button
        /// </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            MMNVAndroidWaveFormAsset waveformAsset = (MMNVAndroidWaveFormAsset)target;

            DrawDefaultInspector();

            if (waveformAsset.AHAPFile != null)
            {
                if (GUILayout.Button("Import from AHAP"))
                {
                    MMNVAndroidWaveForm tempWaveform = MMNVAHAP.AHAPtoAndroidWaveForm(waveformAsset.AHAPFile.text, waveformAsset.IntensityMultiplier, waveformAsset.SharpnessMultiplier);
                    waveformAsset.WaveForm.Pattern    = tempWaveform.Pattern;
                    waveformAsset.WaveForm.Amplitudes = tempWaveform.Amplitudes;
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts a AHAP string into a MMNVAndroidWaveForm
        /// </summary>
        /// <param name="AHAPasString"></param>
        /// <returns></returns>
        public static MMNVAndroidWaveForm AHAPtoAndroidWaveForm(string AHAPasString)
        {
            MMNVAHAP ahap = JsonConvert.DeserializeObject <MMNVAHAP>(AHAPasString);

            List <long> patterns   = new List <long>();
            List <int>  amplitudes = new List <int>();

            double totalTimeStamp    = 0f;
            double previousTimeStamp = 0f;

            foreach (MMNVAHAPPattern pattern in ahap.Pattern)
            {
                if (pattern.ParameterCurve != null)
                {
                    if (pattern.ParameterCurve.ParameterID == "HapticIntensityControl")
                    {
                        foreach (MMNVAHAPParameterCurveControlPoint point in pattern.ParameterCurve.ParameterCurveControlPoints)
                        {
                            double timeStamp = point.Time - previousTimeStamp;
                            totalTimeStamp += timeStamp;
                            patterns.Add((long)(timeStamp * 1000));

                            float originalIntensity = (float)point.ParameterValue;
                            int   intensity         = (int)NiceVibrationsDemoHelpers.Remap(originalIntensity, 0f, 1f, 0f, 255f);
                            amplitudes.Add(intensity);

                            previousTimeStamp = point.Time;
                        }
                    }
                }
            }

            MMNVAndroidWaveForm returnWaveForm = new MMNVAndroidWaveForm();

            returnWaveForm.Amplitudes = amplitudes.ToArray();
            returnWaveForm.Pattern    = patterns.ToArray();

            return(returnWaveForm);
        }