Commit 4a7f819a authored by Tanner Grehawick's avatar Tanner Grehawick

add InputManager assetpackage

credit to Matt Kelly
parent 6e9e582b
fileFormatVersion: 2
guid: d47f78f47db2e41f2b5edb2426396e63
folderAsset: yes
timeCreated: 1486081262
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: db5e8a1e71fe955478cf51c1f332836a
timeCreated: 1486077609
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: dfa71b7b6162c694ab929717dd70b38d
timeCreated: 1486077649
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e2deae9c9eaf7402a844dc3126db04a8
folderAsset: yes
timeCreated: 1486081262
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 5a2e4ee577140444aac3c217f188c580
timeCreated: 1486077756
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4e0c70be2118e4175aa93af96de1d1c9
folderAsset: yes
timeCreated: 1486081262
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 1459b3ab312bd4e7ebe2c101e0c9cd6b
folderAsset: yes
timeCreated: 1486081262
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public abstract class AbstractBehavior : MonoBehaviour {
public Buttons[] inputButtons;
public MonoBehaviour[] disableScripts;
protected Animator animator;
protected InputState inputState;
protected CollisionState collisionState;
protected Rigidbody2D body;
protected virtual void Awake(){
animator = GetComponent<Animator> ();
animator.logWarnings = false;
inputState = GetComponent<InputState> ();
collisionState = GetComponent<CollisionState>();
body = GetComponent<Rigidbody2D> ();
}
protected virtual void ToggleScripts (bool value) {
foreach(MonoBehaviour script in disableScripts) {
script.enabled = value;
}
}
}
fileFormatVersion: 2
guid: eede421df1e67744c8f46cc1fdfb6805
timeCreated: 1486076722
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class CollisionState : MonoBehaviour {
public LayerMask collisionLayer;
public LayerMask enemyLayer;
public bool onGround, onWall;
public Vector2 bottomPosition = Vector2.zero;
public Vector2 rightPosition = Vector2.zero;
public Vector2 leftPosition = Vector2.zero;
public float collisionRadius = 1f;
[HideInInspector]public Collider2D enemyHit;
private InputState inputState;
void Awake() {
inputState = GetComponent<InputState>();
}
void FixedUpdate() {
enemyHit = null;
Vector2 pos = bottomPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
onGround = Physics2D.OverlapCircle(pos, collisionRadius, collisionLayer);
pos = inputState.direction == Directions.Right ? rightPosition : leftPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
onWall = Physics2D.OverlapCircle(pos, collisionRadius, collisionLayer);
enemyHit = Physics2D.OverlapCircle(pos, collisionRadius, enemyLayer);
}
void OnDrawGizmos() {
Gizmos.color = Color.red;
Vector2 pos = bottomPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius);
pos = rightPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius);
pos = leftPosition;
pos.x += transform.position.x;
pos.y += transform.position.y;
Gizmos.DrawSphere(pos, collisionRadius);
}
}
fileFormatVersion: 2
guid: c5db22d5529dd524b9174371b8f9af7a
timeCreated: 1486076722
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
public enum Directions {
Right = 1,
Left = -1
}
fileFormatVersion: 2
guid: c7dc4388fb0565b468012680df03a3b4
timeCreated: 1486076722
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public enum Buttons{
Right,
Left,
Up,
Down,
A,
B,
X,
Y,
RT,
LT,
RB,
LB
}
public enum Condition{
GreaterThan,
LessThan
}
[System.Serializable]
public class InputAxisState{
public string axisName;
public float offValue;
public Buttons buttons;
public Condition condition;
public bool value{
get{
var val = Input.GetAxisRaw (axisName);
switch (condition) {
case Condition.GreaterThan:
return val > offValue;
case Condition.LessThan:
return val < offValue;
}
return false;
}
}
}
public class InputManager : MonoBehaviour {
public InputAxisState[] inputs;
public InputState inputState;
void Update () {
foreach(var input in inputs){
inputState.SetButtonValue (input.buttons, input.value);
}
}
}
fileFormatVersion: 2
guid: 5a7bd8d106353a247bd436ee1baa2061
timeCreated: 1486076726
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/* The player movement script will need to get a reference to this object, which should also be placed on the player.
* The player should also have an array of Buttons that are all of its inputs. If the player script has an input
* in the 0 slot, calling inputState.GetButtonValue(buttons[0]) for example, will return whether or not that
* button in the buttons array is currently pressed.
*/
public class ButtonState{
public bool value;
public float holdTime = 0;
}
public class InputState : MonoBehaviour {
public Directions direction = Directions.Right;
private Dictionary<Buttons,ButtonState> buttonStates = new Dictionary<Buttons, ButtonState>();
public void SetButtonValue(Buttons key, bool value){
if(!buttonStates.ContainsKey(key)){
buttonStates.Add (key, new ButtonState ());
}
var state = buttonStates[key];
if(state.value && !value){//key has been released
state.holdTime = 0;
}else if(state.value && value){//key is being held down
state.holdTime += Time.deltaTime;
}
state.value = value;
}
public bool GetButtonValue(Buttons key){
if (buttonStates.ContainsKey (key)) {
return buttonStates [key].value;
} else {
return false;
}
}
public float GetButtonHoldTime(Buttons key){
if(buttonStates.ContainsKey(key)){
return buttonStates [key].holdTime;
}else{
return 0;
}
}
}
fileFormatVersion: 2
guid: 90413373afbe7ce47a1e5595b11b1a63
timeCreated: 1486076726
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment