public void ProcessInputs(InputPackage p) { Player?.ProcessInputs(p); }
// Update is called once per frame void Update() { inputPackage = inputController.InputPackage; if (!beatBox.IsOnBeat(100)) { beat = false; } #region TriggerResets anim.ResetTrigger("jumping"); anim.ResetTrigger("attacking"); anim.ResetTrigger("evasion"); anim.ResetTrigger("evasionRight"); anim.ResetTrigger("evasionLeft"); #endregion if (evasion) { if (!blockRotationPlayer) { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(desiredMoveDirection), desiredRotationSpeed); } controller.Move(desiredMoveDirection * Time.deltaTime * evasionSpeed); StartCoroutine(animationLock()); } if (!animationLocked) { if (inputPackage.CameraButton) { ChangePlayerStance(nextStance); } if (inputPackage.InputA) { if (beatBox.IsOnBeat(100) && stanceChargeLevel < 4 && !beat) { stanceChargeLevel++; Debug.Log("StanceChargeLevel: " + stanceChargeLevel); beat = true; } Jump(); } if (inputPackage.TriggerRight != 0) { if (beatBox.IsOnBeat(100) && stanceChargeLevel < 4 && !beat) { stanceChargeLevel++; Debug.Log("StanceChargeLevel: " + stanceChargeLevel); beat = true; } Attack(); StartCoroutine(animationLock()); } if (inputPackage.InputB) { if (beatBox.IsOnBeat(100) && stanceChargeLevel < 4 && !beat) { stanceChargeLevel++; Debug.Log("StanceChargeLevel: " + stanceChargeLevel); beat = true; } var forward = cam.transform.forward; var right = cam.transform.right; forward.y = 0f; right.y = 0f; forward.Normalize(); right.Normalize(); desiredMoveDirection = forward * InputZ + right * InputX; Evade(); StartCoroutine(animationLock()); } InputMagnitude(); isGrounded = controller.isGrounded; if (isGrounded) { verticalVel = 0; } else { verticalVel -= 2; } moveVector = new Vector3(0, verticalVel, 0); controller.Move(moveVector); } }
public override void HandleInput(InputPackage p) { }
// called every frame from context manager public override void HandleInput(InputPackage p) { if (!Won) { if (p.Touchdown) { if (p.TouchdownChange) { // clicked Tile t = Physics2D.OverlapCircleAll(p.MousePositionWorldSpace, 3f, tileMask) // roughly 1/3 of a tile of tap tolerance .Select(g => g.GetComponent <Tile>()) .Where(g => g != null && g.Movable) .OrderBy(g => Vector2.Distance(p.MousePositionWorldSpace, g.transform.position)) .FirstOrDefault(); if (t != null) { SelectedTile = t; grabPoint = p.MousePositionWorldSpace; SelectedTile.Select(true); MMVibrationManager.Haptic(HapticTypes.Selection); grabMovingVelocityAverage = Vector2.zero; } #if UNITY_EDITOR if (ShowFingerprint) { Fingerprint = GetComponentInChildren <Fingerprint>(true); Fingerprint.gameObject.SetActive(true); Fingerprint.transform.position = p.MousePositionWorldSpace; } #endif } else if (SelectedTile != null) { grabMovingVelocityAverage = p.MousePositionWorldSpaceDelta * 0.1f + grabMovingVelocityAverage * 0.9f; float scale = SelectedTile.transform.lossyScale.x; Vector2 moveAmount = (p.MousePositionWorldSpace - grabPoint) / scale; Tilespace tileBeforeMove = SelectedTile.Space; bool changedTilespaces = SelectedTile.TryMoveToPosition(SelectedTile.GetPositionFromInput(moveAmount), p.MousePositionWorldSpaceDelta); if (changedTilespaces) { if (SelectedTile.Space.Sticky) { SelectedTile = null; } else { Vector3 move = ((Vector2)SelectedTile.transform.position - SelectedTile.PositionWhenSelected); grabPoint += move; if (Mathf.Abs(move.y) > Mathf.Abs(move.x) && Mathf.Abs(moveAmount.x) < 2 * Tile.BaseThreshold) { grabPoint.x = p.MousePositionWorldSpace.x; } else if (Mathf.Abs(moveAmount.y) < 2 * Tile.BaseThreshold) { grabPoint.y = p.MousePositionWorldSpace.y; } SelectedTile.Select(true); } } if (!TimerRunning && !Won && !SelectedTile.Centered) { StartTimer(); } } Vector3 position = p.MousePositionWorldSpace + Player.Direction * -8.5f; if (Vector2.Distance(Player.transform.position, p.MousePositionWorldSpace) < 5) { Preview.Show(true, position); Preview.WatchedPosition = Player.transform.position; } else { Preview.Show(false, position); } #if UNITY_EDITOR if (Fingerprint != null) { Fingerprint.transform.position = p.MousePositionWorldSpace; } #endif } else if (!p.Touchdown && p.TouchdownChange) { Preview.Show(false); if (SelectedTile != null) { Vector2 avgOnRelease = grabMovingVelocityAverage; if (!SelectedTile.Centered) { avgOnRelease *= SelectedTile.NormalizedPosition; } //Debug.Log(avgOnRelease); SelectedTile.SetResidualVelocity(avgOnRelease); SelectedTile.Select(false); SelectedTile = null; } #if UNITY_EDITOR if (Fingerprint != null) { Fingerprint.gameObject.SetActive(false); } #endif } } }
// Use this for initialization void Start() { package = new InputPackage(); }
public abstract void HandleInput(InputPackage p);
void Thread_Recive() { #if MOBILE_EDITION return; #endif try { InputCmdTrans = new int[LenInputDataPerCtrller, 2]; for (int i = 0; i != LenInputDataPerCtrller; ++i) InputCmdTrans[i, 0] = i; InputCmdTrans[0,1] = (int)InputCmd.InCoin; InputCmdTrans[1,1] = (int)InputCmd.BtnE; InputCmdTrans[2,1] = (int)InputCmd.OutTicket; InputCmdTrans[3,1] = (int)InputCmd.OutCoin; InputCmdTrans[4,1] = (int)InputCmd.Up; InputCmdTrans[5,1] = (int)InputCmd.Down; InputCmdTrans[6,1] = (int)InputCmd.Left; InputCmdTrans[7,1] = (int)InputCmd.Right; InputCmdTrans[8,1] = (int)InputCmd.BtnA; InputCmdTrans[9,1] = (int)InputCmd.BtnB; InputCmdTrans[10,1] = (int)InputCmd.BtnC; InputCmdTrans[11,1] = (int)InputCmd.BtnD; //取消,左,右,小游戏,确定,下 BackStageInputCmdTrans = new int[12]; BackStageInputCmdTrans[0] = (int)InputCmd.Up; BackStageInputCmdTrans[1] = (int)InputCmd.BtnB; BackStageInputCmdTrans[2] = (int)InputCmd.Left; BackStageInputCmdTrans[3] = (int)InputCmd.Right; BackStageInputCmdTrans[4] = (int)InputCmd.BtnC; BackStageInputCmdTrans[5] = (int)InputCmd.BtnA; BackStageInputCmdTrans[6] = (int)InputCmd.Down; if (mOutputBuff == null) mOutputBuff = new BitArray((LenOuputBuf - 1) * 8 );//输入bitarray 减少一字节.以便.复制的时候向右移位 BitArray tmpBA = null;//当前InputBitArray byte[] tmpOutputBuff = new byte[LenOuputBuf]; byte[] tmpInputBuff = new byte[LenInputBuf]; byte[] tmpPreInputBuff = new byte[LenInputBuf]; List<InputPackage> tmpRecivePack = new List<InputPackage>(); if (mOuttingCoinTag == null) mOuttingCoinTag = new Dictionary<int, OutBountyElapse>(); if (mOuttingTicketTag == null) mOuttingTicketTag = new Dictionary<int, OutBountyElapse>(); List<int> tmpListI = new List<int>(); int offsetRead = 8;//读缓冲向右移8 bit uint numWrite = 0; uint readCount = 0; mRndObj = new System.Random(); //读取一次状态 mWriteOL.Clear(); Array.Clear(tmpOutputBuff, 0, tmpOutputBuff.Length); Win32Usb.WriteFile(mIOHandler, tmpOutputBuff, (uint)tmpOutputBuff.Length, ref numWrite, ref mWriteOL); if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//读取 { Win32Usb.ReadFile(mIOHandler, tmpInputBuff, (uint)tmpInputBuff.Length, ref readCount, ref mReadOL); //接收包 if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0) { mInputBuff = new BitArray(tmpInputBuff); #if RECORE_INITSTATE mInputBuffInit = new BitArray(tmpInputBuff); #endif //初始化控制板状态 for (int i = OfsInput_ControlBoardState + offsetRead; i != OfsInput_ControlBoardState + offsetRead + NumControlBoard; ++i) { tmpRecivePack.Add(new InputPack_CtrlBoardState(InputPackCmd.CtrlBoardConnectState , 0, i - OfsInput_ControlBoardState - offsetRead, mInputBuff[i]));//控制板状态 } _FlushInputPackToMainThread(tmpRecivePack); } Thread.Sleep(100); } #region 测试程序 /* bool enableOutCoin = false; while (mThreadLoopRecive && mIOHandler != IntPtr.Zero) { mWriteOL.Clear(); Array.Clear(tmpOutputBuff, 0, tmpOutputBuff.Length); mOutputBuff[0 * LenOuputDataPerCtrller + OfsOutput_OutCoin] = enableOutCoin; enableOutCoin = !enableOutCoin; mOutputBuff.CopyTo(tmpOutputBuff, 1); Win32Usb.WriteFile(mIOHandler, tmpOutputBuff, (uint)tmpOutputBuff.Length, ref numWrite, ref mWriteOL); if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//发送完成 { Thread.Sleep(1); Win32Usb.ReadFile(mIOHandler, tmpInputBuff, (uint)tmpInputBuff.Length, ref readCount, ref mReadOL); //接收包 if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//接收完成 { mInputBuff = new BitArray(tmpInputBuff); //Thread.Sleep(1); //初始化控制板状态 //for (int i = OfsInput_ControlBoardState + offsetRead; i != OfsInput_ControlBoardState + offsetRead + NumControlBoard; ++i) //{ // tmpRecivePack.Add(new InputPack_CtrlBoardState(InputPackCmd.CtrlBoardConnectState // , 0, i - OfsInput_ControlBoardState - offsetRead, mInputBuff[i]));//控制板状态 //} //_FlushInputPackToMainThread(tmpRecivePack); } } } */ #endregion while (mThreadLoopRecive && mIOHandler != IntPtr.Zero) { if (Evt_HSThread_FrameStart != null) Evt_HSThread_FrameStart(); if (Monitor.TryEnter(mSendPack_ThreadLock)) { List<OutputPackage> tempList = mPackToSendST; mPackToSendST = mPackToSendMT; mPackToSendMT = tempList; Monitor.Exit(mSendPack_ThreadLock); } foreach (OutputPackage pack in mPackToSendST) { switch (pack.Cmd) { case OutputPackCmd.OutCoin: mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_OutCoin] = ((OutputPack_OutBounty)pack).Enable; if (!mOuttingCoinTag.ContainsKey(pack.CtrllerIdx)) mOuttingCoinTag.Add(pack.CtrllerIdx, new OutBountyElapse(DateTime.Now.Ticks)); else Debug.LogWarning("重复出币调用"); break; case OutputPackCmd.OutTicket: mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_OutTicket] = ((OutputPack_OutBounty)pack).Enable; if (!mOuttingTicketTag.ContainsKey(pack.CtrllerIdx)) mOuttingTicketTag.Add(pack.CtrllerIdx, new OutBountyElapse(DateTime.Now.Ticks)); else Debug.LogWarning("重复出票调用"); break; case OutputPackCmd.FlashLight: { OutputPack_Light lightPack = (OutputPack_Light)pack; if (lightPack.LightIdx == 0) mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_Light0] = lightPack.IsOn; else mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_Light1] = lightPack.IsOn; } break; case OutputPackCmd.RequestMCUInfo: { tmpOutputBuff[1] = tmpOutputBuff[tmpOutputBuff.Length - 1] = 1; System.Random randObj = new System.Random(); int challengeNum = randObj.Next(int.MinValue, int.MaxValue); //发出要求MCU验证的数字 System.Array.Copy(System.BitConverter.GetBytes(challengeNum), 0, tmpOutputBuff, 2, 4); mWriteOL.Clear(); Win32Usb.WriteFile(mIOHandler, tmpOutputBuff, (uint)tmpOutputBuff.Length, ref numWrite, ref mWriteOL); if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//读取 { Win32Usb.ReadFile(mIOHandler, tmpInputBuff, (uint)tmpInputBuff.Length, ref readCount, ref mReadOL); bool verfySucess = true; if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read,true) == 0) { if (tmpInputBuff[1] == tmpInputBuff[tmpInputBuff.Length - 1] && tmpInputBuff[1] == 1) { HMACMD5 cryptor = new HMACMD5(System.Text.Encoding.ASCII.GetBytes("yidingyaochang")); byte[] challengeAnswer = cryptor.ComputeHash(System.BitConverter.GetBytes(challengeNum)); for (int i = 0; i != challengeAnswer.Length; ++i) { if (challengeAnswer[i] != tmpInputBuff[7 + i]) { verfySucess = false; break; } } } else//验证失败 { verfySucess = false; } } else//验证失败 { verfySucess = false; } if (verfySucess) { tmpRecivePack.Add(new InputPack_MCUInfo(InputPackCmd.MCUInfo, 0, true, tmpInputBuff[2],//游戏序号 System.BitConverter.ToUInt16(tmpInputBuff, 3),//主版本号 System.BitConverter.ToUInt16(tmpInputBuff, 5)//副版本号 )); } else { tmpRecivePack.Add(new InputPack_MCUInfo(InputPackCmd.MCUInfo, 0, false, -1, 0, 0)); } _FlushInputPackToMainThread(tmpRecivePack); } } break; case OutputPackCmd.EditMCUInfo: { OutputPack_EditMCUInfo op = (OutputPack_EditMCUInfo)pack; bool result = _UsbThread_ChangeMCUInfo(op.GameIdx, op.MainVersion, op.SubVersion); tmpRecivePack.Add(new InputPack_ResultEditMCUInfo(InputPackCmd.ResultEditMCUInfo, 0, result)); _FlushInputPackToMainThread(tmpRecivePack); } break; case OutputPackCmd.ReadWriteRequest://有读写请求的,直接进行读取处理 { OutputPack_ReadWriteRequest p = (OutputPack_ReadWriteRequest)pack; //包标识 tmpOutputBuff[1] = 0xf2; //读写标记 tmpOutputBuff[2] = (byte)(p.IsWrite ? 1 : 0); //地址 Array.Copy(System.BitConverter.GetBytes(p.Address), 0, tmpOutputBuff, 3, 4); //数据长度 tmpOutputBuff[7] = p.DataLength; //数据 if(p.Data != null) Array.Copy(p.Data, 0, tmpOutputBuff, 8, p.DataLength); //随机数填充 Byte[] tmpByte = new byte[5]; mRndObj.NextBytes(tmpByte); Array.Copy(tmpByte, 0, tmpOutputBuff, 24, 5); //校验码 Array.Clear(tmpByte,0,5); for (int i = 0; i != 4; ++i) { for (int j = 0; j != 7; ++j) { tmpByte[i] ^= tmpOutputBuff[j * 4 + i + 1]; } } Array.Copy(tmpByte, 0, tmpOutputBuff, 29, 4); //Debug.Log(string.Format("adress:{0:d} len:{1:d} ", p.Address, p.DataLength)); //Debug.Log("w"); //发出消息 mWriteOL.Clear(); Win32Usb.WriteFile(mIOHandler, tmpOutputBuff, (uint)tmpOutputBuff.Length, ref numWrite, ref mWriteOL); //读取消息 if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//读取 { Win32Usb.ReadFile(mIOHandler, tmpInputBuff, (uint)tmpInputBuff.Length, ref readCount, ref mReadOL); if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0) { //验证包是否正常 if(tmpInputBuff[1] != 0xF2) goto BREAK_THIS_SWITCH; //校验码是否正确 Byte[] tmpByte4 = new byte[4]; for (int i = 0; i != 4; ++i) { for (int j = 0; j != 7; ++j) { tmpByte4[i] ^= tmpInputBuff[j * 4 + i + 1]; } } for(int i = 0; i != 4; ++i) { if(tmpByte4[i] != tmpInputBuff[29+i]) goto BREAK_THIS_SWITCH; } //Array.Copy(tmpInputBuff, 3, tmpByte4, 0, 4); uint adress = System.BitConverter.ToUInt32(tmpInputBuff,3); byte dataLen = tmpInputBuff[7]; byte[] dataOut = null; if(tmpInputBuff[2] == 0)//读取标记 { dataOut = new byte[dataLen]; Array.Copy(tmpInputBuff,9,dataOut,0,dataLen); } //开始组包 tmpRecivePack.Add(new InputPack_ResultReadWrite(InputPackCmd.ResultReadWrite , tmpInputBuff[2] == 0 ? false : true,//读写标记 adress,//地址 dataLen,//包长度 tmpInputBuff[8],//读写结果 dataOut//包 )); //Debug.Log(string.Format("adress:{0:d} datalen{1:d} resultcode:{2:d} ",adress,dataLen,tmpInputBuff[8])); _FlushInputPackToMainThread(tmpRecivePack); } } } BREAK_THIS_SWITCH: break; } } mPackToSendST.Clear(); //发出数据 mOutputBuff.CopyTo(tmpOutputBuff, 1); mWriteOL.Clear(); Win32Usb.WriteFile(mIOHandler, tmpOutputBuff, (uint)tmpOutputBuff.Length, ref numWrite, ref mWriteOL); //Thread.Sleep(5); if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) != 0)//读超时 { goto TAG_INPUT_PROCESS;//读超时,则跳过缺币检测 } //缺币检测(提高扫描速度) tmpListI.Clear(); foreach (KeyValuePair<int, OutBountyElapse> kvp in mOuttingCoinTag) { if (DateTime.Now.Ticks - kvp.Value.Time > Timeout_Outbounty)//超时放入删除列表 tmpListI.Add(kvp.Key); } foreach (int ctrlIdx in tmpListI) { tmpRecivePack.Add(new InputPackage(InputPackCmd.LackCoin, ctrlIdx));//发送包 mOutputBuff[ctrlIdx * LenOuputDataPerCtrller + OfsOutput_OutCoin] = false;//关闭出币口 mOuttingCoinTag.Remove(ctrlIdx); } //缺票处理 tmpListI.Clear(); foreach (KeyValuePair<int, OutBountyElapse> kvp in mOuttingTicketTag) { if (DateTime.Now.Ticks - kvp.Value.Time > Timeout_Outbounty)//超时放入删除列表 tmpListI.Add(kvp.Key); } foreach (int ctrlIdx in tmpListI) { tmpRecivePack.Add(new InputPackage(InputPackCmd.LackTicket, ctrlIdx)); mOutputBuff[ctrlIdx * LenOuputDataPerCtrller + OfsOutput_OutTicket] = false;//关闭出票口 mOuttingTicketTag.Remove(ctrlIdx); } TAG_INPUT_PROCESS: //接收数据 mReadOL.Clear(); Win32Usb.ReadFile(mIOHandler, tmpInputBuff, (uint)tmpInputBuff.Length, ref readCount, ref mReadOL); //接收包 if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0) { //检测有变化 #region 检查接受内容是否有变化,没有变化则跳过(这里先对字节循环,而不是比特,提高效率) int idxValid = 0;//验证到的索引 for(idxValid = 0; idxValid != tmpPreInputBuff.Length;++idxValid) { if(tmpPreInputBuff[idxValid] != tmpInputBuff[idxValid]) { break; } } if (idxValid == tmpPreInputBuff.Length)//前一帧包与当前包一致 { //goto TAG_BREAK_INPUT; } else { tmpInputBuff.CopyTo(tmpPreInputBuff, 0); } #endregion tmpBA = new BitArray(tmpInputBuff); int validDataEnd = LenInputDataPerCtrller * NumCtrller + offsetRead; for (int i = offsetRead; i != validDataEnd; ++i) { if (tmpBA[i] != mInputBuff[i]) { int ctrlIdx = (i - offsetRead) / LenInputDataPerCtrller; InputCmd dataIdx = (InputCmd)InputCmdTrans[((i - offsetRead) % LenInputDataPerCtrller), ctrlIdx % 2]; switch (dataIdx) { case InputCmd.Up: case InputCmd.Down: case InputCmd.Left: case InputCmd.Right: case InputCmd.BtnA: case InputCmd.BtnB: case InputCmd.BtnC: case InputCmd.BtnD: case InputCmd.BtnE: { if (FuncHSThread_AddKeyPress == null) { InputPack_Key pack = new InputPack_Key(InputPackCmd.Key, ctrlIdx, dataIdx, tmpBA[i]); tmpRecivePack.Add(pack); } else { if (FuncHSThread_AddKeyPress(ctrlIdx, dataIdx , tmpBA[i])) { InputPack_Key pack = new InputPack_Key(InputPackCmd.Key, ctrlIdx, dataIdx, tmpBA[i]); tmpRecivePack.Add(pack); } } //InputPack_Key pack = new InputPack_Key(InputPackCmd.Key, ctrlIdx, dataIdx, tmpBA[i]); //tmpRecivePack.Add(pack); } break; case InputCmd.InCoin: { if (tmpBA[i]) { InputPackage pack = new InputPackage(InputPackCmd.InsertCoin, ctrlIdx); tmpRecivePack.Add(pack); } } break; case InputCmd.OutCoin: { #if RECORE_INITSTATE if (tmpBA[i] == mInputBuffInit[i]) #else if (tmpBA[i]) #endif { InputPackage pack = new InputPackage(InputPackCmd.OutCoin, ctrlIdx); tmpRecivePack.Add(pack); //重置出币 mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_OutCoin] = false; mOuttingCoinTag.Remove(pack.CtrllerIdx); } } break; case InputCmd.OutTicket: { #if RECORE_INITSTATE if (tmpBA[i] == mInputBuffInit[i]) #else if (tmpBA[i]) #endif { InputPackage pack = new InputPackage(InputPackCmd.OutTicket, ctrlIdx); tmpRecivePack.Add(pack); //重置出票 mOutputBuff[pack.CtrllerIdx * LenOuputDataPerCtrller + OfsOutput_OutTicket] = false; mOuttingTicketTag.Remove(pack.CtrllerIdx); } } break; }//switch }//if (tmpBA[i] != mInputBuff[i])判断是否改变了 }//for (int i = 0; i != validData; ++i)每个有效数据循环, //控制板状态 for (int i = OfsInput_ControlBoardState + offsetRead; i != OfsInput_ControlBoardState + offsetRead + NumControlBoard; ++i) { if (tmpBA[i] != mInputBuff[i]) { tmpRecivePack.Add(new InputPack_CtrlBoardState(InputPackCmd.CtrlBoardConnectState , 0, i - OfsInput_ControlBoardState - offsetRead, tmpBA[i]));//控制板状态 } } //Debug.Log("pBA[257]=" + tmpBA[257]); //后台按键判断 //上,取消,左,右,小游戏,确定,下 for (int i = OfsInput_BsKeyStartBit + offsetRead; i != OfsInput_BsKeyEndBit + offsetRead; ++i) { if (tmpBA[i] != mInputBuff[i]) { InputPack_Key pack = new InputPack_Key(InputPackCmd.Key, 21, (InputCmd)BackStageInputCmdTrans[i - OfsInput_BsKeyStartBit - offsetRead], tmpBA[i]); tmpRecivePack.Add(pack); } } mInputBuff = tmpBA; foreach (InputPackage p in mInputPackageFromPlugin) { tmpRecivePack.Add(p); } mInputPackageFromPlugin.Clear(); _FlushInputPackToMainThread(tmpRecivePack); //TAG_BREAK_INPUT: ; }//if (Win32Usb.WaitForSingleObjectEx(mIOHandler, Timeout_Read, true) == 0)//等待读取超时 }//while //线程while循环 }//try catch (System.TimeoutException) { Debug.LogError("time out"); } catch (System.Exception ex) { Debug.LogError("SerialThreadUpdate Exception:" + ex.Message); } finally { Debug.Log("thread exit"); } }
public void Think(out InputPackage inputs) { inputs = workingInputs; workingInputs.ResetPressReleased(); }
/// <summary> /// 有外部加入的输入Package /// </summary> /// <param name="p"></param> public void AddInputPackage(InputPackage p) { #if MOBILE_EDITION return; #endif if (!IsOpen()) return; mInputPackageFromPlugin.Add(p); }
public InputController() { main = Camera.main; package = new InputPackage(); }
public void HandleInput(InputPackage p) { ContextManager.HandleInput(p); }
public void ProcessInputs(InputPackage p) { var dir = new Vector2(p.Horizontal, p.Vertical); targetSpeed = dir.magnitude * MaxMovespeed * (CarriedBox?.MovespeedModifier ?? 1) * Time.fixedDeltaTime; moveDirection = dir.normalized; bool canPickup = false; var direction = ((Vector3)p.MouseLocation - transform.position).normalized; if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) { this.transform.localRotation = Quaternion.Euler(0, 0, 90f * Mathf.Sign(direction.x)); anim.SetBool("Reverse", Mathf.Sign(direction.x) * moveDirection.x < 0); } else { this.transform.localRotation = Quaternion.Euler(0, 0, direction.y < 0 ? 0 : 180); anim.SetBool("Reverse", Mathf.Sign(direction.y) * moveDirection.y < 0); } var box = Physics2D.RaycastAll(p.MouseLocation, Vector2.one, 0, BoxHighlingLayers) .Where(g => g.collider != null && g.collider.gameObject != CarriedBox?.gameObject) .Select(g => g.collider.GetComponent <Box>()) .FirstOrDefault(g => g.Interactable); if (box != null) { var mousedBox = box; if (mousedBox != null && !mousedBox.IsAirborn) { if (highlightedBox != mousedBox) { if (highlightedBox != null) { highlightedBox.OutlineColor = Color.clear; } highlightedBox = mousedBox; } if (CarriedBox != null) { canPickup = Vector2.Distance(CarriedBox.transform.position, highlightedBox.transform.position) < 0.3f; } else { canPickup = Vector2.Distance(transform.position, highlightedBox.transform.position) < 1.25f; } highlightedBox.OutlineColor = canPickup ? Color.green : Color.red; } } else { if (highlightedBox != null) { highlightedBox.OutlineColor = Color.clear; } highlightedBox = null; } if (CarriedBox == null) { if (p.MouseClick != MouseInput.NONE && canPickup) { //pick up box CarriedBox = highlightedBox; highlightedBox = null; carriedBoxDistance = Vector3.Distance(transform.position, CarriedBox.transform.position); CarriedBox.PickedUp(this.transform); } } else { CarriedBox.transform.localPosition = transform.position + ((Vector3)p.MouseLocation - transform.position).normalized * carriedBoxDistance; if (CarriedBoxPositionValid()) { if (p.MouseClick == MouseInput.RIGHT) { // throw box CarriedBox.Throw(moveDirection * currentSpeed, ((Vector3)p.MouseLocation - transform.position).normalized); CarriedBox = null; } else if (p.MouseClick == MouseInput.LEFT) { //place box CarriedBox.Place(box); CarriedBox = null; } } } }
public void ProcessInputs(InputPackage p) { throw new System.NotImplementedException(); }