本文整理汇总了C#中PlayerState.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PlayerState.ToString方法的具体用法?C# PlayerState.ToString怎么用?C# PlayerState.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PlayerState
的用法示例。
在下文中一共展示了PlayerState.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setState
public void setState(PlayerState state)
{
Logger.message(LogLevel.LOG_INFO, "Player state sets to "+state.ToString());
if (state == _currentState)
return;
switch(state)
{
case PlayerState.DEFAULT:
_sprite.Play("stand");
break;
case PlayerState.BUSY:
_sprite.Play("work");
break;
case PlayerState.MOVING:
break;
default:
Logger.message(LogLevel.LOG_ERROR, "Unknown player state - "+_currentState.ToString());
break;
}
_currentState = state;
}
示例2: StateChanged
private void StateChanged(PlayerState newState)
{
if (PreviousAnimation != null)
PreviousAnimation = CurrentAnimation;
string key = newState.ToString();
CurrentAnimation = new Animation(Animations[key]);
}
示例3: WaitUntil
private void WaitUntil (PlayerEvent? @event, PlayerState? state, System.Action action)
{
if (action == null) {
throw new ArgumentNullException ("action");
}
if (@event == null && state == null) {
throw new ArgumentException ("Event or state must be non-null");
}
if (@event != null && state != null) {
throw new ArgumentException ("Event and state cannot be both non-null");
}
object lock_object = new object ();
string evnt_or_state_desc = @event != null ? @event.Value.ToString () : state.Value.ToString ();
Exception exception = null;
Func<PlayerEventArgs, bool> matches = (a) => {
if (a == null) {
throw new ArgumentNullException ("a");
}
var sca = a as PlayerEventStateChangeArgs;
PlayerEvent? last_event = a.Event;
PlayerState? last_state = null;
if (sca != null) {
last_state = sca.Current;
}
return (@event != null && @event.Value.Equals (last_event.Value))
|| (state != null && last_state != null && state.Value.Equals (last_state.Value));
};
var args_queue = new Queue<PlayerEventArgs> ();
var reset_event = new ManualResetEvent (false);
reset_event.Reset ();
var handler = new PlayerEventHandler (a => {
try {
lock (lock_object) {
args_queue.Enqueue (a);
}
} catch (Exception ex) {
exception = ex;
}
reset_event.Set ();
});
service.ConnectEvent (handler);
bool return_early = (state != null && service.CurrentState.Equals (state.Value));
action ();
if (return_early) {
return;
}
const int seconds = 3;
int count = 0;
const int max_count = 10;
string event_or_state_desc = @event != null ? @event.ToString () : state.ToString ();
bool found = false;
do {
if (!reset_event.WaitOne (TimeSpan.FromSeconds (seconds))) {
Assert.Fail (String.Format ("Waited {0}s for {1} at iteration {2}, but didn't happen",
seconds, evnt_or_state_desc, count));
break;
}
lock (lock_object) {
while (args_queue.Count > 0) {
var arg = args_queue.Dequeue ();
if (matches (arg)) {
found = true;
break;
}
count++;
}
}
if (exception != null) {
throw exception;
}
if (count > max_count) {
Assert.Fail (String.Format ("More than {0} events/states happened, but not {1}", max_count, event_or_state_desc));
}
} while (!found);
service.DisconnectEvent (handler);
}