这次得到了一个很酷的位逻辑/布尔逻辑问题!按位逻辑行为(布尔逻辑)我的代码中的结构看起来不对!
我目前在使用C#作为语言的Visual Studio 2010中工作,我试图跟踪一些使用[Flags]枚举的状态。
我用他们几次(坦白地说发现他们非常有用!)
它有5个州OFC任何地方没有问题的2一切权力,名字是characterState(可变我在其中存储的值)
在下面的代码示例:
private void DebugLogState()
{
//Check and log the current state of the character
//If a state matches, play it's respective animation
if ((currentCharacterState & Controller_2D.CharacterState.Idle) > 0)
{
Debug.Log("Idle state is active, log from object: Controller_2D");
}
if ((currentCharacterState & Controller_2D.CharacterState.Walking) > 0)
{
Debug.Log("Walking state is active, log from object: Controller_2D");
}
if ((currentCharacterState & Controller_2D.CharacterState.Running) > 0)
{
Debug.Log("Running state is active, log from object: Controller_2D");
}
if ((currentCharacterState & Controller_2D.CharacterState.Jumping) > 0)
{
Debug.Log("Jumping state is active, log from object: Controller_2D");
}
if ((currentCharacterState & Controller_2D.CharacterState.Crouching) > 0)
{
Debug.Log("Crouching state is active, log from object: Controller_2D");
}
}
现在我所希望的是比较01011(或在空闲设置为1的任何其它排列)与空闲状态(01000)&他们两个和检查> 0检查我f IDLE = true。我在我的脑海里发出了一个警报,说现在就收了!但我只是开始盯着看,想知道最好的方法是什么。
随时可以帮助我找到什么是最好的检查IDLE状态,我会尝试与我的一些旧的枚举代码在此期间比较。
谢谢,正是我所需要的! 而事实证明,我有我的哑巴程序到.NET 2.0 啊....这就像岩石撞在一起做饭,我知道:( 您的帮助是旅游居停了我的学习不分的Tx – Proclyon 2010-11-01 14:56:32