Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace></RootNamespace>
<ProjectGuid>{06515F97-C670-B94C-8141-437BF7EAD910}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<AssemblyName>Assembly-CSharp</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseDirectory>Assets</BaseDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_4_2;UNITY_5_4;UNITY_5;UNITY_64;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_EDITOR_RETINA;ENABLE_RETINA_GUISTYLES;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX;UNITY_TEAM_LICENSE;UNITY_PRO_LICENSE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>Temp\bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.XML" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="UnityEngine">
<HintPath>/Applications/Unity/Unity.app/Contents/Managed/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEditor">
<HintPath>/Applications/Unity/Unity.app/Contents/Managed/UnityEditor.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\SwipeManager.cs" />
<Compile Include="Assets\demo.cs" />
<Reference Include="UnityEngine.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
31 changes: 17 additions & 14 deletions SwipeManager.cs → Assets/SwipeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public enum Swipes { None, Up, Down, Left, TopLeft, BottomLeft, Right, TopRight,
public class SwipeManager : MonoBehaviour
{
public float minSwipeLength = 200f;
Vector2 currentSwipe;


private Vector2 fingerStart;
private Vector2 fingerEnd;

public static Swipes direction;
public static float angle;
public static Vector2 strength;

public static bool debugMode = false;

void Update ()
{
Expand All @@ -49,48 +52,48 @@ public void SwipeDetection ()
if(Input.GetMouseButton(0)) {
fingerEnd = Input.mousePosition;

currentSwipe = new Vector2 (fingerEnd.x - fingerStart.x, fingerEnd.y - fingerStart.y);
strength = new Vector2 (fingerEnd.x - fingerStart.x, fingerEnd.y - fingerStart.y);

// Make sure it was a legit swipe, not a tap
if (currentSwipe.magnitude < minSwipeLength) {
if (strength.magnitude < minSwipeLength) {
direction = Swipes.None;
return;
}

float angle = (Mathf.Atan2(currentSwipe.y, currentSwipe.x) / (Mathf.PI));
Debug.Log(angle);
angle = (Mathf.Atan2(strength.y, strength.x) / (Mathf.PI));
if (debugMode) Debug.Log(angle);
// Swipe up
if (angle>0.375f && angle<0.625f) {
direction = Swipes.Up;
Debug.Log ("Up");
if (debugMode) Debug.Log ("Up");
// Swipe down
} else if (angle<-0.375f && angle>-0.625f) {
direction = Swipes.Down;
Debug.Log ("Down");
if (debugMode) Debug.Log ("Down");
// Swipe left
} else if (angle<-0.875f || angle>0.875f) {
direction = Swipes.Left;
Debug.Log ("Left");
if (debugMode) Debug.Log ("Left");
// Swipe right
} else if (angle>-0.125f && angle<0.125f) {
direction = Swipes.Right;
Debug.Log ("Right");
if (debugMode) Debug.Log ("Right");
}
else if(angle>0.125f && angle<0.375f){
direction = Swipes.TopRight;
Debug.Log ("top right");
if (debugMode) Debug.Log ("top right");
}
else if(angle>0.625f && angle<0.875f){
direction = Swipes.TopLeft;
Debug.Log ("top left");
if (debugMode) Debug.Log ("top left");
}
else if(angle<-0.125f && angle>-0.375f){
direction = Swipes.BottomRight;
Debug.Log ("bottom right");
if (debugMode) Debug.Log ("bottom right");
}
else if(angle<-0.625f && angle>-0.875f){
direction = Swipes.BottomLeft;
Debug.Log ("bottom left");
if (debugMode) Debug.Log ("bottom left");
}
}

Expand Down
12 changes: 12 additions & 0 deletions Assets/SwipeManager.cs.meta

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

26 changes: 26 additions & 0 deletions Assets/demo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class demo : MonoBehaviour {

public GameObject obj;
public Text txt1;

// Use this for initialization
void Start () {

}

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

obj.transform.rotation = new Quaternion (1, 1, SwipeManager.angle, 1);
obj.transform.localScale = new Vector3 (SwipeManager.strength.x/100, SwipeManager.strength.y/100, 1);

if (SwipeManager.direction != Swipes.None) {
txt1.text = SwipeManager.direction + "\t\t\t A: "+SwipeManager.angle+"\t\t\t S: "+SwipeManager.strength+"\n" + txt1.text;
}

}
}
12 changes: 12 additions & 0 deletions Assets/demo.cs.meta

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

Binary file added Assets/demo.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/demo.unity.meta

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

Binary file added ProjectSettings/AudioManager.asset
Binary file not shown.
Binary file added ProjectSettings/ClusterInputManager.asset
Binary file not shown.
Binary file added ProjectSettings/DynamicsManager.asset
Binary file not shown.
Binary file added ProjectSettings/EditorBuildSettings.asset
Binary file not shown.
Binary file added ProjectSettings/EditorSettings.asset
Binary file not shown.
Binary file added ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file added ProjectSettings/InputManager.asset
Binary file not shown.
Binary file added ProjectSettings/NavMeshAreas.asset
Binary file not shown.
Binary file added ProjectSettings/NetworkManager.asset
Binary file not shown.
Binary file added ProjectSettings/Physics2DSettings.asset
Binary file not shown.
Binary file added ProjectSettings/ProjectSettings.asset
Binary file not shown.
2 changes: 2 additions & 0 deletions ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
m_EditorVersion: 5.4.2f1
m_StandardAssetsVersion: 0
Binary file added ProjectSettings/QualitySettings.asset
Binary file not shown.
Binary file added ProjectSettings/TagManager.asset
Binary file not shown.
Binary file added ProjectSettings/TimeManager.asset
Binary file not shown.
Binary file added ProjectSettings/UnityAdsSettings.asset
Binary file not shown.
Binary file added ProjectSettings/UnityConnectSettings.asset
Binary file not shown.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
Finger gesture detection in 8 direction using unity C#

This class has been designed to detect finger swipe in 8 different direction across device's screen.

![Alt text](https://d30y9cdsu7xlg0.cloudfront.net/png/38561-200.png "Swipe")

# 11 Nov 2016

- Added public variables for swipe strength and angle.

- Added unity demo project
23 changes: 23 additions & 0 deletions SwipeManager.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2008

Project("{A2789334-E086-3646-F573-647C11DDECF5}") = "SwipeManager", "Assembly-CSharp.csproj", "{06515F97-C670-B94C-8141-437BF7EAD910}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{06515F97-C670-B94C-8141-437BF7EAD910}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06515F97-C670-B94C-8141-437BF7EAD910}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06515F97-C670-B94C-8141-437BF7EAD910}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06515F97-C670-B94C-8141-437BF7EAD910}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Assembly-CSharp.csproj
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions SwipeManager.userprefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Properties StartupItem="Assembly-CSharp.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/demo.cs">
<Files>
<File FileName="Assets/demo.cs" Line="22" Column="78" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
</Properties>