Exemple #1
0
		protected override void CustomOnGUI ()
		{
			System.Enum newValue = EditorGUILayout.EnumPopup( _content, value);
			if( newValue != value)
			{
				value = newValue;
				CallGUIAction();
			}
		}
Exemple #2
0
		public GUIEnumPopup( GUIContent content, System.Enum value, OnGUIAction action=null)
		{
			this.value = value;

			_content = content;
			if( action != null)
			{
				onGUIAction += action;
			}
		}
 public static bool vTryParse <T>(this System.Enum theEnum, string valueToParse, out T returnValue)
 {
     returnValue = default(T);
     if (System.Enum.IsDefined(typeof(T), valueToParse))
     {
         System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T));
         returnValue = (T)converter.ConvertFromString(valueToParse);
         return(true);
     }
     return(false);
 }
        public void ValidDuplicateCreateField(ResourceId resourceId, System.Enum param, Enums.ValidDuplicated validDuplicated)
        {
            var handler         = new DefaultManager();
            var properties      = FileHelpers.GenerateProperties(FileFieldTestData.FileFieldType, Properties.Label.Max, Properties.Caption.Min, Properties.Search.True, Properties.Match.True, Properties.Highlight.True, Properties.Require.True, Properties.Default.Null, FileType.Bmp, Properties.Height.Max);
            var otherProperties = FileHelpers.GenerateProperties(FileFieldTestData.FileFieldType, Properties.Label.Min, Properties.Caption.Max, Properties.Search.False, Properties.Match.False, Properties.Highlight.False, Properties.Require.False, Properties.Default.Null, FileType.Png, Properties.Height.Min);
            var request         = CommonHelpers.CreateDuplicateRequest(resourceId, properties, otherProperties, param, validDuplicated);
            var response        = handler.Send <FieldCreateResponse>(FieldManager.FieldHandlingRelativeUrl, request, HttpMethod.POST);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK), "Can not Create Field");
            CommonHelpers.DeleteField(new[] { response.Result.Id });
        }
        public void ValueOfKindAsTypeOfKind_EatTargetCallTest()
        {
            // Arrange
            var helper = new ExpressionKindHelper();

            // Assert
            foreach (ExpressionKind kind in Enum.GetValues(typeof(ExpressionKind)))
            {
                Assert.AreEqual(helper.ValueOfKindAsTypeOfKind(ExpressionKind.TargetCall, kind), ExpressionKind.Result);
            }
        }
        private System.Enum drawEnumPopup(string name, System.Enum value, ref bool isChange)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(name, GUILayout.Width(120));
            var prev = value;

            value = EditorGUILayout.EnumPopup(value, GUILayout.Width(350));
            EditorGUILayout.EndHorizontal();
            isChange |= (prev != value);
            return(value);
        }
Exemple #7
0
        /// <summary>
        /// 获得枚举值的Description特性的值,一般是消息的搜索码
        /// </summary>
        /// <param name="value">要查找特性的枚举值</param>
        /// <returns>返回查找到的Description特性的值,如果没有,就返回.ToString()</returns>
        public static string GetEnumDescription(System.Enum value)
        {
            var fi = value.GetType().GetField(value.ToString());

            if (fi == null)
            {
                return(value.ToString());
            }
            var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            return((attributes.Length > 0) ? attributes[0].Description : value.ToString());
        }
Exemple #8
0
        /// <summary>
        /// Gets an attribute on an enum field value
        /// </summary>
        /// <typeparam name="T">The type of the attribute you want to retrieve</typeparam>
        /// <param name="enumVal">The enum value</param>
        /// <returns>The attribute of type T that exists on the enum value</returns>
        /// <example DescriptionAttribute="().Description;">string desc = myEnumVariable.GetAttributeOfType</example>
        public static T GetAttribute <T>(this System.Enum enumVal) where T : System.Attribute
        {
            var type = enumVal.GetType();

            var memInfo = type.GetMember(enumVal.ToString());

            var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);

            return((attributes.Length > 0)
                ? (T)attributes[0]
                : null);
        }
Exemple #9
0
        public static string MimeType(this System.Enum value)
        {
            System.Reflection.MemberInfo field = value.GetType().GetField(value.ToString());
            // System.Reflection.FieldInfo field = value.GetType().GetField(value.ToString());
            // System.Reflection.PropertyInfo field = null;
            // System.Reflection.MemberInfo field = null;

            // MimeTypeAttribute[] attributes = (MimeTypeAttribute[]) field.GetCustomAttributes(typeof(MimeTypeAttribute), false);
            // if (attributes == null) return null;
            // return attributes[0].MimeType;
            return(GetAttributeValue <MimeTypeAttribute, string>(field, x => x.MimeType));
        }
