当前位置: 首页>>代码示例>>C#>>正文


C# Enum类代码示例

本文整理汇总了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);
 }
开发者ID:pb0,项目名称:ID0_Test,代码行数:25,代码来源:Stat.cs

示例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;
    }
开发者ID:asifashraf,项目名称:Radmade-Portable-Framework,代码行数:30,代码来源:StringEnum.cs

示例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);
         }
     }
 }
开发者ID:GaoKaiHaHa,项目名称:MyUnityFrameWork,代码行数:41,代码来源:GlobalEvent.cs

示例4: Init

    protected void Init(Enum statType, object val)
    {
        CheckKeyType(statType);
        ClearCache();

        initValue.Add(statType, val);
    }
开发者ID:pb0,项目名称:ID0_Test,代码行数:7,代码来源:Stat.cs

示例5: Limp_Enter

    IEnumerator Limp_Enter(Enum prevState)
    {
        Debug.Log("Enter Limp " + prevState.ToString());
        yield return new WaitForSeconds(5);

        Debug.Log("Limp Entered");
    }
开发者ID:GisleSolv,项目名称:SEP,代码行数:7,代码来源:StateMachineTest.cs

示例6: GetRatio

    public float GetRatio(Enum statusKey)
    {
        Assert.IsTrue(ContainsKey(statusKey));

        var targetStatus = Find(statusKey);
        return targetStatus.Get(statusKey) / targetStatus.GetMax(statusKey);
    }
开发者ID:pb0,项目名称:ID0_Test,代码行数:7,代码来源:StatusHolder.cs

示例7: Get

    public float Get(Enum statKey)
    {
        Type keyType = statKey.GetType();
        Assert.IsTrue(stats.ContainsKey(keyType));

        return stats[keyType].Get(statKey);
    }
开发者ID:pb0,项目名称:ID0_Test,代码行数:7,代码来源:StatHolder.cs

示例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);
            }
        }
开发者ID:katerina-marchenkova,项目名称:my,代码行数:38,代码来源:EnumItem.cs

示例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);
        }
    }
开发者ID:eldunce,项目名称:DelegateStateMachine,代码行数:26,代码来源:DelegateStateMachine.cs

示例10: Exit_EnterState

 void Exit_EnterState()
 {
     exitSaveColor = exitStyle.normal.textColor;
     exitStyle.normal.textColor = Color.red;
     this.lastState = (Enum)stateMachine.lastState;
     this.lastMachine = stateMachine.lastStateMachineBehaviour;
 }
开发者ID:Tyderion,项目名称:snake-unity,代码行数:7,代码来源:Settings.cs

示例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;
        }
    }
开发者ID:HarmonicOrder,项目名称:WarpedDrive,代码行数:27,代码来源:Tutorial.cs

示例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;
 }
开发者ID:Daloupe,项目名称:Syzygy_Git,代码行数:14,代码来源:DatablockEnumAttribute.cs

示例13: Visitor

			internal Visitor(Enum providerMode)
			{
				if(providerMode == null)
				{
					throw Error.ArgumentNull("providerMode");
				}
				this._providerMode = providerMode;
			}
开发者ID:modulexcite,项目名称:LinqToSQL2,代码行数:8,代码来源:CompatibilityCheck.cs

示例14: EnumComboBox

 public static Enum EnumComboBox(string label, Enum selected)
 {
     EditorGUILayout.BeginHorizontal();
     GUILayout.Label(label);
     var result = EnumComboBox(selected);
     EditorGUILayout.EndHorizontal();
     return result;
 }
开发者ID:meta-42,项目名称:uEasyKit,代码行数:8,代码来源:EditorGUIExtension.cs

示例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);
    }
开发者ID:jtuttle,项目名称:ritual,代码行数:8,代码来源:FiniteStateMachine.cs


注:本文中的Enum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。