public void ChangeState(PlayerStates state) { if (_state != null) { _state.Dispose(); _state = null; } Debug.Log("Changing to player state : " + state.ToString()); _state = _stateFactory.CreateState(state); _state.Start(); }
public virtual void Update() { // Gets the anolog input from the player // Checks to see if the X & Y are in different directions then the previous frames // Also checks the distance the analog stick has traveled // If the analog stick has traveled too far and the directions are different the player will skid previousInput = currentInput; targetVelocity = new Vector3(-XCI.GetAxis(XboxAxis.LeftStickX, playerNumber), 0f, -XCI.GetAxis(XboxAxis.LeftStickY, playerNumber)); targetVelocity.Normalize(); currentInput = new Vector2(targetVelocity.x, targetVelocity.z); Vector2 prevDir = new Vector2(previousInput.x > 0 ? 1 : previousInput.x < 0 ? -1 : 0, previousInput.y > 0 ? 1 : previousInput.y < 0 ? -1 : 0); Vector2 currentDir = new Vector2(currentInput.x > 0 ? 1 : currentInput.x < 0 ? -1 : 0, currentInput.y > 0 ? 1 : currentInput.y < 0 ? -1 : 0); delta = Vector2.Distance(currentInput, previousInput); if (currentState == PlayerStates.Run && delta > maxAnalogChange && (prevDir.x != currentDir.x || prevDir.y != currentDir.y)) { if (speed >= maxSpeed) { SetState(PlayerStates.Stopping); } } // Controls player states if (currentState != targetState) { StopCoroutine(currentState.ToString()); pastState = previousState; previousState = currentState; currentState = targetState; StartCoroutine(currentState.ToString()); } Counters(); }
public bool PlaySongAsync(string song) { double playerpos = player.CurrentPosition; Debug.Print("playing {0}\n", song); Dictionary <String, String> properties = new Dictionary <string, string>(); var TimeElapsed = DateTime.UtcNow - LastTime; properties["TrackCount"] = Playlist.Count.ToString(); properties["LoopMode"] = isLooping.ToString(); properties["CompareMode"] = isAligned.ToString(); properties["PlayMode"] = playerState.ToString(); LastTime = DateTime.UtcNow; Analytics.TrackEvent("PlayTrack", properties); try { player.Stop(); using (Stream s = new FileStream(song, FileMode.Open)) { if (player.Load(s)) { if (playerState != PlayerStates.Stopped && isAligned) { player.Seek(playerpos); } NowPlaying = Path.GetFileNameWithoutExtension(song); StartPlayer(); } else { properties.Clear(); properties["Length"] = s.Length.ToString(); properties["Type"] = Path.GetExtension(song); Analytics.TrackEvent("PlayCurrent player.Load failed", properties); ErrorMsg(AppResources.SongPlayFailedTitle, AppResources.SongPlayFailed, AppResources.OK); StopPlayer(); return(false); } } } catch (Exception ex) { ErrorMsg(AppResources.SongPlayFailedTitle, ex.Message, AppResources.OK); Debug.Print(ex.ToString()); return(false); } return(true); }
void SetAnimationState(PlayerStates animationState) { _animationState = animationState; _animator.Play(_animationState.ToString()); }