Exemple #10
0
        public static System.Enum EnumPopup(GUIContent gc, System.Enum value)
        {
            GUILayout.BeginHorizontal();

            GUILayout.Label(gc);
            GUILayout.FlexibleSpace();
            var ret = EditorGUILayout.EnumPopup(value, "Popup", GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth / 2));

            GUILayout.EndHorizontal();

            return(ret);
        }
        private void SetTemplateData(System.Enum _incEnum)
        {
            if (_incEnum.GetType() == typeof(E_NewCombatStateTemplate))
            {
                E_NewCombatStateTemplate template = (E_NewCombatStateTemplate)_incEnum;
                m_copiedStateCache?.Cleanup();
                m_copiedStateCache = new StateDataCache();

                OTGEditorUtility.PopulateStateByTemplate(template, ref m_copiedStateCache, m_editorConfig);
                ContainerElement.Q <TextField>("new-state-name-textfield").value = template.ToString() + "template selected";
            }
        }
Exemple #12
0
 public static bool IsEnumValid_NotSequential(System.Enum enumValue, int value, params int[] enumValues)
 {
     System.Diagnostics.Debug.Assert(Enum.GetValues(enumValue.GetType()).Length == enumValues.Length, "Not all the enum members were passed in.");
     for (int i = 0; i < enumValues.Length; i++)
     {
         if (enumValues[i] == value)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #13
0
 public BlockType(bool random)
 {
     if (random)
     {
         //Set base type
         int enumLength = System.Enum.GetValues(typeof(BaseBlockType)).Length;
         int rand       = Random.Range(0, enumLength);
         baseType = (BaseBlockType)rand;
         //Set sub type
         subType = RandSubType(baseType);
     }
 }
        public static void UpdateModeEnum(SerializedProperty prop, GUIContent label, System.Enum _enum, params GUILayoutOption[] options)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = prop.hasMultipleDifferentValues;
            var newValue = (int)(MultiAudioManager.UpdateModes)EditorGUILayout.EnumPopup(label, _enum, options);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                prop.enumValueIndex = newValue;
            }
        }
        public void Produce(System.Enum type)
        {
            GameObject prefab = GetSoldier(type);

            if (prefab != null)
            {
                AIAgent agent = Instantiate(prefab, transform.position, Quaternion.identity).GetComponent <AIAgent>();
                agent.Owner = Player;
                agent.gameObject.SetActive(true);
                agent.SetTarget(TargetType.Place, Vector3.ProjectOnPlane(transform.position + transform.forward * 8, Vector3.up));
            }
        }
        public static System.Enum EnumFlagField(GUIContent label, System.Enum value)
        {
            if (value == null)
            {
                throw new System.ArgumentException("Enum value must be non-null.", "value");
            }

            var enumType = value.GetType();
            int i        = EnumFlagField(enumType, label, System.Convert.ToInt32(value));

            return(System.Enum.ToObject(enumType, i) as System.Enum);
        }
        public static string GetEnumDescription(this System.Enum value)
        {
            var fi         = value.GetType().GetField(value.ToString());
            var attributes =
                (EnumMemberAttribute[])fi.GetCustomAttributes(typeof(EnumMemberAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Value);
            }
            return(value.ToString());
        }
Exemple #18
0
        public static string GetDescription(Enum en)
        {
            var attr = GetAttribute <DescriptionAttribute>(en);

            if (attr != null)
            {
                return(attr.Description);
            }
            else
            {
                return(en.ToString());
            }
        }
Exemple #19
0
        private static bool isObsolete(System.Enum value)
        {
            int enumInt = (int)(object)value;

            if (enumInt == 4 || enumInt == 14)
            {
                return(false);
            }

            System.Reflection.FieldInfo field      = value.GetType().GetField(value.ToString());
            System.ObsoleteAttribute[]  attributes = (System.ObsoleteAttribute[])field.GetCustomAttributes(typeof(System.ObsoleteAttribute), false);
            return(attributes.Length > 0);
        }
