Unclaimed Package Is this your package? Claim it to unlock full analytics and manage your listing.
Claim This Package

Install via UPM

Add to Unity Package Manager using this URL

https://www.pkglnk.dev/inputswitcher.git

README Markdown

Copy this to your project's README.md

Style
Preview
pkglnk installs badge
## Installation

Add **InputSwitcher** to your Unity project via Package Manager:

1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/inputswitcher.git
```

[![pkglnk](https://www.pkglnk.dev/badge/inputswitcher.svg?style=pkglnk)](https://www.pkglnk.dev/pkg/inputswitcher)

Dependencies (2)

README

InputSwitcher

Inputの分岐を安全かつ楽にできるライブラリ

必要なもの

UniRx

InputAsObservable

Installation

Add from GitHub

You can also add it directly from GitHub on Unity 2019.4+. Note that you won't be able to receive updates through Package Manager this way, you'll have to update manually.

  • open Package Manager
  • click +
  • select Add from Git URL
  • paste https://github.com/euglenach/InputSwitcher.git
  • click Add

使い方

Input元に IInputReceiverインターフェース を実装する

using UnityEngine;
using InputSwitcher;

public class Hoge : MonoBehaviour, IInputReceiver{

}

InputSwクラスのメソッドにIInputReceiverのインスタンスを渡す

using UnityEngine;
using UniRx;
using InputSwitcher;

public class Hoge : MonoBehaviour, IInputReceiver{
    void Start(){
        InputSw.GetKey(this, KeyCode.C)
            .Subscribe(_ => {Debug.Log("Hoge");}); //Cをおすとほげええええ
    }
}
using UnityEngine;
using UniRx;
using InputSwitcher;

public class Foo : MonoBehaviour,IInputReceiver{
    void Start(){
        InputSw.GetKey(this, KeyCode.C)
               .Subscribe(_ => {Debug.Log("Foo");}); //Cを押すとふううううう
    }
}

分岐方法を決定する

using InputSwitcher;
using UnityEngine;
using UniRx.Triggers;
using UniRx;

public class SampleInputController : MonoBehaviour{
    [SerializeField] private Hoge hoge;
    [SerializeField] private Foo foo;
    private void Start(){
        this.OnKeyDownAsObservable(KeyCode.H)
            .Subscribe(_ => {
                Debug.Log("switch hoge");
                InputSw.Switch(hoge); //Hを押したらhogeのインプットしか受け取らない
            });

        this.OnKeyDownAsObservable(KeyCode.F)
            .Subscribe(_ => {
                Debug.Log("switch foo");
                InputSw.Switch(foo); //Fを押したらfooのインプットしか受け取らない
            });
    }
}

screenshot 1559356854

リファレンス

IInputReceiver

インプットを流すクラスに実装するインターフェース

public class Hoge : MonoBehaviour,IInputReceiver{

}

Switch

インプットを通すキーになるインスタンスを切り替える

InputSw.Switch(hoge);

Inputを流す

InputSwのインプット系のメソッドにIInputReceiverインスタンスを渡す

InputSw.GetKey(this, KeyCode.C)
        .Subscribe(_ => {Debug.Log("Hoge");});

Current

現在のキーインスタンスを取得する

InputSw.Current;

IsCurrent

今のキーインスタンスが引数と一致するか

InputSw.IsCurrent(hoge)

IsActive

InputSwがアクティブかどうかを取得する

IsActiveプロパティがfalseだと、SwitchメソッドとInput系メソッドを通さなくなる デフォルトはtrue

InputSw.IsActive;
InputSw.IsActive = !InputSw.IsActive;

Pause

InputSw.IaActiveプロパティを非アクティブにする

InputSw.Pause();

Resume

InputSw.IaActiveプロパティをアクティブにする

InputSw.Resume();

IsLogWrite

ログを出力するかのプロパティ デフォルトはtrue

InputSw.IsLogWrite = false;

Comments

No comments yet. Be the first!