<commit_before>﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using InControl;

public class UserInputManager : MonoBehaviour {


	// variable set in Inspector
	public int playerNum = 0;

	// variables for player controller and GUI
	[HideInInspector]
	public Vector2 leftInput;
	[HideInInspector]
	public Vector2 rightInput;
	[HideInInspector]
	public int button_id = -1;

	[SerializeField]
	private EventSystem eventSystem = null;

	// controller input events:
	public delegate void OnInput();

	// Game control: Trigger and bumpers
	public event OnInput OnPressMainSkill;
	public event OnInput OnPressSubSkill;
	public event OnInput OnReleaseSubSkill;
	public event OnInput OnPressHit;
	public event OnInput OnPressSwapIceFire;

	public event OnInput OnPressRunning;
	public event OnInput OnReleaseRunning;

	// UI control:
	public event OnInput OnPressConfirm;
	public event OnInput OnPressBack;
	public event OnInput OnPressNavUp;
	public event OnInput OnPressNavDown;

	// Buttons: X, Y, A, B
	public event OnInput OnPressButton;
	public event OnInput OnReleaseButton;




	
	// input lock of each: left, right, buttons, trigger & bumper;
	private bool[] ctrlLocks = new bool[4]{false, false, false, false};
	void Start()
	{}
	
	void Update()
	{
		var inputDevice = (InputManager.Devices.Count > playerNum) ? InputManager.Devices[playerNum] : null;
		if (inputDevice == null)
		{
//			Debug.Log ("No devide detected for player:" + playerNum);
		}
		else
		{
			UpdateWithInputDevice( inputDevice );
		}

	}
	
	
	void UpdateWithInputDevice( InputDevice inputDevice )
	{
		GetButtonInput (inputDevice);
		GetTriggerBumperInput (inputDevice);
		GetDirectionInput (inputDevice);
	}
	
	void GetButtonInput(InputDevice inputDevice)
	{
		if(ctrlLocks[2]) return;

		// if any buttons in X,Y,A,B is pressed down (one shot)
		if (inputDevice.AnyButton) 
		{

			if (inputDevice.Action1.WasPressed)
			{
				Debug.Log ("Button pressed: A");
				button_id = 1;
			}
			else
				if (inputDevice.Action2.WasPressed)
			{
				Debug.Log ("Button pressed: B");
				button_id = 2;
			}
			else
				if (inputDevice.Action3.WasPressed)
			{
				Debug.Log ("Button pressed: X");
				button_id = 3;
			}
			else
				if (inputDevice.Action4.WasPressed)
			{
				Debug.Log ("Button pressed: Y");
				button_id = 4;
			}
			else
			{
				// should occur when keep pressing
				Debug.Log ("Button pressed: pressing");
			}
		}

		if(inputDevice.AnyButton.WasPressed)
		{
			Debug.Log ("Button pressed");
			
			if(OnPressButton != null) OnPressButton();
		}

		if(inputDevice.Action1.WasReleased
		   || inputDevice.Action2.WasReleased
		   || inputDevice.Action3.WasReleased
		   || inputDevice.Action4.WasReleased)
		{
			if(OnReleaseButton != null) OnReleaseButton();
			Debug.Log ("Button released" + inputDevice.AnyButton.Value);
		}


	}

	void GetTriggerBumperInput(InputDevice inputDevice)
	{
		if(ctrlLocks[3]) return;

		if(inputDevice.LeftBumper.WasPressed)
		{
			if(OnPressNavUp != null) OnPressNavUp();
			if(OnPressSwapIceFire != null) OnPressSwapIceFire();
		}
		
		if(inputDevice.RightBumper.WasPressed)
		{
			if(OnPressNavDown != null) OnPressNavDown();
			if(OnPressSubSkill != null) OnPressSubSkill();
		}

		if(inputDevice.RightTrigger.WasPressed)
		{
			if(eventSystem != null && eventSystem.currentSelectedGameObject != null)
			{
				Debug.Log(eventSystem.currentSelectedGameObject.ToString());
				ExecuteEvents.Execute (eventSystem.currentSelectedGameObject, null, ExecuteEvents.submitHandler);
			}

			if(OnPressConfirm != null) OnPressConfirm();
			if(OnPressMainSkill != null) OnPressMainSkill();
		}

		if(inputDevice.LeftTrigger.WasPressed)
		{
			if(eventSystem != null && eventSystem.currentSelectedGameObject != null)
			{
				Debug.Log(eventSystem.currentSelectedGameObject.ToString());
				ExecuteEvents.Execute (eventSystem.currentSelectedGameObject, null, ExecuteEvents.submitHandler);
			}

			if(OnPressBack != null) OnPressBack();
			if(OnPressRunning != null) OnPressRunning();
		}

		if(inputDevice.LeftTrigger.WasReleased)
		{
			if(OnReleaseRunning != null) OnReleaseRunning();
		}


	}
<commit_msg>update control Trigger -> AB Button<commit_after>﻿using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using InControl;

public class UserInputManager : MonoBehaviour {


	// variable set in Inspector
	public int playerNum = 0;