Exemple #20
0
 //completely removes the value
 public static T Remove <T>(this System.Enum type, T value)
 {
     try {
         return((T)(object)(((int)(object)type & ~(int)(object)value)));
     }
     catch (System.Exception ex) {
         throw new System.ArgumentException(
                   string.Format(
                       "Could not remove value from enumerated type '{0}'.",
                       typeof(T).Name
                       ), ex);
     }
 }
        public static System.Enum DrawEnumField(System.Enum value, string title, bool enabled = true)
        {
            if (enabled)
            {
                return(EditorGUILayout.EnumPopup(title, value));
            }
            var saveColor = GUI.color;

            GUI.color = new Color(1f, 1f, 1f, 0.25f);
            EditorGUILayout.EnumPopup(title, value);
            GUI.color = saveColor;
            return(value);
        }
Exemple #22
0
        /// <summary>
        /// 通过枚举获取描述信息
        /// </summary>
        /// <param name="enumInstance"></param>
        /// <returns></returns>
        public static string GetDescriptionByEnum(System.Enum enumInstance)
        {
            var des        = enumInstance.GetType().GetField(enumInstance.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
            var attributes = des.ToList();

            if (attributes.Count < 1)
            {
                return(string.Empty);
            }
            var descriptionAttribute = attributes[0] as DescriptionAttribute;

            return(descriptionAttribute != null ? descriptionAttribute.Description : string.Empty);
        }
Exemple #23
0
        public static string GetLiteral(this System.Enum e)
        {
            var attr = e.GetAttributeOnEnum <EnumLiteralAttribute>();

            if (attr != null)
            {
                return(attr.Literal);
            }
            else
            {
                return(null);
            }
        }
        public static string GetEnumDescription(System.Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes = fi.GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[];

            if (attributes != null && attributes.Any())
            {
                return(attributes.First().Description);
            }

            return(value.ToString());
        }
        public static string GetDescription(this System.Enum columnEnum)
        {
            var attributes = columnEnum.GetAttributes();

            if (attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(string.Empty);
            }
        }
        public static int GetPosition(this System.Enum columnEnum)
        {
            var attributes = columnEnum.GetAttributes();

            if (attributes.Length > 0)
            {
                return(attributes[0].Position);
            }
            else
            {
                return(-1);
            }
        }
        public static System.Enum DrawEnumField(System.Enum value, string title, string tooltip, bool enabled, params GUILayoutOption[] options)
        {
            if (enabled)
            {
                return(EditorGUILayout.EnumPopup(new GUIContent(title, tooltip), value, options));
            }
            var saveColor = GUI.color;

            GUI.color = new Color(1f, 1f, 1f, 0.25f);
            EditorGUILayout.EnumPopup(new GUIContent(title, tooltip), value, options);
            GUI.color = saveColor;
            return(value);
        }
        public static string GetDescription(System.Enum value)
        {
            var enumMember           = value.GetType().GetMember(value.ToString()).FirstOrDefault();
            var descriptionAttribute =
                enumMember == null
                    ? default(DescriptionAttribute)
                    : enumMember.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;

            return
                (descriptionAttribute == null
                    ? value.ToString()
                    : descriptionAttribute.Description);
        }
 public static IEnumerable <SelectListItem> ToSelectList <T>(this System.Enum enumValue)
 {
     return
         (System.Enum.GetValues(enumValue.GetType()).Cast <T>()
          .Select(
              x =>
              new SelectListItem
     {
         Text = ((System.Enum)(object) x).ToDescription(),
         Value = x.ToString(),
         Selected = (enumValue.Equals(x))
     }));
 }
 public static T Add <T>(this System.Enum type, T value)
 {
     try {
         return((T)(object)(((int)(object)type | (int)(object)value)));
     }
     catch (Exception ex) {
         throw new ArgumentException(
                   string.Format(
                       "Could not append value from enumerated type '{0}'.",
                       typeof(T).Name
                       ), ex);
     }
 }
Exemple #31
0
        public static string GetEnumDescription(this System.Enum enumValue)
        {
            string str = enumValue.ToString();

            System.Reflection.FieldInfo field = enumValue.GetType().GetField(str);
            object[] objs = field.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
            if (objs == null || objs.Length == 0)
            {
                return(str);
            }
            System.ComponentModel.DescriptionAttribute da = (System.ComponentModel.DescriptionAttribute)objs[0];
            return(da.Description);
        }
Exemple #32
0
        /// <summary>
        /// Returns the value of the DescriptionAttribute if the specified Enum value has one.
        /// If not, returns the ToString() representation of the Enum value.
        /// </summary>
        /// <param name="value">The Enum to get the description for</param>
        /// <returns></returns>
        public static string GetDescription(System.Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(value.ToString());
            }
        }