GithubHelp home page GithubHelp logo

inputswitcher's Introduction

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;

inputswitcher's People

Contributors

euglenach avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.