本文整理汇总了C#中Enum类的典型用法代码示例。如果您正苦于以下问题:C# Enum类的具体用法?C# Enum怎么用?C# Enum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Enum类属于命名空间,在下文中一共展示了Enum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyBuff
float ApplyBuff(Enum statType, float value)
{
string strStatType = statType.ToString();
float addSum = 0;
float multiSum = 0;
foreach (var buff in buffs)
{
if (buff.Value.statMod != null)
{
foreach (var buffStat in buff.Value.statMod)
{
string strBuffStatType = buffStat.Key.ToString();
if (strBuffStatType == strStatType)
{
addSum += buffStat.Value;
}
else if (strBuffStatType != "GoldGetAmplifier" && strBuffStatType == strStatType + "Amplifier")
{
multiSum += buffStat.Value;
}
}
}
}
return (value + addSum) * (1 + multiSum);
}
示例2: GetStringValue
/// <summary>
/// Gets a string value for a particular enum value.
/// </summary>
/// <param name="value">Value.</param>
/// <returns>String Value associated via a <see cref="StringValueAttribute"/> attribute, or null if not found.</returns>
public static string GetStringValue(Enum value)
{
string output = null;
Type type = value.GetType();
if (_stringValues.ContainsKey(value))
output = (_stringValues[value] as StringValueAttribute).Value;
else
{
//Look for our 'StringValueAttribute' in the field's custom attributes
FieldInfo fi = type.GetField(value.ToString());
StringValueAttribute[] attrs = fi.GetCustomAttributes(typeof(StringValueAttribute), false) as StringValueAttribute[];
if (attrs.Length > 0)
{
try
{
_stringValues.Add(value, attrs[0]);
}
catch { }
output = attrs[0].Value;
}
}
return output;
}
示例3: AddEvent
/// <summary>
/// 添加事件及回调
/// </summary>
/// <param name="type">事件枚举</param>
/// <param name="handle">回调</param>
/// <param name="isUseOnce"></param>
public static void AddEvent(Enum type, EventHandle handle, bool isUseOnce = false)
{
if (isUseOnce)
{
if (mUseOnceEventDic.ContainsKey(type))
{
if (!mUseOnceEventDic[type].Contains(handle))
mUseOnceEventDic[type].Add(handle);
else
Debug.LogWarning("already existing EventType: " + type + " handle: " + handle);
}
else
{
List<EventHandle> temp = new List<EventHandle>();
temp.Add(handle);
mUseOnceEventDic.Add(type, temp);
}
}
else
{
if (mEventDic.ContainsKey(type))
{
if (!mEventDic[type].Contains(handle))
mEventDic[type].Add(handle);
else
Debug.LogWarning("already existing EventType: "+ type+" handle: "+ handle );
}
else
{
List<EventHandle> temp = new List<EventHandle>();
temp.Add(handle);
mEventDic.Add(type, temp);
}
}
}
示例4: Init
protected void Init(Enum statType, object val)
{
CheckKeyType(statType);
ClearCache();
initValue.Add(statType, val);
}
示例5: Limp_Enter
IEnumerator Limp_Enter(Enum prevState)
{
Debug.Log("Enter Limp " + prevState.ToString());
yield return new WaitForSeconds(5);
Debug.Log("Limp Entered");
}
示例6: GetRatio
public float GetRatio(Enum statusKey)
{
Assert.IsTrue(ContainsKey(statusKey));
var targetStatus = Find(statusKey);
return targetStatus.Get(statusKey) / targetStatus.GetMax(statusKey);
}
示例7: Get
public float Get(Enum statKey)
{
Type keyType = statKey.GetType();
Assert.IsTrue(stats.ContainsKey(keyType));
return stats[keyType].Get(statKey);
}
示例8: EnumItem
/// <summary>
/// Initializes a new instance of the EnumItem class.
/// </summary>
/// <param name="document">The document that contains the element.</param>
/// <param name="parent">The parent of the element.</param>
/// <param name="header">The Xml header for this element.</param>
/// <param name="attributes">The list of attributes attached to this element.</param>
/// <param name="declaration">The declaration code for this element.</param>
/// <param name="initialization">The initialization expression, if there is one.</param>
/// <param name="unsafeCode">Indicates whether the element resides within a block of unsafe code.</param>
/// <param name="generated">Indicates whether the code element was generated or written by hand.</param>
internal EnumItem(
CsDocument document,
Enum parent,
XmlHeader header,
ICollection<Attribute> attributes,
Declaration declaration,
Expression initialization,
bool unsafeCode,
bool generated)
: base(document,
parent,
ElementType.EnumItem,
"enum item " + declaration.Name,
header,
attributes,
declaration,
unsafeCode,
generated)
{
Param.Ignore(document, parent, header, attributes, declaration, initialization, unsafeCode, generated);
this.initialization = initialization;
if (this.initialization != null)
{
this.AddExpression(this.initialization);
}
}
示例9: ChangeState
public void ChangeState(Enum newState)
{
if(mCurrentWorkDelegate != null){
StopCoroutine(mCurrentWorkDelegate);
}
if(mCurrentState != null){
StateTransitionDelegate exitDelegate = mEndStateDelegate[mCurrentState];
if(exitDelegate != null){
exitDelegate();
}
}
StateTransitionDelegate enterDelegate = mStartStateDelegate[newState];
if(enterDelegate != null){
enterDelegate();
}
mCurrentState = newState;
StateWorkDelegate workDelegate = mStateWorkDelegate[mCurrentState];
if(workDelegate != null){
mCurrentWorkDelegate = workDelegate();
StartCoroutine(mCurrentWorkDelegate);
}
}
示例10: Exit_EnterState
void Exit_EnterState()
{
exitSaveColor = exitStyle.normal.textColor;
exitStyle.normal.textColor = Color.red;
this.lastState = (Enum)stateMachine.lastState;
this.lastMachine = stateMachine.lastStateMachineBehaviour;
}
示例11: HasDone
public static bool HasDone(Enum check)
{
if (HarmonicSerialization.Instance.CurrentSave != null)
{
if (HarmonicSerialization.Instance.CurrentSave.HideTutorial)
return true;
else
{
if (check is MeatspaceProgress)
return (HarmonicSerialization.Instance.CurrentSave.MeatspaceProgression & ((MeatspaceProgress)check)) != 0;
else if (check is CyberspaceProgress)
return (HarmonicSerialization.Instance.CurrentSave.CyberspaceProgression & ((CyberspaceProgress)check)) != 0;
else if (check is WorkstationProgress)
return (HarmonicSerialization.Instance.CurrentSave.WorkstationProgression & ((WorkstationProgress)check)) != 0;
else if (check is HackingProgress)
return (HarmonicSerialization.Instance.CurrentSave.HackingProgression & ((HackingProgress)check)) != 0;
UnityEngine.Debug.LogWarning("flag enum is none of any progression enums!");
return false;
}
}
else
{
UnityEngine.Debug.LogWarning("no current save to check enums against!");
return false;
}
}
示例12: DatablockEnumAttribute
/// <summary>
/// Limit the display of the field based on the enum value of another field
/// </summary>
/// <param name="field">Field to check for enum value</param>
/// <param name="value">Enum value other field must have</param>
/// <param name="contains">If not contains, enums have to match exactly</param>
/// <param name="reverse">If reversed, will only display if the other field's value does not match</param>
public DatablockEnumAttribute(string field, object value, bool reverse = false, bool contains = false)
{
fieldName = field;
enumValue = (Enum)value;
this.reverse = reverse;
this.contains = contains;
}
示例13: Visitor
internal Visitor(Enum providerMode)
{
if(providerMode == null)
{
throw Error.ArgumentNull("providerMode");
}
this._providerMode = providerMode;
}
示例14: EnumComboBox
public static Enum EnumComboBox(string label, Enum selected)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label(label);
var result = EnumComboBox(selected);
EditorGUILayout.EndHorizontal();
return result;
}
示例15: RemoveState
public void RemoveState(Enum stateId) {
FSMState state = GetState(stateId);
if(state == null)
throw new Exception("Could not find state " + stateId.ToString() + " for removal.");
_states.Remove(state);
}