public void ChangeState(CState aNextState) { mBeforeState = mState; mState = aNextState; mIsInit = true; mStateTime = 0.0f; }
void UpdateFromMoving() { //初期化 if (mNeedInitState == true) { mNeedInitState = false; mFloorModel.transform.localPosition = Vector3.zero; } //処理 Vector3 lVibration = GetFloorPositionAnimation(mStateTime, mFromMovingTime, mFromMovingHz, mFromMovingAmp); VibrationFloor(lVibration); //重さに応じた場所まで、現在の場所から遠いなら Vector3 lTargetLocalPosition = GetTargetLocalPosition(); if (!ReachFloor(lTargetLocalPosition)) { mState = CState.cToMoving; return; } if (mStateTime >= mFromMovingTime) { MoveFloorByMoveManager(lTargetLocalPosition); mState = CState.cStay; } }
private int ReadSubState(int nSubSTateCnt, string path) { if (path == null || nSubSTateCnt == 0 || path == "") { Debug.LogError("SubState Init Error. SubState Info is invalid. File:" + path); return(-1); } if (nSubSTateCnt < 0 || nSubSTateCnt >= 100) { Debug.LogError("SubState Init Error. SubState Count is invalid. File:" + path); return(-1); } int ret = 0; for (int i = 0; i < nSubSTateCnt; i++) { string stateName = String.Format("State{0:00}", i); CState state = new CState(m_stateMgr, this); if (state.LoadFromFile(path, stateName)) { m_mapSubState.Add(state.type, state); ret++; } } return(ret); }
//Called for every fixedupdate that this module is active public override void FixedUpdateModule() { if (!m_ControlledCollider.GetSideCastInfo().m_HasHitSide || (!m_ControlledCollider.IsPartiallyTouchingWall())) { return; } m_WallNormal = m_ControlledCollider.GetSideCastInfo().GetSideNormal(); float distance = m_ControlledCollider.GetSideCastInfo().GetDistance(); m_ControlledCollider.GetCapsuleTransform().Move(-m_WallNormal * distance); m_RotateMethod = (m_WallNormal.y < 0) ? RotateMethod.FromTop : RotateMethod.FromBottom; m_UpDirection = CState.GetDirectionAlongNormal(Vector3.up, m_WallNormal); m_ControlledCollider.RotateToAlignWithNormal(m_UpDirection, m_RotateMethod); Vector2 currentVel = m_ControlledCollider.GetVelocity(); Vector2 fGravity = -m_UpDirection *m_WallRunGravity *Vector2.Dot(-m_UpDirection, Vector2.down); //Gravity along wall, but with correct velocity Vector2 fDrag = -0.5f * (currentVel.sqrMagnitude) * m_CharacterController.GetDragConstant() * currentVel.normalized; if (!m_ApplyDrag) { fDrag = Vector2.zero; } Vector2 summedF = fGravity + fDrag; Vector2 newVel = currentVel + (summedF * Time.fixedDeltaTime); m_ControlledCollider.UpdateWithVelocity(newVel); }
private void SetupRandPartA() { if (this.su_i2 <= this.last) { this.su_chPrev = this.su_ch2; int su_ch2Shadow = this.data.ll8[this.su_tPos] & 0xff; this.su_tPos = this.data.tt[this.su_tPos]; if (this.su_rNToGo == 0) { this.su_rNToGo = Rand.Rnums(this.su_rTPos) - 1; if (++this.su_rTPos == 512) { this.su_rTPos = 0; } } else { this.su_rNToGo--; } this.su_ch2 = su_ch2Shadow ^= (this.su_rNToGo == 1) ? 1 : 0; this.su_i2++; this.currentChar = su_ch2Shadow; this.currentState = CState.RAND_PART_B; this.crc.UpdateCRC((byte)su_ch2Shadow); } else { EndBlock(); InitBlock(); SetupBlock(); } }
private CState <entity_type> m_pGlobalState; //全局状态 /*状态机构造函数*/ public CStateMachine(entity_type owner) { m_pOwner = owner; m_pCurrentState = null; m_pPreviousState = null; m_pGlobalState = null; }
//Query whether this module can be active, given the current state of the character controller (velocity, isGrounded etc.) //Called every frame when inactive (to see if it could be) and when active (to see if it should not be) public override bool IsApplicable() { if (m_ControlledCollider.IsGrounded()) { return(false); } //Wall needs to be hit for the module to be active if (m_ControlledCollider.GetSideCastInfo().m_HasHitSide) { if (!m_ControlledCollider.IsPartiallyTouchingWall()) { return(false); } m_WallNormal = m_ControlledCollider.GetSideCastInfo().GetSideNormal(); m_RotateMethod = (m_WallNormal.y < 0) ? RotateMethod.FromTop : RotateMethod.FromBottom; m_UpDirection = CState.GetDirectionAlongNormal(Vector3.up, m_WallNormal); if (!m_ControlledCollider.CanAlignWithNormal(m_UpDirection)) { return(false); } return(true); } return(false); }
public bool IsCurState(CState State) { if (curState == null) { return(false); } return((curState == State) ? true : false); }
public virtual bool check(CState lastState) { if (m_info.check != null) { return(StateCheck(lastState)); } return(true); }
//Easy way to get a direction along the ground public override Vector2 GetWalkDirection(Vector2 a_Speed) { if (a_Speed.x == 0 || !m_IsGrounded) { return(Vector2.zero); } return(CState.GetDirectionAlongNormal(a_Speed, GetNormal())); }
public bool IsCurState(CState kState) { if (m_curState == null) { return(false); } return((m_curState == kState) ? true : false); }
protected bool ChangeState(CState newState) { if (newState != null) { chr.CSMachine.ChangeState(newState); return(true); } return(false); }
public CState GetSubStateByType(int type) { CState state = null; if (m_mapSubState.TryGetValue(type, out state)) { return(state); } return(null); }
//状態が変わったときのイベント void ChangeState(CState aState) { bool canChange = false; switch (state) { case CState.cWait: if (aState == CState.cStart) { canChange = true; } break; case CState.cStart: if (aState == CState.cMain) { canChange = true; } break; case CState.cMain: if (aState == CState.cResult || aState == CState.cGameover || aState == CState.cTutorialGoal) { canChange = true; } break; case CState.cResult: if (aState == CState.cResultEnd) { canChange = true; } break; case CState.cTutorialGoal: if (aState == CState.cResultEnd) { canChange = true; } break; case CState.cGameover: break; case CState.cResultEnd: break; } if (canChange) { state = aState; stateChanged = true; } }
//This takes the results of a sidecast and tries to determine if a wall is found. //Using the sidecast information, it sends out three probes (from the center of the top and bottom hemispheres and the center of the capsule). //It counts the amount of hits that are valid and stores this for other classes to access. void WallCast(RaycastHit a_SidecastHit) { if (Vector3.Angle(Vector3.up, a_SidecastHit.normal) > m_CapsuleCollider.GetMaxWallAngle() || Vector3.Angle(Vector3.up, a_SidecastHit.normal) < m_CapsuleCollider.GetMaxGroundedAngle()) { m_WallCastCount = 0; return; } float wallCastMargin = m_CapsuleCollider.GetWallCastMargin(); float wallCastDistance = m_CapsuleCollider.GetWallCastDistance(); Vector3 hitPos = a_SidecastHit.point; Vector3 normal = a_SidecastHit.normal; Vector3 currentUp = m_CapsuleCollider.GetUpDirection(); Vector3 direction = CState.GetDirectionAlongNormal(Vector3.up, normal); Vector3 startHitPos1 = Vector3.zero; Vector3 startHitPos2 = Vector3.zero; Vector3 startHitPos3 = Vector3.zero; Vector3 normalOff = normal * (m_CapsuleCollider.GetRadius() - wallCastMargin); //Determines where the sidecast has hit. This to orient the probes in the correct way. if (Vector3.Dot(currentUp, hitPos) <= Vector3.Dot(currentUp, m_CapsuleCollider.GetDownCenter()))//Hit on the lower hemisphere { startHitPos1 = m_CapsuleCollider.GetDownCenter() + direction * m_CapsuleCollider.GetDefaultLength() - normalOff; startHitPos2 = m_CapsuleCollider.GetDownCenter() - normalOff; startHitPos3 = m_CapsuleCollider.GetDownCenter() + direction * m_CapsuleCollider.GetDefaultLength() * 0.5f - normalOff; } else if (Vector3.Dot(currentUp, hitPos) >= Vector3.Dot(currentUp, m_CapsuleCollider.GetUpCenter()))//Hit on the upper hemisphere { startHitPos1 = m_CapsuleCollider.GetUpCenter() - direction * m_CapsuleCollider.GetDefaultLength() - normalOff; startHitPos2 = m_CapsuleCollider.GetUpCenter() - normalOff; startHitPos3 = m_CapsuleCollider.GetUpCenter() - direction * m_CapsuleCollider.GetDefaultLength() * 0.5f - normalOff; } else //Hit somewhere in the middle { startHitPos1 = m_CapsuleCollider.GetDownCenter(true) + direction * m_CapsuleCollider.GetDefaultLength() - normalOff; startHitPos2 = m_CapsuleCollider.GetDownCenter(true) - normalOff; startHitPos3 = m_CapsuleCollider.GetDownCenter(true) + direction * m_CapsuleCollider.GetDefaultLength() * 0.5f - normalOff; } RaycastHit newHit; m_WallCastCount = 0; if (Physics.Raycast(startHitPos1, -normal, out newHit, wallCastDistance + wallCastMargin, m_CapsuleCollider.GetLayerMask())) { m_WallCastCount++; } if (Physics.Raycast(startHitPos2, -normal, out newHit, wallCastDistance + wallCastMargin, m_CapsuleCollider.GetLayerMask())) { m_WallCastCount++; } if (Physics.Raycast(startHitPos3, -normal, out newHit, wallCastDistance + wallCastMargin, m_CapsuleCollider.GetLayerMask())) { m_WallCastCount++; } }
public CState GetState(Type type) { CState returnState = null; for (int i = 0; i < cStates.Count; i++) { if (cStates[i].GetType() == type) { returnState = cStates[i]; } } return(returnState); }
//Called for every fixedupdate that this module is active public override void FixedUpdateModule() { m_WallNormal = m_ControlledCollider.GetSideCastInfo().GetSideNormal(); m_RotateMethod = (m_WallNormal.y < 0) ? RotateMethod.FromTop : RotateMethod.FromBottom; m_UpDirection = CState.GetDirectionAlongNormal(Vector3.up, m_WallNormal); m_ControlledCollider.RotateToAlignWithNormal(m_UpDirection, m_RotateMethod); float distance = m_ControlledCollider.GetSideCastInfo().GetDistance(); m_ControlledCollider.GetCapsuleTransform().Move(-m_WallNormal * distance); m_ControlledCollider.UpdateWithVelocity(Vector2.zero); }
private bool StateCheck(CState lastState) { if (m_info.check != null) { object[] ret = m_info.check.Call(lastState); if (ret.Length != 0 && ret[0].ToString() != "True" && ret[0].ToString() != "False") { Debug.LogError("The value returned by Check Function in invalid. Return:" + ret[0].ToString() + ", File:" + m_path); return(false); } return((bool)ret[0]); } return(true); }
public void setState(CState state) { GameObject player = GameObject.FindGameObjectWithTag("Player"); if (m_state != null) { m_state.exit(player); } if (state != null) { state.enter(player); m_state = state; } }
private void complete() { this.storedCombinedCRC = bsGetInt(); this.currentState = CState.EOF; this.data = null; if (this.storedCombinedCRC != this.computedCombinedCRC) { var msg = String.Format("BZip2 CRC error (expected {0:X8}, computed {1:X8})", this.storedCombinedCRC, this.computedCombinedCRC); throw new IOException(msg); } }
public CState(CStateMgr StateMgr, CState parent = null) { if (StateMgr == null) { Debug.LogError("State Construct Error. StateMgr is null."); } m_stateMgr = StateMgr; if (parent != null) { m_parent = parent; } }
protected virtual void UpdateNextState() { if (m_info.nextState == null) { if (!m_stateMgr.role.AnmationMgr.isPlaying) { AfterAction(); } } else { foreach (int type in m_info.nextState) { CState state = null; if (m_parent == null) { state = m_stateMgr.getStateByType(type); if (state != null && state.check(this)) { if (m_stateMgr.ChangeToState(type)) { return; } } } else { if (type == SUBSTATE_END) { if (!m_stateMgr.role.AnmationMgr.isPlaying) { m_parent.AfterAction(); } } else { state = m_parent.GetSubStateByType(type); if (state != null && state.check(this)) { if (m_parent.ChangeToSubState(type)) { return; } } } } } } }
void FixedUpdate() { CSideCastInfo sideCastInfo = m_Collider.GetSideCastInfo(); if (sideCastInfo.m_WallCastCount >= 2) { Vector2 currentVel = m_Collider.GetVelocity(); float dot = Vector3.Dot(currentVel, CState.GetDirectionAlongNormal(currentVel, sideCastInfo.GetSideNormal())); if (dot >= m_Threshold) { m_ParticleSystem.transform.position = sideCastInfo.GetSidePoint(); m_ParticleSystem.transform.LookAt(sideCastInfo.GetSidePoint() + new Vector3(sideCastInfo.GetSideNormal().x, sideCastInfo.GetSideNormal().y, 0.0f), Vector3.back); m_ParticleSystem.Emit(m_EmissionCount); } } }
private void SetupRandPartC() { if (this.su_j2 < this.su_z) { this.currentChar = this.su_ch2; this.crc.UpdateCRC((byte)this.su_ch2); this.su_j2++; } else { this.currentState = CState.RAND_PART_A; this.su_i2++; this.su_count = 0; SetupRandPartA(); } }
public void OnUpdate() { if (newState != null) { if (curState != null) { curState.OnExit(); } curState = newState; newState = null; curState.OnEnter(); } if (curState != null) { curState.OnUpdate(); } }
//Called for every fixedupdate that this module is active public override void FixedUpdateModule() { m_WallNormal = m_ControlledCollider.GetSideCastInfo().GetSideNormal(); m_RotateMethod = (m_WallNormal.y < 0) ? RotateMethod.FromTop : RotateMethod.FromBottom; m_UpDirection = CState.GetDirectionAlongNormal(Vector3.up, m_WallNormal); m_ControlledCollider.RotateToAlignWithNormal(m_UpDirection, m_RotateMethod); //if touching a wall during a jump, cut it short when jump is released if (m_HonorJumpCut) { m_CharacterController.UpdateJumpCut(); } Vector2 currentVel = m_ControlledCollider.GetVelocity(); Vector2 fInput = m_CharacterController.GetDirectedInputMovement() * m_EscapeVelocity; if (m_WallNormal.y >= 0.1f) { fInput = Vector2.zero; } float inputDotToNormal = Vector2.Dot(fInput, m_WallNormal); if (inputDotToNormal <= 0)//Moving into wall, or not moving at all { fInput = Vector2.zero; float distance = m_ControlledCollider.GetSideCastInfo().GetDistance(); m_ControlledCollider.GetCapsuleTransform().Move(-m_WallNormal * distance); } Vector2 fGravity = -m_UpDirection * m_SlideGravity;// if (!m_UseSameGravityForAllSlopes) { fGravity *= Vector2.Dot(-m_UpDirection, Vector2.down);//Gravity along wall, but with corrected gravity } Vector2 fDrag = -0.5f * (currentVel.sqrMagnitude) * m_CharacterController.GetDragConstant() * currentVel.normalized; Vector2 summedF = fInput + fGravity + fDrag; Vector2 newVel = currentVel + (summedF * Time.fixedDeltaTime); newVel += GetFrictionAlongWall(newVel); m_ControlledCollider.UpdateWithVelocity(newVel); }
void InitBlock() { char magic0 = bsGetUByte(); char magic1 = bsGetUByte(); char magic2 = bsGetUByte(); char magic3 = bsGetUByte(); char magic4 = bsGetUByte(); char magic5 = bsGetUByte(); if (magic0 == 0x17 && magic1 == 0x72 && magic2 == 0x45 && magic3 == 0x38 && magic4 == 0x50 && magic5 == 0x90) { complete(); // end of file } else if (magic0 != 0x31 || magic1 != 0x41 || magic2 != 0x59 || magic3 != 0x26 || magic4 != 0x53 || magic5 != 0x59) { this.currentState = CState.EOF; var msg = String.Format("bad block header at offset 0x{0:X}", this.input.Position); throw new IOException(msg); } else { this.storedBlockCRC = bsGetInt(); // Console.WriteLine(" stored block CRC : {0:X8}", this.storedBlockCRC); this.blockRandomised = (GetBits(1) == 1); // Lazily allocate data if (this.data == null) { this.data = new DecompressionState(this.blockSize100k); } // currBlockNo++; getAndMoveToFrontDecode(); this.crc.Reset(); this.currentState = CState.START_BLOCK; } }
private void SetupNoRandPartC() { if (this.su_j2 < this.su_z) { int su_ch2Shadow = this.su_ch2; this.currentChar = su_ch2Shadow; this.crc.UpdateCRC((byte)su_ch2Shadow); this.su_j2++; this.currentState = CState.NO_RAND_PART_C; } else { this.su_i2++; this.su_count = 0; SetupNoRandPartA(); } }
void UpdateStay() { //初期化 if (mNeedInitState == true) { mNeedInitState = false; mFloorModel.transform.localPosition = Vector3.zero; } //処理 Vector3 lTargetLocalPosition = GetTargetLocalPosition(); if (!ReachFloor(lTargetLocalPosition)) { mState = CState.cToMoving; } }
void UpdateMoving() { //初期化 if (mNeedInitState == true) { mNeedInitState = false; mFloorModel.transform.localPosition = Vector3.zero; mMoveDirection = GetTargetLocalPosition() - mFloor.transform.localPosition; mMoveFloorSEInstance = SoundManager.SPlay(mMoveFloorSE); } // //処理 // Vector3 lTargetLocalPosition = GetTargetLocalPosition(); //方向転換のチェック // Vector3 lMoveDirection = lTargetLocalPosition - mFloor.transform.localPosition; //進行方向が逆向きなら if (Vector3.Dot(lMoveDirection, mMoveDirection) < 0.0f) { mState = CState.cTurn; return; } mMoveDirection = lMoveDirection; //移動 // Vector3 lLocalPosition = MovePosition(mFloor.transform.localPosition, lTargetLocalPosition, mMoveSpeed * Time.deltaTime); MoveMoveFloor(lLocalPosition); if (ReachFloor(lTargetLocalPosition)) { mState = CState.cFromMoving; SoundManager.SStop(mMoveFloorSEInstance); return; } }
internal static void SaveCntState(SearchEntry entry, int cntreg, int value) { entry.isState=true; CState current=entry.cCurrent; if(current==null) { CState head=entry.cHead; if(head==null) entry.cHead=entry.cCurrent=current=new CState(); else current=head; } else { CState next=current.next; if(next==null) { current.next=next=new CState(); next.prev=current; } current=next; } current.index=cntreg; current.value=value; entry.cCurrent=current; }