Skip to content

Commit

Permalink
[Chore] Merged with forked upstream repo "[master]" branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mfdeveloper committed Sep 15, 2023
2 parents 36cf617 + 0fe3ea1 commit 0cb4064
Show file tree
Hide file tree
Showing 11 changed files with 715 additions and 78 deletions.
75 changes: 64 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,93 @@
# Vibration
Native plugin for Unity for iOS and Android.

Native **free** plugin for Unity for iOS and Android.
Use custom vibrations on mobile.

**iOS and Android**
If you like this free plugin, that's be cool if you can buy me a coffee 😀☕️
Send tips to https://paypal.me/UnityVibrationPlugin

# Installation

The minimal checked Unity Version is 2019.3.* LTS

Open Package Manager and "Add package from git url..." using next string:
* `https://github.com/BenoitFreslon/Vibration.git`

You also can edit `Packages/manifest.json` manually, just add:
* `"com.benoitfreslon.vibration": "https://github.com/BenoitFreslon/Vibration.git",`

Or you can simply copy and paste the entire `Vibration` folder to your Unity3D `Assets` folder.

# Use

## Initialization

Initialize the plugin with this line before using vibrations:

`Vibration.Init();`

## Vibrations

### iOS and Android

* Use `Vibration.Vibrate();` for a classic default ~400ms vibration
#### Default vibration

* Pop vibration: weak boom (For iOS: only available with the haptic engine. iPhone 6s minimum)
Use `Vibration.Vibrate();` for a classic default ~400ms vibration

#### Pop vibration

Pop vibration: weak boom (For iOS: only available with the haptic engine. iPhone 6s minimum or Android)

`Vibration.VibratePop();`

* Peek vibration: strong boom (For iOS: only available on iOS with the haptic engine. iPhone 6s minimum)
#### Peek Vibration

Peek vibration: strong boom (For iOS: only available on iOS with the haptic engine. iPhone 6s minimum or Android)

`Vibration.VibratePeek();`

* Nope vibration: series of three weak booms (For iOS: only available with the haptic engine. iPhone 6s minimum)
#### Nope Vibration

`Vibration.VibrateNope();`
Nope vibration: series of three weak booms (For iOS: only available with the haptic engine. iPhone 6s minimum or Android)

`Vibration.VibrateNope();`

**Android Only**
---
## Android Only

* Custom duration in milliseconds
#### Custom duration in milliseconds

`Vibration.Vibrate(500);`

* Pattern
#### Pattern

```
long [] pattern = { 0, 1000, 1000, 1000, 1000 };
Vibration.Vibrate ( pattern, -1 );
```

* Cancel
#### Cancel

`Vibration.Cancel();`

---
## IOS only
vibration using haptic engine

`Vibration.VibrateIOS(ImpactFeedbackStyle.Light);`

`Vibration.VibrateIOS(ImpactFeedbackStyle.Medium);`

`Vibration.VibrateIOS(ImpactFeedbackStyle.Heavy);`

`Vibration.VibrateIOS(ImpactFeedbackStyle.Rigid);`

`Vibration.VibrateIOS(ImpactFeedbackStyle.Soft);`

`Vibration.VibrateIOS(NotificationFeedbackStyle.Error);`

`Vibration.VibrateIOS(NotificationFeedbackStyle.Success);`

`Vibration.VibrateIOS(NotificationFeedbackStyle.Warning);`

`Vibration.VibrateIOS_SelectionChanged();`
4 changes: 4 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 33 additions & 7 deletions Samples/VibrationExample/VibrationExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,29 +18,54 @@ public class VibrationExample : MonoBehaviour
public Text inputTime;
public Text inputPattern;
public Text inputRepeat;
public Text txtAndroidVersion;

<<<<<<<< HEAD:Samples/VibrationExample/VibrationExample.cs
========
// Use this for initialization
void Start ()
{
Vibration.Init ();
Debug.Log ( "Application.isMobilePlatform: " + Application.isMobilePlatform );
txtAndroidVersion.text = "Android Version: " + Vibration.AndroidVersion.ToString ();
}

// Update is called once per frame
void Update ()
{

}

>>>>>>>> master:Vibration/Example/VibrationExample.cs
public void TapVibrate ()
{
Vibration.Vibrate ();
}

public void TapVibrateCustom ()
{
Debug.Log ( inputTime.text );
Vibration.Vibrate ( int.Parse ( inputTime.text ) );
#if UNITY_ANDROID
Vibration.VibrateAndroid ( int.Parse ( inputTime.text ) );
#endif
}

public void TapVibratePattern ()
{
long[] longs = inputPattern.text.Select ( item => ( long )item ).ToArray ();
Debug.Log ( longs + " " + int.Parse ( inputRepeat.text ) );
Vibration.Vibrate ( longs, int.Parse ( inputRepeat.text ) );
string[] patterns = inputPattern.text.Replace ( " ", "" ).Split ( ',' );
long[] longs = Array.ConvertAll<string, long> ( patterns, long.Parse );

Debug.Log ( longs.Length );
//Vibration.Vibrate ( longs, int.Parse ( inputRepeat.text ) );
#if UNITY_ANDROID
Vibration.VibrateAndroid ( longs, int.Parse ( inputRepeat.text ) );
#endif
}

public void TapCancelVibrate ()
{

Vibration.Cancel ();
#if UNITY_ANDROID
Vibration.CancelAndroid();
#endif
}

public void TapPopVibrate ()
Expand Down
Loading

0 comments on commit 0cb4064

Please sign in to comment.