Skip to content

A library that makes input branching safe and easy using Rx.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

euglenach/InputSwitcher

Repository files navigation

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;

About

A library that makes input branching safe and easy using Rx.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Packages

No packages published

Languages