Ejemplo n.º 1
0
    public static System.IConvertible BitmapPopup(string p_label, System.IConvertible p_enum)
    {
        System.IConvertible p_return = p_enum;
        if (EnumHelper.CheckIfIsEnum(p_enum.GetType(), true))
        {
            try
            {
                int v_value = (int)((System.IConvertible)p_enum);
                if (string.IsNullOrEmpty(p_label))
                {
                    v_value = EditorGUILayout.MaskField(v_value, System.Enum.GetNames(p_enum.GetType()));
                }
                else
                {
                    v_value = EditorGUILayout.MaskField(p_label, v_value, System.Enum.GetNames(p_enum.GetType()));
                }
                p_return = ((System.IConvertible)v_value);
            }
            catch {}
        }
        else if (EnumHelper.CheckIfIsEnum(p_enum.GetType(), false))
        {
            try
            {
                if (string.IsNullOrEmpty(p_label))
                {
                    p_return = (System.Enum)EditorGUILayout.EnumPopup((System.Enum)p_enum);
                }
                else
                {
                    p_return = (System.Enum)EditorGUILayout.EnumPopup(p_label, (System.Enum)p_enum);
                }
            }
            catch {}
        }

        return(p_return);
    }
Ejemplo n.º 2
0
        public static int GetFlagsCount(this System.IConvertible self)
        {
            var res    = 0;
            var values = System.Enum.GetValues(self.GetType());

            foreach (var value in values)
            {
                if (((int)self & (int)value) != 0)
                {
                    res++;
                }
            }
            return(res);
        }