{"id":16209925,"url":"https://github.com/annulusgames/lucidinput","last_synced_at":"2025-03-02T08:35:02.048Z","repository":{"id":148154141,"uuid":"583495231","full_name":"annulusgames/LucidInput","owner":"annulusgames","description":"Simple input system for Unity","archived":false,"fork":false,"pushed_at":"2023-01-23T11:25:48.000Z","size":679,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-02T03:24:15.877Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/annulusgames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-30T00:20:38.000Z","updated_at":"2025-01-21T10:57:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"550be051-40c1-47c1-9e21-ad3241581617","html_url":"https://github.com/annulusgames/LucidInput","commit_stats":null,"previous_names":["yn01dev/lucidinput","yn01-dev/lucidinput","annulusgames/lucidinput"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FLucidInput","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FLucidInput/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FLucidInput/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FLucidInput/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/annulusgames","download_url":"https://codeload.github.com/annulusgames/LucidInput/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241481967,"owners_count":19969833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T10:34:10.826Z","updated_at":"2025-03-02T08:35:02.036Z","avatar_url":"https://github.com/annulusgames.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lucid Input\nSimple input system for Unity\n\n[![license](https://img.shields.io/badge/LICENSE-MIT-green.svg)](LICENSE)\n\n\u003cimg src=\"https://github.com/AnnulusGames/LucidInput/blob/main/Assets/LucidInput/Documentation~/Header.png\" width=\"800\"\u003e\n\n## 概要\n\nLucid InputはUnityのInputクラスを拡張し、同時押しやフリック、ダブルクリックなどの高度な入力を従来のInputクラスのようにコード一行で取得することを可能にします。\n\n### 特徴\n* シンプルで扱いやすいシステム\n* 同時押しやフリックなどの高度な入力に対応\n* Input Systemに対応、UnityEngine.Inputとの切り替えが可能\n\n## セットアップ\n\n### 要件\n* Unity 2019.4 以上\n\n### インストール\n1. Window \u003e Package ManagerからPackage Managerを開く\n2. 「+」ボタン \u003e Add package from git URL\n3. 以下を入力する\n   * https://github.com/AnnulusGames/LucidInput.git?path=/Assets/LucidInput\n\n\nあるいはPackages/manifest.jsonを開き、dependenciesブロックに以下を追記\n\n```json\n{\n    \"dependencies\": {\n        \"com.annulusgames.lucid-input\": \"https://github.com/AnnulusGames/LucidInput.git?path=/Assets/LucidInput\"\n    }\n}\n```\n\n### Namespace\nLucidInputを利用する場合は、ファイルの冒頭に以下の一行を追加します。\n\n```cs\nusing AnnulusGames.LucidTools.InputSystem;\n```\n\n## Input Systemに対応\nInput Systemを導入すると、Lucid Inputは自動的にInput SyetemのAPIを利用するように切り替わります。もしLucid Inputがどちらを利用するかを切り替えたい場合は、LucidInput.activeInputHandlingを変更してください。\n\n```cs\n//InputManager(UnityEngine.Input)を使用\nLucidInput.activeInputHandling = InputHandlingMode.InputManager;\n\n//InputSystemを使用\nLucidInput.activeInputHandling = InputHandlingMode.InputSystem;\n```\n\nゲームパッドでの入力を行いたい場合は、Input Systemの導入が必須になります。\n\n\n## キー入力\n\n### 基本的な入力\n\nキーの入力を取得する場合、以下のように記述します。\n```cs\nif (LucidInput.GetKey(Key.Space))\n{\n    Debug.Log(\"space key is held down\");\n}\n```\n\nLucidInputでは、独自の列挙型「Key」を用いてキーを識別します。\nKeyは、以下のようにKeyCodeやUnityEngine.InputSystem.Keyに変換可能です。\n\n```cs\nKey spaceKey = Key.Space;\n\n//Key -\u003e KeyCodeに変換\nif (Input.GetKeyDown(spaceKey.ToKeyCode()))\n{\n    Debug.Log(\"space key was pressed\");\n}\n\n//Key -\u003e UnityEngine.InputSystem.Keyに変換\nif (Keyboard.current[spaceKey.ToISKey()].wasPressedThisFrame)\n{\n    Debug.Log(\"space key was pressed\");\n}\n```\n\n押された瞬間や離された瞬間を取得したい場合は、従来のInputクラスと同様にGetKeyDown、GetKeyUpを利用します。\n\n```cs\nif (LucidInput.GetKeyDown(Key.A))\n{\n    Debug.Log(\"A key was pressed\");\n}\nif (LucidInput.GetKeyUp(Key.B))\n{\n    Debug.Log(\"B key was released\");\n}\n```\n\n### 複数のキー\n\n複数のキーを判別する場合はGetKeyAny、GetKeyAllを利用します。\n\n```cs\n//A、B、Cのいずれかのキーが押されている\nif (LucidInput.GetKeyAny(Key.A, Key.B, Key.C))\n{\n    Debug.Log(\"A key or B key or C key is held down\");\n}\n\n//AキーとBキーが同時に押された\nif (LucidInput.GetKeyDownAll(Key.A, Key.B))\n{\n    Debug.Log(\"A key and B key was released\");\n}\n```\n\n同時押しを判定する時間を調整したい場合は、LucidInput.simultaneousPressIntervalの値を変更します。(初期値は0.1[s])\n```cs\n//同時押しを判定する時間を0.15sに変更\nLucidInput.simultaneousPressInterval = 0.15f;\n```\n\n### タップ\n\nキーが一定の時間押された後に離された(タップされた)瞬間を取得した場合は、GetKeyTapを利用します。\n```cs\n//Spaceキーが一定の時間押された後に離された\nif (LucidInput.GetKeyTap(Key.Space))\n{\n    Debug.Log(\"tap\");\n}\n```\nダブルタップを取得する場合はGetKeyDoubleTap、それ以上の回数のタップを取得する場合はGetKeyMultiTapを利用します。\n```cs\n//ダブルタップ\nif (LucidInput.GetKeyDouleTap(Key.Space))\n{\n    Debug.Log(\"double tap\");\n}\n\n//4回のタップ\nif (LucidInput.GetKeyMultiTap(Key.Space, 4))\n{\n    Debug.Log(\"4 tap\");\n}\n```\n\nまた、タップされた回数を取得したい場合はGetKeyTapCountを利用します。\n```cs\nint tapCount = LucidInput.GetKeyTapCount(Key.Space);\n```\n\nタップを判定する時間を調整したい場合はLucidInput.tapTime、複数回のタップの間隔を変更したい場合はLucidInput.tapIntervalの値を変更します。(初期値はどちらも0.2[s])\n\n```cs\nLucidInput.tapTime = 0.25f;\nLucidInput.tapInterval = 0.15f;\n```\n\n### ホールド\n\nキーの長押しを取得する場合は、GetKeyHold、GetKeyHoldEndedを利用します。\n\n```cs\n//スペースキーが1.0秒押された後、離されるまで毎フレームtrueを返す\nif (LucidInput.GetKeyHold(Key.Space, 1.0f))\n{\n    Debug.Log(\"hold\");\n}\n\n//スペースキーが1.0秒押された後、離された瞬間にtrueを返す\nif (LucidInput.GetKeyHoldEnded(Key.Space, 1.0f))\n{\n    Debug.Log(\"hold ended\");\n}\n```\n\nまた、キーが押されている時間を取得したい場合はGetKeyHoldTimeを利用します。\n\n```cs\nfloat time = LucidInput.GetKeyHoldTime(Key.Space);\n```\n\n## マウス入力\n\n### ボタン\n\nマウスのボタンの入力は以下のように行います。\n\n```cs\nif (LucidInput.GetMouseButton(0))\n{\n    Debug.Log(\"Pressed left click.\");\n}\n\nif (LucidInput.GetMouseButton(1))\n{\n    Debug.Log(\"Pressed right click.\");\n}\n\nif (LucidInput.GetMouseButton(2))\n{\n    Debug.Log(\"Pressed middle click.\");\n}\n```\n\nマウスのボタンもタップやホールドに対応しています。\n```cs\nif (LucidInput.GetMouseButtonDoubleTap(0))\n{\n    Debug.Log(\"double click.\");\n}\n\nif (LucidInput.GetMouseButtonHoldEnded(1))\n{\n    Debug.Log(\"right button hold\");\n}\n```\n\n### フリック\n\nマウスを利用したフリック操作を取得することも可能です。\n\n```cs\n//上下左右のいずれかの方向にフリック\nif (LucidInput.GetMouseFlick(0))\n{\n    Debug.Log(\"flick\");\n}\n\n//指定された方向にフリック\nif (LucidInput.GetMouseFlick(0, Direction.Right))\n{\n    Debug.Log(\"right flick\");\n}\n```\n\nフリック操作を判定する距離や時間については、それぞれLucidInput.flickMinDistance、LucidInput.flickTimeを変更することで調整が可能です。\n\n```cs\nLucidInput.flickMinDistance = 80;\nLucidInput.flickTime = 0.25f;\n```\n\nデフォルトではマウス操作をタッチでシミュレートするように設定されているため、GetMouse系のメソッドはタッチスクリーンでも動作します。無効にしたい場合は、LucidInput.simulateMouseWithTouchesをfalseに設定してください。\n\n```cs\nLucidInput.simulateMouseWithTouches = false;\n```\n\n### マウスポインター・ホイール\n\nマウスポインターの位置や移動量を取得したい場合は、以下のように記述します。\n\n```cs\n//マウスポインターの位置をスクリーン座標で取得\nVector2 position = LucidInput.mousePosition;\n\n//マウスポインターの移動量を取得\nVector2 delta = LucidInput.mousePositionDelta;\n```\n\nマウスホイールの変化量を取得する場合はmouseScrollDeltaを利用します。\n```cs\n//マウスホイールの変化量を取得\nVector2 mouseWheelDelta = LucidInput.mouseScrollDelta;\n```\n\n## タッチスクリーン\n\n※Input Systemを使用する場合、タッチ情報の取得にはEnhancedTouchを利用するためEnhancedTouchSupportが有効化されている必要があります。(activeInputHandlingをInputSystemに設定すると自動で有効化されます)\n\n画面のタッチの情報を取得したい場合は以下のように記述します。\n\n```cs\n//画面上のタッチの数だけ繰り返す\nfor (int i = 0; i \u003c LucidInput.touchCount; i++)\n{\n    //タッチ情報を取得 (画面上にタッチが存在しない場合はnullを返す)\n    Touch touch = LucidInput.GetTouch(i);\n}\n```\n\nまた、タッチもホールドやダブルタップなどに対応しています。それらを取得したい場合は、GetTouchButtonを利用します。\n\n```cs\nif (LucidInput.GetTouchButtonHold(0, 1.0f))\n{\n    Debug.Log(\"hold\");\n}\n\nif (LucidInput.GetTouchButtonDoubleTap(0))\n{\n     Debug.Log(\"double tap\");\n}\n```\n\nフリック操作を取得したい場合はGetTouchFlickを利用します。\n\n```cs\nif (LucidInput.GetTouchFlick(0, Direction.Left))\n{\n    Debug.Log(\"left flick\");\n}\n```\n\nピンチ操作(画面に2本の指をタッチして広げる・狭める動作)にも対応しています。ピンチ操作の変化量を取得したい場合は、pinchDeltaから取得できます。(画面に2本以上の指がない場合は0を返します)\n\n```cs\nfloat delta = LucidInput.pinchDelta;\n```\n\n## ゲームパッド\n※ゲームパッドの入力にはInput Systemの導入が必須です。LucidInput.activeInputHandlingがInputSystemに設定されている場合にのみ動作します。\n\nゲームパッドのボタンの入力を取得する場合は、GetGamepadButtonを使用します。\n\n```cs\nif (LucidInput.GetGamepadButtonDown(GamepadButton.A))\n{\n    Debug.Log(\"A button was pressed\");\n}\n```\n\nゲームパッドのボタンも他のボタン同様、高度な入力に対応しています。\n\n```cs\nif (LucidInput.GetGamepadButtonHoldEnded(GamepadButton.RightTrigger, 1f))\n{\n    Debug.Log(\"hold ended\");\n}\n\nif (LucidInput.GetGamepadButtonDoubleTap(GamepadButton.DpadDown))\n{\n    Debug.Log(\"double tap\");\n}\n```\n\nまた、GetKeyと同様にAny、Allも利用できます。\n\n```cs\nif (LucidInput.GetGamepadButtonDownAny(GamepadButton.A, GamepadButton.B))\n{\n    Debug.Log(\"A button or B button was pressed\");\n}\n\nif (LucidInput.GetGamepadButtonDownAll(GamepadButton.RightTrigger, GamepadButton.LeftTrigger))\n{\n    Debug.Log(\"RT and LT was pressed\");\n}\n```\n\nスティックの値やトリガーの値を取得したい場合は、以下のように記述します。\n```cs\n//左スティックの値を取得\nVector2 stickValue = LucidInput.GetGamepadStick(LR.Left);\n\n//右トリガーの値を取得\nfloat triggerValue =  LucidInput.GetGamepadTrigger(LR.Right);\n```\n\n## Axis\nLucid Inputでは以下の5つのAxisが利用可能です。\n* Horizontal\n* Vertical\n* MouseX\n* MouseY\n* MouseScrollWheel\n\n```cs\n//キー入力の場合、平滑化された値を返す\nfloat value = LucidInput.GetAxis(Axis.Horizontal);\n\n//-1, 0, 1のいずれかを返す\nfloat valueRaw = LucidInput.GetAxisRaw(Axis.Vertical);\n```\n\nGetAxisによって取得できる値は独自の計算方式で算出されるため、従来のInput.GetAxisとは値が異なる場合があります。\n\n## ライセンス\n\n[Mit License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Flucidinput","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fannulusgames%2Flucidinput","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Flucidinput/lists"}