public virtual void ReadState(ControllerState outState) { // if (m_ControllerInput != null) { if (m_ControllerInput.connectionState != DeviceConnectionState.Connected) // If not connected. { m_ControllerInput = null; } } if (m_ControllerInput == null) { // Search available controller... for (int i = 0, imax = m_ControllerInputs.Length; i < imax; ++i) { if (m_ControllerInputs[i] != null || m_ControllerInputs[i].connectionState == DeviceConnectionState.Connected) { m_ControllerInput = m_ControllerInputs[i]; break; } } if (m_ControllerInput == null) { outState.connectionState = GvrConnectionState.Disconnected; return; } } // outState.connectionState = GvrConnectionState.Connected; //(GvrConnectionState)m_ControllerInput.connectionState; // Touchpad outState.touchPos = m_ControllerInput.GetTouchPos(); outState.isTouching = m_ControllerInput.GetButton(DaydreamButton.Touch); outState.touchDown = m_ControllerInput.GetButtonDown(DaydreamButton.Touch); outState.touchUp = m_ControllerInput.GetButtonUp(DaydreamButton.Touch); // Click Button outState.clickButtonState = m_ControllerInput.GetButton(DaydreamButton.Click); outState.clickButtonDown = m_ControllerInput.GetButtonDown(DaydreamButton.Click); outState.clickButtonUp = m_ControllerInput.GetButtonUp(DaydreamButton.Click); // App Button outState.appButtonState = m_ControllerInput.GetButton(DaydreamButton.App); outState.appButtonDown = m_ControllerInput.GetButtonDown(DaydreamButton.App); outState.appButtonUp = m_ControllerInput.GetButtonUp(DaydreamButton.App); // Home Button outState.recentering = m_ControllerInput.GetButton(DaydreamButton.Home); outState.recentered = m_ControllerInput.GetButtonUp(DaydreamButton.Home); // Fix recenter api. if (m_ControllerInput.GetButtonUp(DaydreamButton.Home)) { m_ControllerInput.Recenter(); } // Motions outState.orientation = m_ControllerInput.GetRotation(); outState.accel = m_ControllerInput.GetAccelerometer(); outState.gyro = m_ControllerInput.GetGyroscope(); }
void DebugDrawControllers() { for (uint controller = 1; controller < 2; ++controller) { GUILayout.Label("Controller " + (controller + 1)); foreach (ControllerInput.Range range in System.Enum.GetValues(typeof(ControllerInput.Range))) { Vector2 val = ControllerInput.GetRange(controller, range); GUILayout.Label(ControllerInput.GetRangeName(range) + ": " + val); } foreach (ControllerInput.Button button in System.Enum.GetValues(typeof(ControllerInput.Button))) { string state = ""; if (ControllerInput.GetButtonDown(controller, button)) { state += " Down"; } if (ControllerInput.GetButton(controller, button)) { state += " Pressed"; } if (ControllerInput.GetButtonUp(controller, button)) { state += " Up"; } Indent(1, () => (GUILayout.Label(ControllerInput.GetButtonName(button) + ":" + state))); } GUILayout.Space(10.0f); } }
protected virtual void Update() { if (m_ControllerInput != null) { for (int i = 0, imax = m_Buttons.Length; i < imax; ++i) { if (m_Buttons[i].value != null) { if (m_ControllerInput.GetButtonDown(m_Buttons[i].key)) { m_Buttons[i].OnPointerEnter(m_EventData); } else if (m_ControllerInput.GetButtonUp(m_Buttons[i].key)) { m_Buttons[i].OnPointerExit(m_EventData); } // if (m_ControllerInput.GetButtonDown(((uint)m_Buttons[i].key >> 16))) { m_Buttons[i].OnPointerClick(m_EventData); } } } } }
protected virtual void Update() { if (m_ControllerInput != null) { if (m_ControllerInput.GetButtonDown(ControllerButton.PrimaryTrigger)) { int i = 0, imax; #if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 imax = Physics.OverlapSphereNonAlloc(m_Point.position, m_Radius, m_Colliders, layerMask); #else m_Colliders = Physics.OverlapSphere(m_Point.position, m_Radius, layerMask); imax = m_Colliders.Length; #endif if (imax > 0) { if (m_MaxObjects >= 0) { imax = Mathf.Min(imax, m_MaxObjects); } for (; i < imax; ++i) { AddPickObject(m_Colliders[i].transform); } } } else if (m_ControllerInput.GetButtonUp(ControllerButton.PrimaryTrigger)) { ClearPickObjects(); } } }
public static bool GetButtonUp(this ControllerInput thiz, XimmerseButton buttonMask) { if (thiz == null) { return(false); } return(thiz.GetButtonUp((uint)buttonMask)); }
/// <summary> /// 获得指定按键是否在这一帧抬起 /// </summary> /// <param name="controllerButton"></param> /// <returns></returns> public bool GetButtonUp(XBoxControllerButton controllerButton) { #if UNITY_METRO && !UNITY_EDITOR return(controllerInput.GetButtonUp((ControllerButton)controllerButton)); #else return(Input.GetButtonUp(TransformButtonId(controllerButton))); #endif }
public void Initialize(ButtonEvent buttonEvent) { switch (type) { case Type.Input_Button: Get = () => (Input.GetButton(stringArg)); GetDown = () => (Input.GetButtonDown(stringArg)); GetUp = () => (Input.GetButtonUp(stringArg)); break; case Type.Input_Key: Get = () => (Input.GetKey((KeyCode)intArg)); GetDown = () => (Input.GetKeyDown((KeyCode)intArg)); GetUp = () => (Input.GetKeyUp((KeyCode)intArg)); break; //case Type.CrossInput: // Get = ()=>(CrossInputManager.GetButton(stringArg)); // GetDown = ()=>(CrossInputManager.GetButtonDown(stringArg)); // GetUp = ()=>(CrossInputManager.GetButtonUp(stringArg)); //break; case Type.ControllerInput: ControllerInput input = ControllerInputManager.instance.GetControllerInput(stringArg); if (input == null) { goto default_label; } Get = () => (input.GetButton((ControllerButton)intArg)); GetDown = () => (input.GetButtonDown((ControllerButton)intArg)); GetUp = () => (input.GetButtonUp((ControllerButton)intArg)); break; default: default_label: Get = GetFalse; GetDown = GetFalse; GetUp = GetFalse; break; } }
private void setLastButtonUp() { if (controllerInput.GetButtonUp(ControllerButton.A)) { lastButtonUp = "A"; } if (controllerInput.GetButtonUp(ControllerButton.B)) { lastButtonUp = "B"; } if (controllerInput.GetButtonUp(ControllerButton.X)) { lastButtonUp = "X"; } if (controllerInput.GetButtonUp(ControllerButton.Y)) { lastButtonUp = "Y"; } if (controllerInput.GetButtonUp(ControllerButton.LeftShoulder)) { lastButtonUp = "LB"; } if (controllerInput.GetButtonUp(ControllerButton.RightShoulder)) { lastButtonUp = "RB"; } if (controllerInput.GetButtonUp(ControllerButton.View)) { lastButtonUp = "SHOW ADDRESS"; } if (controllerInput.GetButtonUp(ControllerButton.Menu)) { lastButtonUp = "SHOW MENU"; } if (controllerInput.GetButtonUp(ControllerButton.LeftThumbstick)) { lastButtonUp = "LEFT STICK CLICK"; } if (controllerInput.GetButtonUp(ControllerButton.RightThumbstick)) { lastButtonUp = "RIGHT STICK CLICK"; } if (controllerInput.GetButtonUp(ControllerButton.DPadDown)) { lastButtonUp = "DPadDown"; } if (controllerInput.GetButtonUp(ControllerButton.DPadUp)) { lastButtonUp = "DPadUp"; } if (controllerInput.GetButtonUp(ControllerButton.DPadLeft)) { lastButtonUp = "DPadLeft"; } if (controllerInput.GetButtonUp(ControllerButton.DPadRight)) { lastButtonUp = "DPadRight"; } }
void Update() { if (player == null) { return; } //Seleciona outro jogador manual mais proximo se eu estiver muito longe da bola if (player.GetCampTeam().GetSelectionMode() == GameOptionMode.automatric && player.GetCampTeam().HasPlayerOk() && !player.Locomotion.inHoldTug && !player.Locomotion.isJoint && playerToPass == null) { timeToSelect += Time.deltaTime; if (timeToSelect > 1.5f) { if (player.Distance(BallController.GetPosition()) > 3.5f || player.isOk == false) //Procurando jogador mais proximo { PlayerController nearBall = GameManager.instance.GetPlayerNearBall(player.GetCampTeam()); if (nearBall != player) { speed = 0; dir = 0; nearBall.SelectME(); timeToSelect = 0.0f; return; } } } } //Loockat na bola se estiver em strafe if (locomotion.inStrafe) { locomotion.ResetSpeedMultiples(); Vector3 ballposition = BallController.GetPosition(); ballposition.y = transform.position.y; transform.LookAt(ballposition); } //Gerenciamento de stamina if (locomotion.inSoccer) { SkillVar stamina = player.GetSkill_Stamina(); stamina.mode = SkillVarMode.autoSubtract; if (stamina.IsMin || player.isOk == false) { player.GetSkill_Stamina().mode = SkillVarMode.autoRegen; locomotion.ResetSpeedMultiples(); player.SetMotionNormal(); } } //Para ações manuais se estiver tropeçando if (player.Locomotion.inStumble)//Tropeçando { locomotion.ResetSpeedMultiples(); speed = 0; dir = 0; return; } //Solicita avoid dos aliados a frente if (player.IsMyBall()) { PlayerController allyBtw = null; if (player.IsHitForwad(5.5f, out allyBtw, player.GetCampTeam())) { if (allyBtw.IsLookAt(player)) { Vector3 origim = allyBtw.transform.position + (-allyBtw.transform.forward * 4.5f); Vector3 freePos = locomotion.GetRandomNavCircle(origim, 4.5f); allyBtw.GetComponent <AIController>().GoToPosition(freePos, BallController.instance.transform); } } } //Se houver um jogador selecionado para o passe de bola vou esperar ficar distante que o jogador efetue alguma ação difernte de se mover //para remover a seleção do jogador a passar a bola if (playerToPass != null) { if (playerToPass.Distance(player) > 11.5f) { playerToPass = null; GameManager.instance.ResetIndicator(); } } Vector2 move = locomotion.GetDirectionAxis1(); dir = move.x; speed = move.y; //Fill kick power amount if (ControllerInput.GetButtonDown(player.GetInputType(), player.GetInputs().Input_Kick)) { //Fill kick power or fill action2 power SkillVar skillKick = player.GetSkill_BasicKick(); if (player.IsMyBall()) { skillKick.SetToggle(); if (skillKick.IsReady) { skillKick.mode = SkillVarMode.autoRegen; } } playerToPass = null; GameManager.instance.ResetIndicator(); } //Kick ball if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Kick)) { //Fill kick power if is myBall SkillVar skillKick = player.GetSkill_BasicKick(); locomotion.ResetHoldTugAnimator(); if (player.IsMyBall() && skillKick.isToggle) { if (skillKick.IsReady) { if (locomotion.TriggerKick()) { skillKick.TriggerCooldown(); } } } skillKick.mode = SkillVarMode.nothing; skillKick.SetCurrentValue(0); skillKick.ResetTogle(); playerToPass = null; GameManager.instance.ResetIndicator(); } //Soccer Motion if (ControllerInput.GetButton(player.GetInputType(), player.GetInputs().Input_Stamina)) { SkillVar Stamina = player.GetSkill_Stamina(); if (Stamina.IsCritical == false && player.isOk) { // playerToPass = null; // GameManager.instance.ResetIndicator(); player.SetMotionSoccer(); player.Locomotion.SetSpeedMultiplies(1.2f); } } if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Stamina)) { // playerToPass = null; // GameManager.instance.ResetIndicator(); player.Locomotion.ResetSpeedMultiples(); player.SetMotionNormal(); player.GetSkill_Stamina().mode = SkillVarMode.autoRegen; } //Strafe Motion if (ControllerInput.GetButtonDown(player.GetInputType(), player.GetInputs().Input_Strafe)) { // playerToPass = null; // GameManager.instance.ResetIndicator(); player.SetMotionStrafe(); player.Locomotion.SetSpeedMultiplies(1.2f); } if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Strafe)) { // playerToPass = null; // GameManager.instance.ResetIndicator(); player.Locomotion.ResetSpeedMultiples(); player.SetMotionNormal(); } //Seleção para passe de bola if (ControllerInput.GetButton(player.GetInputType(), player.GetInputs().Input_Pass)) { if (player.IsMyBall() == true && locomotion.inNormal) { Vector3 mdirection = transform.forward; List <PlayerController> players = player.GetPlayersNear(10.5f); if (players.Count > 0) { PlayerController target = players.MinAngle(player, mdirection); playerToPass = target; GameManager.instance.IndicatePlayer(playerToPass); } } } //Rasteira if (ControllerInput.GetButtonDown(player.GetInputType(), player.GetInputs().Input_Pass)) { if (player.IsMyBall() == false && locomotion.inNormal) { SkillVar skilltrack = player.GetSkill_BasicActionTwo(); if (skilltrack.IsReady) { if (locomotion.TriggerActionTwo()) { skilltrack.TriggerCooldown(); } } } } //Passe de bola if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Pass)) { //playerToPass = null; //GameManager.instance.ResetIndicator(); SkillVar skillPass = player.GetSkill_BasicPass(); if (skillPass.IsReady && player.IsMyBall()) { if (locomotion.inNormal) { if (locomotion.TriggerPass()) { skillPass.TriggerCooldown(); } else { playerToPass = null; GameManager.instance.ResetIndicator(); } } } else { playerToPass = null; GameManager.instance.ResetIndicator(); } } //JUMP if (ControllerInput.GetButtonDown(player.GetInputType(), player.GetInputs().Input_Jump)) { locomotion.jump = true; } if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Jump)) { locomotion.jump = false; } }
// this is called every frame void IControllerProvider.ReadState(ControllerState outState) { lock (state) { if (ctrl != null) { XDevicePlugin.UpdateInputState(handle); XDevicePlugin.GetInputState(handle, ref m_leftControllerState); state.orientation = new Quaternion( -m_leftControllerState.rotation[0], -m_leftControllerState.rotation[1], m_leftControllerState.rotation[2], m_leftControllerState.rotation[3] ); state.gyro = new Vector3( -m_leftControllerState.gyroscope[0], -m_leftControllerState.gyroscope[1], m_leftControllerState.gyroscope[2] ); state.accel = new Vector3( m_leftControllerState.accelerometer[0], m_leftControllerState.accelerometer[1], -m_leftControllerState.accelerometer[2] ); state.touchPos = ctrl.touchPos; // GVR Hack Detection Controller if (ctrl.connectionState == DeviceConnectionState.Connected) { state.connectionState = GvrConnectionState.Connected; } else if (ctrl.connectionState == DeviceConnectionState.Connecting) { state.connectionState = GvrConnectionState.Connecting; } else { state.connectionState = GvrConnectionState.Disconnected; } // GVR Input Mapping state.apiStatus = GvrControllerApiStatus.Ok; state.appButtonState = ctrl.GetButton(XimmerseButton.App); state.appButtonDown = ctrl.GetButtonDown(XimmerseButton.App); state.appButtonUp = ctrl.GetButtonUp(XimmerseButton.App); state.homeButtonDown = ctrl.GetButtonDown(XimmerseButton.Home); state.homeButtonState = ctrl.GetButton(XimmerseButton.Home); state.clickButtonDown = ctrl.GetButtonDown(XimmerseButton.Click) || ctrl.GetButtonDown(XimmerseButton.Trigger); state.clickButtonState = ctrl.GetButton(XimmerseButton.Click) || ctrl.GetButton(XimmerseButton.Trigger); state.clickButtonUp = ctrl.GetButtonUp(XimmerseButton.Click) || ctrl.GetButtonUp(XimmerseButton.Trigger); // GVR Battery Indicator if (ctrl.batteryLevel > 80) { state.batteryLevel = GvrControllerBatteryLevel.Full; } if (ctrl.batteryLevel > 60 && ctrl.batteryLevel <= 80) { state.batteryLevel = GvrControllerBatteryLevel.AlmostFull; } if (ctrl.batteryLevel > 40 && ctrl.batteryLevel <= 60) { state.batteryLevel = GvrControllerBatteryLevel.Medium; } if (ctrl.batteryLevel > 20 && ctrl.batteryLevel <= 40) { state.batteryLevel = GvrControllerBatteryLevel.Low; } if (ctrl.batteryLevel >= 0 && ctrl.batteryLevel <= 20) { state.batteryLevel = GvrControllerBatteryLevel.CriticalLow; } // GVR Recenter Touchpad Detection if (ctrl.GetButtonDown(ControllerButton.PrimaryThumbMove) || ctrl.GetButtonDown(XimmerseButton.Click)) { state.touchDown = true; state.isTouching = true; } if (ctrl.GetButton(ControllerButton.PrimaryThumbMove) || ctrl.GetButton(XimmerseButton.Click)) { state.isTouching = true; } if (ctrl.GetButtonUp(ControllerButton.PrimaryThumbMove) || ctrl.GetButtonUp(XimmerseButton.Click)) { state.touchUp = true; state.isTouching = false; } // GVR Recenter Interactions state.gvrPtr = IntPtr.Zero; if (ctrl.GetButtonUp(XimmerseButton.Home)) { GvrCardboardHelpers.Recenter(); ctrl.Recenter(); state.recentered = true; } } else { if (EnableXdevice == false && FlipAppInstalled() == true) { EnableXdevice = true; XDevicePlugin.Init(); handle = XDevicePlugin.GetInputDeviceHandle("XCobra-0"); ctrl = new ControllerInput(handle); } state.connectionState = GvrConnectionState.Disconnected; state.clickButtonState = false; state.clickButtonDown = false; state.clickButtonUp = false; state.appButtonState = false; state.appButtonDown = false; state.appButtonUp = false; } outState.CopyFrom(state); } state.ClearTransientState(); }
// Update is called once per frame void Update() { SmootIKWeight(); PlayerController mnPlayer; mnPlayer = player.GetPlayerNear(); //Estica maos para o jogaodr mais proximo HandleHandsTo(mnPlayer); if (jointPlayer) { if (!player.isOk || player.Locomotion.inStumble || player.Locomotion.inTrack || player.IsMyBall() || !jointPlayer.isOk || !player.GetSkill_BasicActionOne().IsReady ) { RemoveJoint(); } } else if (player.Locomotion.inHoldTug) { if (mnPlayer != null && !player.Locomotion.inAir && player.isOk && !mnPlayer.IsMyTeaM(player)) { float dist = mnPlayer.Distance(player); if (dist <= tugWarDistance && dist > 0.5f && mnPlayer.isOk && !mnPlayer.Locomotion.inAir) { //JOINT player.Locomotion.JointTo(mnPlayer); jointPlayer = mnPlayer; jointPlayer.GetAnimatorEvents().OnChangeDirStart += EnemyOnChangeDir; } } } //CONTROLE MANUAL if (!player.IsIA) { if (player.IsMyBall() || player.isOk == false) { if (player.Locomotion.inHoldTug) { player.Locomotion.ResetHoldTugAnimator(); } player.GetSkill_BasicActionOne().mode = SkillVarMode.autoSubtract; return; } if (ControllerInput.GetButton(player.GetInputType(), player.GetInputs().Input_Kick) && player.isOk) { SkillVar skilltug = player.GetSkill_BasicActionOne(); skilltug.SetToggle(); if (skilltug.IsMax) { skilltug.TriggerCooldown(); } if (skilltug.IsReady) { skilltug.mode = SkillVarMode.autoRegen; if (jointPlayer == null) { player.Locomotion.SetHoldTugAnimator(); } else { player.Locomotion.ResetHoldTugAnimator(); } } else { skilltug.SetCurrentValue(0); skilltug.mode = SkillVarMode.nothing; player.Locomotion.ResetHoldTugAnimator(); } } if (ControllerInput.GetButtonUp(player.GetInputType(), player.GetInputs().Input_Kick)) { SkillVar skilltug = player.GetSkill_BasicActionOne(); if (skilltug.isToggle == false) { return; } skilltug.mode = SkillVarMode.autoSubtract; player.Locomotion.ResetHoldTugAnimator(); skilltug.ResetTogle(); if (skilltug.IsReady) { RemoveJoint(); } } } }