public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick) { position = reader.ReadVector3Q(); rotation = reader.ReadFloatQ(); aimYaw = reader.ReadFloatQ(); aimPitch = reader.ReadFloatQ(); moveYaw = reader.ReadFloatQ(); charLocoState = (CharPredictedStateData.LocoState)reader.ReadInt32(); charLocoTick = reader.ReadInt32(); charAction = (CharPredictedStateData.Action)reader.ReadInt32(); charActionTick = reader.ReadInt32(); sprinting = reader.ReadBoolean() ? 1 : 0; sprintWeight = reader.ReadFloatQ(); damageTick = reader.ReadInt32(); damageDirection = reader.ReadFloatQ(); moveAngleLocal = reader.ReadFloatQ(); shootPoseWeight = reader.ReadFloatQ(); locomotionVector = reader.ReadVector2Q(); locomotionPhase = reader.ReadFloatQ(); banking = reader.ReadFloatQ(); landAnticWeight = reader.ReadFloatQ(); turnStartAngle = reader.ReadFloatQ(); turnDirection = reader.ReadInt16(); squashTime = reader.ReadFloatQ(); squashWeight = reader.ReadFloatQ(); inAirTime = reader.ReadFloatQ(); jumpTime = reader.ReadFloatQ(); simpleTime = reader.ReadFloatQ(); footIkOffset = reader.ReadVector2Q(); footIkNormalLeft = reader.ReadVector3Q(); footIkNormaRight = reader.ReadVector3Q(); }
public void Interpolate(ref PresentationState prevState, ref PresentationState nextState, float f) { position = Vector3.Lerp(prevState.position, nextState.position, f); rotation = Mathf.LerpAngle(prevState.rotation, nextState.rotation, f); aimYaw = Mathf.LerpAngle(prevState.aimYaw, nextState.aimYaw, f); aimPitch = Mathf.LerpAngle(prevState.aimPitch, nextState.aimPitch, f); moveYaw = Mathf.LerpAngle(prevState.moveYaw, nextState.moveYaw, f); charLocoState = prevState.charLocoState; charLocoTick = prevState.charLocoTick; charAction = prevState.charAction; charActionTick = prevState.charActionTick; sprinting = prevState.sprinting; sprintWeight = Mathf.Lerp(prevState.sprintWeight, nextState.sprintWeight, f); damageTick = prevState.damageTick; damageDirection = prevState.damageDirection; moveAngleLocal = Mathf.LerpAngle(prevState.moveAngleLocal, nextState.moveAngleLocal, f); shootPoseWeight = Mathf.Lerp(prevState.shootPoseWeight, nextState.shootPoseWeight, f); locomotionVector = Vector2.Lerp(prevState.locomotionVector, nextState.locomotionVector, f); locomotionPhase = Mathf.Lerp(prevState.locomotionPhase, nextState.locomotionPhase, f); banking = Mathf.Lerp(prevState.banking, nextState.banking, f); landAnticWeight = Mathf.Lerp(prevState.landAnticWeight, nextState.landAnticWeight, f); turnStartAngle = prevState.turnStartAngle; turnDirection = prevState.turnDirection; squashTime = Mathf.Lerp(prevState.squashTime, nextState.squashTime, f); squashWeight = Mathf.Lerp(prevState.squashWeight, nextState.squashWeight, f); inAirTime = Mathf.Lerp(prevState.inAirTime, nextState.inAirTime, f); jumpTime = Mathf.Lerp(prevState.jumpTime, nextState.jumpTime, f); simpleTime = Mathf.Lerp(prevState.simpleTime, nextState.simpleTime, f); footIkOffset = Vector2.Lerp(prevState.footIkOffset, nextState.footIkOffset, f); footIkNormalLeft = Vector3.Lerp(prevState.footIkNormalLeft, nextState.footIkNormalLeft, f); footIkNormaRight = Vector3.Lerp(prevState.footIkNormaRight, nextState.footIkNormaRight, f); }
public ActionAnimation GetActionAnimation(CharPredictedStateData.Action action) { ActionAnimation actionAnimation; m_actionAnimations.TryGetValue(action, out actionAnimation); return(actionAnimation); }
public void UpdateAction(CharPredictedStateData.Action newAction, float actionTime) { // Handle action change. This does not happen when action changes to None if (newAction != m_currentAction && newAction != CharPredictedStateData.Action.None && m_actionAnimations.ContainsKey(newAction)) { // Stop current action if (m_currentAction != CharPredictedStateData.Action.None) { m_actionAnimations[m_currentAction].animation.Pause(); m_mixer.SetInputWeight(m_actionAnimations[m_currentAction].port, 0); } m_currentAction = newAction; // Start new action animation m_actionAnimations[m_currentAction].animation.Play(); m_mixer.SetInputWeight(m_actionAnimations[m_currentAction].port, 1); } if (m_currentAction == CharPredictedStateData.Action.None) { return; } // We syncronize time when presentation state is in same action. If presentation state has None action the animation will continue playing normally if (newAction == m_currentAction) { if (actionTime < m_lastActionTime) { m_actionRestarted = true; } m_lastActionTime = actionTime; float time = m_actionRestarted ? actionTime + m_actionAnimations[m_currentAction].restartTimeOffset : actionTime; m_actionAnimations[m_currentAction].animation.SetTime(time); } // Stop animation when it is done bool animDone = m_actionAnimations[m_currentAction].animation.GetTime() >= m_actionAnimations[m_currentAction].animation.GetDuration(); if (animDone) { m_actionAnimations[m_currentAction].animation.Pause(); m_mixer.SetInputWeight(m_actionAnimations[m_currentAction].port, 0); m_currentAction = CharPredictedStateData.Action.None; m_actionRestarted = false; m_lastActionTime = 0; } }