	// variables for player controller and GUI
	[HideInInspector]
	public Vector2 leftInput;
	[HideInInspector]
	public Vector2 rightInput;
	[HideInInspector]
	public int button_id = -1;

	[SerializeField]
	private EventSystem eventSystem = null;

	// controller input events:
	public delegate void OnInput();

	// Game control: Trigger and bumpers
	public event OnInput OnPressMainSkill;
	public event OnInput OnPressSubSkill;
	public event OnInput OnReleaseSubSkill;
	public event OnInput OnPressHit;
	public event OnInput OnPressSwapIceFire;

	public event OnInput OnPressRunning;
	public event OnInput OnReleaseRunning;

	// UI control:
	public event OnInput OnPressConfirm;
	public event OnInput OnPressBack;
	public event OnInput OnPressNavUp;
	public event OnInput OnPressNavDown;

	// Buttons: X, Y, A, B
	public event OnInput OnPressButton;
	public event OnInput OnReleaseButton;




	
	// input lock of each: left, right, buttons, trigger & bumper;
	private bool[] ctrlLocks = new bool[4]{false, false, false, false};
	void Start()
	{}
	
	void Update()
	{
		var inputDevice = (InputManager.Devices.Count > playerNum) ? InputManager.Devices[playerNum] : null;
		if (inputDevice == null)
		{
//			Debug.Log ("No devide detected for player:" + playerNum);
		}
		else
		{
			UpdateWithInputDevice( inputDevice );
		}

	}
	
	
	void UpdateWithInputDevice( InputDevice inputDevice )
	{
		GetButtonInput (inputDevice);
		GetTriggerBumperInput (inputDevice);
		GetDirectionInput (inputDevice);
	}
	
	void GetButtonInput(InputDevice inputDevice)
	{
		if(ctrlLocks[2]) return;

		// if any buttons in X,Y,A,B is pressed down (one shot)
		if (inputDevice.AnyButton) 
		{

			if (inputDevice.Action1.WasPressed)
			{
				Debug.Log ("Button pressed: A");
				if(OnPressConfirm != null) OnPressConfirm();

				button_id = 1;
			}
			else
				if (inputDevice.Action2.WasPressed)
			{
				Debug.Log ("Button pressed: B");
				if(OnPressBack != null) OnPressBack();

				button_id = 2;
			}
			else
				if (inputDevice.Action3.WasPressed)
			{
				Debug.Log ("Button pressed: X");
				button_id = 3;
			}
			else
				if (inputDevice.Action4.WasPressed)
			{
				Debug.Log ("Button pressed: Y");
				button_id = 4;
			}
			else
			{
				// should occur when keep pressing
				Debug.Log ("Button pressed: pressing");
			}
		}

		if(inputDevice.AnyButton.WasPressed)
		{
			Debug.Log ("Button pressed");
			
			if(OnPressButton != null) OnPressButton();
		}

		if(inputDevice.Action1.WasReleased
		   || inputDevice.Action2.WasReleased
		   || inputDevice.Action3.WasReleased
		   || inputDevice.Action4.WasReleased)
		{
			if(OnReleaseButton != null) OnReleaseButton();
			Debug.Log ("Button released" + inputDevice.AnyButton.Value);
		}


	}

	void GetTriggerBumperInput(InputDevice inputDevice)
	{
		if(ctrlLocks[3]) return;

		if(inputDevice.LeftBumper.WasPressed)
		{
			if(OnPressNavUp != null) OnPressNavUp();
			if(OnPressSwapIceFire != null) OnPressSwapIceFire();
		}
		
		if(inputDevice.RightBumper.WasPressed)
		{
			if(OnPressNavDown != null) OnPressNavDown();
			if(OnPressSubSkill != null) OnPressSubSkill();
		}

		if(inputDevice.RightTrigger.WasPressed)
		{
			if(eventSystem != null && eventSystem.currentSelectedGameObject != null)
			{
				Debug.Log(eventSystem.currentSelectedGameObject.ToString());
				ExecuteEvents.Execute (eventSystem.currentSelectedGameObject, null, ExecuteEvents.submitHandler);
			}

//			if(OnPressConfirm != null) OnPressConfirm();
			if(OnPressMainSkill != null) OnPressMainSkill();
		}

		if(inputDevice.LeftTrigger.WasPressed)
		{
			if(eventSystem != null && eventSystem.currentSelectedGameObject != null)
			{
				Debug.Log(eventSystem.currentSelectedGameObject.ToString());
				ExecuteEvents.Execute (eventSystem.currentSelectedGameObject, null, ExecuteEvents.submitHandler);
			}

//			if(OnPressBack != null) OnPressBack();
			if(OnPressRunning != null) OnPressRunning();
		}

		if(inputDevice.LeftTrigger.WasReleased)
		{
			if(OnReleaseRunning != null) OnReleaseRunning();
		}


	}

{'fraction_non_alphanumeric': 0.10615711252653928, 'fraction_numerical': 0.004482189195564991, 'mean_word_length': 4.0082693443591255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919785', 'n_tokens_mistral': 3129, 'n_tokens_neox': 2692, 'n_words': 614}