Beispiel #1
0
        public override void OnGUILayout()
        {
            if (!NativeDrawerSetting.IsShowHelp)
            {
                return;
            }

            HelpAttribute attr        = GetAttr <HelpAttribute>();
            MessageType   messageType = MessageType.None;

            if (attr.MessageType == HelpMessageType.Warning)
            {
                messageType = MessageType.Warning;
            }
            else if (attr.MessageType == HelpMessageType.Error)
            {
                messageType = MessageType.Error;
            }
            else if (attr.MessageType == HelpMessageType.Info)
            {
                messageType = MessageType.Info;
            }

            EditorGUILayout.HelpBox(attr.Text, messageType);
        }
Beispiel #2
0
    static void Main(string[] args)
    {
        Type widgetType = typeof(Widget);

        //Gets every HelpAttribute defined for the Widget type
        object[] widgetClassAttributes = widgetType.GetCustomAttributes(typeof(HelpAttribute), false);

        if (widgetClassAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)widgetClassAttributes[0];
            Console.WriteLine($"Widget class help URL : {attr.Url} - Related topic : {attr.Topic}");
        }



        System.Reflection.MethodInfo displayMethod = widgetType.GetMethod(nameof(Widget.Display));
        //Gets every HelpAttribute defined for the Widget.Display method
        object[] displayMethodAttributes = displayMethod.GetCustomAttributes(typeof(HelpAttribute), false);

        if (displayMethodAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)displayMethodAttributes[0];
            Console.WriteLine($"Display method help URL : {attr.Url} - Related topic : {attr.Topic}");
        }

        Console.ReadLine();
    }
Beispiel #3
0
        protected virtual void DrawHelp(NodeModifier node)
        {
            if (node == null)
            {
                return;
            }
            HelpAttribute help = Attribute.GetCustomAttribute(node.GetType(), typeof(HelpAttribute)) as HelpAttribute;

            if (help == null)
            {
                return;
            }

            GUIStyle style = new GUIStyle();

            style.fontSize         = 13;
            style.normal.textColor = Color.white;// new Color32(238, 130, 238, 255);
            style.clipping         = TextClipping.Overflow;
            style.wordWrap         = true;

            GUIContent con = new GUIContent(help.Help);
            //Vector2 size = style.CalcSize(con);
            float width  = 200;// size.x > 200 ? 200 : size.x;
            float height = style.CalcHeight(con, width);

            Rect rect = new Rect(_contentRect.x + 5, _contentRect.y + 70, width, height);

            //GUI.Box(rect, "", ResourcesManager.GetInstance.skin.box);
            EditorGUI.LabelField(rect, con, style);
        }
Beispiel #4
0
    public static void GetValuesAndNames <T>(out int[] ids, out string[] names)
    {
        T[] typeList = (T[])Enum.GetValues(typeof(T));
        names = new string[typeList.Length];
        ids   = new int[typeList.Length];

        for (int i = 0; i < typeList.Length; i++)
        {
            ids[i] = Convert.ToInt32(typeList[i]);
        }

        Type t = typeof(T);

        FieldInfo[] fis = t.GetFields();
        for (int i = 0; i < fis.Length; i++)
        {
            if (i < 1)
            {
                continue;
            }

            FieldInfo f = fis[i];
            if (f.GetCustomAttributes(true).Length > 0)
            {
                HelpAttribute help = (HelpAttribute)f.GetCustomAttributes(true)[0];
                names[i - 1] = help.description;
            }
            else
            {
                names[i - 1] = f.Name;
            }
        }
    }
Beispiel #5
0
    static void Main()
    {
        double[]   a       = { 0.0, 0.5, 1.0 };
        double[]   squares = Apply(a, Square);
        double[]   sines   = Apply(a, Math.Sin);
        Multiplier m       = new Multiplier(2.0);

        double[] doubles    = Apply(a, m.Multiply);
        Type     widgetType = typeof(Widget);

        //Gets every HelpAttribute defined for the Widget type
        object[] widgetClassAttributes = widgetType.GetCustomAttributes(typeof(HelpAttribute), false);

        if (widgetClassAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)widgetClassAttributes[0];
            Console.WriteLine($"Widget class help URL : {attr.Url} - Related topic : {attr.Topic}");
        }

        System.Reflection.MethodInfo displayMethod = widgetType.GetMethod(nameof(Widget.Display));

        //Gets every HelpAttribute defined for the Widget.Display method
        object[] displayMethodAttributes = displayMethod.GetCustomAttributes(typeof(HelpAttribute), false);

        if (displayMethodAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)displayMethodAttributes[0];
            Console.WriteLine($"Display method help URL : {attr.Url} - Related topic : {attr.Topic}");
        }

        Console.ReadLine();

        Console.Read();
    }
Beispiel #6
0
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        //check if folded out
        if (IsFoldedOut(property) == false)
        {
            return(0);
        }


        if (_bDisplayHelpText)
        {
            //get attribute
            HelpAttribute hatHelpAttribute = attribute as HelpAttribute;

            float fCurrentScreenWidth = EditorGUIUtility.currentViewWidth - _iScrollBarComp;

            bool _bUseWordWarp = EditorStyles.label.wordWrap;
            EditorStyles.label.wordWrap = true;

            float fOutputheight = EditorStyles.label.CalcHeight(new GUIContent(hatHelpAttribute._strHelpText), fCurrentScreenWidth) + _iTextBottomPadding;

            EditorStyles.label.wordWrap = _bUseWordWarp;

            return(fOutputheight);
        }
        else
        {
            return(_iButtonSize);
        }
    }
Beispiel #7
0
 private void Help(params string[] arg)
 {
     if (arg.Length > 0)
     {
         global::Console.DirectCommand directCommand;
         if (this.directCommands.TryGetValue(arg[0], out directCommand))
         {
             HelpAttribute[] array  = directCommand.method.GetCustomAttributes(typeof(HelpAttribute), true) as HelpAttribute[];
             HelpAttribute[] array2 = array;
             for (int i = 0; i < array2.Length; i++)
             {
                 HelpAttribute helpAttribute = array2[i];
                 this.Print(helpAttribute.helpText);
             }
         }
         else
         {
             this.Print("Unknown command");
         }
     }
     else
     {
         string text = "";
         foreach (string current in this.directCommands.Keys)
         {
             text = text + ", " + current;
         }
         text = text.Substring(2);
         this.Print("Type \"help [command]\" to get additional help");
         this.Print("Known commands: " + text);
     }
 }
 private bool TryGetHelpFromOutputTerminal(OutputTerminal outputTerminal, out HelpAttribute help)
 {
     help = Node?.GetType()
            .GetProperty(outputTerminal.Name)
            ?.GetCustomAttributes(typeof(HelpAttribute), true)
            .FirstOrDefault() as HelpAttribute;
     return(help is object);
 }
Beispiel #9
0
 static void PrintAttributeInfo(object attr)
 {
     if (attr is HelpAttribute)
     {
         HelpAttribute attrh = (HelpAttribute)attr;
         Console.WriteLine("----Url: " + attrh.Url + "  Topic: " + attrh.Topic);
     }
 }
Beispiel #10
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //check if folded out
        if (IsFoldedOut(property) == false)
        {
            return;
        }

        //store default font size
        _iDefaultFontSize = EditorStyles.label.fontSize;

        if (_bDisplayHelpText)
        {
            HelpAttribute hatHelpAttribute = attribute as HelpAttribute;

            Rect recButton = new Rect(position);
            Rect recText   = new Rect(position);


            //clamp to button size
            recButton.width  = _iButtonSize;
            recButton.height = _iButtonSize;

            int iFontSize = GUI.skin.button.fontSize;
            GUI.skin.button.fontSize = _iButtonFontSize;
            if (GUI.Button(recButton, "?"))
            {
                _bDisplayHelpText = !_bDisplayHelpText;
            }
            GUI.skin.button.fontSize = iFontSize;

            //shift text over
            recText.x     += _iButtonSize;
            recText.width -= _iButtonSize;
            bool bExistingWarp = EditorStyles.label.wordWrap;
            EditorStyles.label.wordWrap = true;
            EditorGUI.LabelField(recText, hatHelpAttribute._strHelpText);
            EditorStyles.label.wordWrap = bExistingWarp;
        }
        else
        {
            Rect recButton = new Rect(position);

            //clamp to button size
            recButton.width  = _iButtonSize;
            recButton.height = _iButtonSize;

            int iFontSize = GUI.skin.button.fontSize;
            GUI.skin.button.fontSize = _iButtonFontSize;
            if (GUI.Button(recButton, "?"))
            {
                _bDisplayHelpText = !_bDisplayHelpText;
            }
            GUI.skin.button.fontSize = iFontSize;
        }
    }
Beispiel #11
0
        /// <summary>
        /// Unity calls this function to draw the GUI
        /// </summary>
        /// <param name="position">Rectangle to display the GUI in</param>
        public override void OnGUI(Rect position)
        {
            HelpAttribute help = attribute as HelpAttribute;

            HelpFoldOut = EditorGUI.Foldout(position, HelpFoldOut, help.Header);
            if (HelpFoldOut)
            {
                EditorGUI.HelpBox(position, help.Text, MessageType.Info);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Gets the height of the decorator
        /// </summary>
        /// <returns></returns>
        public override float GetHeight()
        {
            HelpAttribute help = attribute as HelpAttribute;

            GUIStyle helpStyle = EditorStyles.helpBox;
            Vector2  size      = helpStyle.CalcSize(new GUIContent(help.Text));
            float    lines     = size.y / helpStyle.lineHeight;

            return(helpStyle.margin.top + helpStyle.margin.bottom + helpStyle.lineHeight * (HelpFoldOut ? lines : 1.0f));
        }
        private bool TryGetHelpFromInputTerminal(InputTerminal inputTerminal, out HelpAttribute help)
        {
            var        nodeType           = Node?.GetType();
            MemberInfo terminalMemberInfo = nodeType?.GetMethod(inputTerminal.Name);

            if (terminalMemberInfo == null)
            {
                terminalMemberInfo = nodeType?.GetProperty(inputTerminal.Name);
            }
            help = terminalMemberInfo?.GetCustomAttributes(typeof(HelpAttribute), true)?.FirstOrDefault() as HelpAttribute;
            return(help is object);
        }
Beispiel #14
0
        /// <summary>
        /// Sendet dem Nutzer die Hilfe
        /// </summary>
        public void AnswerHelp(object plugin)
        {
            Contract.Requires(plugin != null);

            HelpAttribute help = plugin.GetType().GetCustomAttribute <HelpAttribute>();

            if (help == null)
            {
                throw new ArgumentException("Das Plugin verfügt über keine Hilfe");
            }
            Answer(help.Help);
        }
Beispiel #15
0
    public bool IsFoldedOut(SerializedProperty property)
    {
        //get attribute
        HelpAttribute hatHelpAttribute = attribute as HelpAttribute;

        if (string.IsNullOrEmpty(hatHelpAttribute._strFoldOutTarget) == false)
        {
            return(IsParentFoldedOut(property, hatHelpAttribute._strFoldOutTarget, hatHelpAttribute._strCompareValue));
        }

        return(true);
    }
Beispiel #16
0
        /// <summary>
        /// Get the underlying <see cref="HelpAttribute"/> of this drawer.
        /// </summary>
        /// <param name="property">The target SerializedProperty.</param>
        /// <returns>The HelpAttribute of the given property. It could be null based on
        /// the condition function.</returns>
        protected override HelpAttribute GetHelpAttribute(SerializedProperty property)
        {
            DynamicHelpAttribute dynamicHelpAttribute = attribute as DynamicHelpAttribute;
            Type       targetType       = property.serializedObject.targetObject.GetType();
            MethodInfo checkingFunction =
                targetType.GetMethod(dynamicHelpAttribute.CheckingFunction);
            HelpAttribute helpAttribute = (HelpAttribute)checkingFunction.Invoke(
                property.serializedObject.targetObject,
                new object[] { });

            return(helpAttribute);
        }
Beispiel #17
0
        private bool ReadHelp(PropertyInfo pi, out object value)
        {
            value = null;
            HelpAttribute ha = pi.GetCustomAttribute <HelpAttribute>( );

            if (ha == null)
            {
                return(false);
            }

            value = _pr.IsSet(_pr.CliSpecification.HelpOption);
            return(true);
        }
        private bool TryGetHelpAttributeFromViewModel(Screen viewModel, out HelpAttribute helpAttribute)
        {
            switch (viewModel)
            {
            case OutputTerminal outputTerminal:
                return(TryGetHelpFromOutputTerminal(outputTerminal, out helpAttribute));

            case InputTerminal inputTerminal:
                return(TryGetHelpFromInputTerminal(inputTerminal, out helpAttribute));
            }
            helpAttribute = null;
            return(false);
        }
Beispiel #19
0
    public static string GetHelpDescription(Type type, string filedname)
    {
        FieldInfo field = type.GetField(filedname);

        object[] objs = field.GetCustomAttributes(typeof(HelpAttribute), false); //获取描述属性
        if (objs == null || objs.Length == 0)                                    //当描述属性没有时,直接返回名称
        {
            return(filedname);
        }
        HelpAttribute descriptionAttribute = (HelpAttribute)objs[0];

        return(descriptionAttribute.description);
    }
        void OnEnable()
        {
            colorNames   = WarColor.Names;
            colorIds     = WarColor.IDs;
            colorEnables = new bool[colorNames.Length];
            for (int i = 0; i < colorEnables.Length; i++)
            {
                colorEnables[i] = true;
            }


            BuildType[] buildTypes = (BuildType[])Enum.GetValues(typeof(BuildType));
            buildTypeNames = new string[buildTypes.Length - 1];
            buildTypeIds   = new int[buildTypes.Length - 1];

            for (int i = 0; i < buildTypes.Length; i++)
            {
                if (i < 1)
                {
                    continue;
                }
                buildTypeIds[i - 1] = (int)buildTypes[i];
            }

            Type t = typeof(BuildType);

            FieldInfo[] fis = t.GetFields();
            for (int i = 0; i < fis.Length; i++)
            {
                if (i < 2)
                {
                    continue;
                }

                FieldInfo f = fis[i];
                if (f.GetCustomAttributes(true).Length > 0)
                {
                    HelpAttribute help = (HelpAttribute)f.GetCustomAttributes(true)[0];
                    buildTypeNames[i - 2] = help.description;
                }
            }


            buildEnableds = new bool[buildTypes.Length - 1];
            buildSwitchs  = new bool[buildEnableds.Length];
            for (int i = 0; i < buildEnableds.Length; i++)
            {
                buildEnableds[i] = true;
                buildSwitchs [i] = true;
            }
        }
Beispiel #21
0
    static void ShowHelp(MemberInfo member)
    {
        HelpAttribute a = Attribute.GetCustomAttribute(member, typeof(HelpAttribute)) as HelpAttribute;

        if (a == null)
        {
            Console.WriteLine("No help for {0}", member);
        }
        else
        {
            Console.WriteLine("Help for {0}:", member);
            Console.WriteLine("  Url={0}, Topic={1}", a.Url, a.Topic);
        }
    }
Beispiel #22
0
    public static string GetHelpDescription(this Enum enumValue)
    {
        string    value = enumValue.ToString();
        FieldInfo field = enumValue.GetType().GetField(value);

        object[] objs = field.GetCustomAttributes(typeof(HelpAttribute), false); //获取描述属性
        if (objs == null || objs.Length == 0)                                    //当描述属性没有时,直接返回名称
        {
            return(value);
        }
        HelpAttribute descriptionAttribute = (HelpAttribute)objs[0];

        return(descriptionAttribute.description);
    }
Beispiel #23
0
    public static string GetName <T>(T val)
    {
        Type t = typeof(T);

        string    name      = Enum.GetName(t, val);
        FieldInfo fieldInfo = t.GetField(name);

        if (fieldInfo.GetCustomAttributes(true).Length > 0)
        {
            HelpAttribute help = (HelpAttribute)fieldInfo.GetCustomAttributes(true)[0];
            name = help.description;
        }

        return(name);
    }
Beispiel #24
0
    static void show_help(System.Reflection.MemberInfo member)
    {
        HelpAttribute attr = System.Attribute.GetCustomAttribute(
            member,
            typeof(HelpAttribute)
            ) as HelpAttribute;

        if (attr == null)
        {
            utils.print("No help for {0}", member);
        }
        else
        {
            utils.print(attr);
        }
    }
        /// <summary>
        /// Unity calls this function to draw the GUI
        /// </summary>
        /// <param name="position">Rectangle to display the GUI in</param>
        public override void OnGUI(Rect position)
        {
            HelpAttribute help = attribute as HelpAttribute;

            if (help.Collapsible)
            {
                HelpFoldOut = EditorGUI.Foldout(position, HelpFoldOut, help.Header);
                if (HelpFoldOut)
                {
                    EditorGUI.HelpBox(position, help.Text, MessageType.Info);
                }
            }
            else
            {
                EditorGUI.HelpBox(position, help.Text, MessageType.Info);
            }
            cachedPosition = position;
        }
        /// <summary>
        /// Gets the height of the decorator
        /// </summary>
        public override float GetHeight()
        {
            HelpAttribute help = attribute as HelpAttribute;

            // Computing the actual height requires the cachedPosition because
            // CalcSize doesn't factor in word-wrapped height, and CalcHeight
            // requires a pre-determined width.
            GUIStyle   helpStyle     = EditorStyles.helpBox;
            GUIContent helpContent   = new GUIContent(help.Text);
            float      wrappedHeight = helpStyle.CalcHeight(helpContent, cachedPosition.width);

            // The height of the help box should be the content if expanded, or
            // just the header text if not expanded.
            float contentHeight = !help.Collapsible || HelpFoldOut ?
                                  wrappedHeight :
                                  helpStyle.lineHeight;

            return(helpStyle.margin.top + helpStyle.margin.bottom + contentHeight);
        }
        public override void OnGUILayout()
        {
            HelpAttribute attr        = GetAttr <HelpAttribute>();
            MessageType   messageType = MessageType.None;

            if (attr.MessageType == HelpMessageType.Warning)
            {
                messageType = MessageType.Warning;
            }
            else if (attr.MessageType == HelpMessageType.Error)
            {
                messageType = MessageType.Error;
            }
            else if (attr.MessageType == HelpMessageType.Info)
            {
                messageType = MessageType.Info;
            }

            EditorGUILayout.HelpBox(attr.Text, messageType);
        }
Beispiel #28
0
    // </AsyncExample>


    private static void ReadAttributes()
    {
        // <ReadAttributes>
        Type widgetType = typeof(Widget);

        object[] widgetClassAttributes = widgetType.GetCustomAttributes(typeof(HelpAttribute), false);

        if (widgetClassAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)widgetClassAttributes[0];
            Console.WriteLine($"Widget class help URL : {attr.Url} - Related topic : {attr.Topic}");
        }

        System.Reflection.MethodInfo displayMethod = widgetType.GetMethod(nameof(Widget.Display));

        object[] displayMethodAttributes = displayMethod.GetCustomAttributes(typeof(HelpAttribute), false);

        if (displayMethodAttributes.Length > 0)
        {
            HelpAttribute attr = (HelpAttribute)displayMethodAttributes[0];
            Console.WriteLine($"Display method help URL : {attr.Url} - Related topic : {attr.Topic}");
        }
        // </ReadAttributes>
    }
Beispiel #29
0
        /// <summary>
        ///  Add spinner https://shaack.com/projekte/bootstrap-input-spinner/
        /// </summary>

        public static void CreateHTMLPageFromModelNew <TIn>(this TIn itemModel)
        {
            //https://weblogs.asp.net/grantbarrington/using-reflection-to-determine-whether-an-type-is-nullable-and-get-the-underlying-type
            // https://gist.github.com/afreeland/6796800

            //HowManyCountModel.DataModel.Address itemModel =
            // new HowManyCountModel.DataModel.Address();

            StringBuilder sb = new StringBuilder();
            Type          t  = itemModel.GetType();

            PropertyInfo[] propertyInfos = t.GetProperties();

            // typeof(HelpAttribute),
            try
            {
                sb.AppendLine("<div class=\"container\">");
                sb.AppendLine("<h2>" + t.Name + " Description</h2>");
                sb.AppendLine("<hr />");

                sb.AppendLine("@using (Html.BeginForm(\"SaveAndUpdate\", \"" + t.Name + "\", FormMethod.Post))");
                sb.AppendLine("{");
                foreach (var prop in propertyInfos)
                {
                    bool attrResult = false;
                    if (prop.GetCustomAttributes(true).Length != 0)
                    {
                        var           att = prop.GetCustomAttributes(true)[0];
                        HelpAttribute ha  = (HelpAttribute)att;
                        attrResult = ha.IsDropDownList;
                    }

                    sb.AppendLine("<div class=\"form-group\">");
                    sb.AppendLine("<label for=\"" + prop.Name + "\">" + prop.Name + "</label>");

                    TypeCode typeCode = System.Type.GetTypeCode(prop.PropertyType);
                    // typeof(Decimal).Name
                    //  sb.AppendLine("<select class=\"form-control\"  name=\"" + prop.Name + "\"   id=\"" + prop.Name + "\" class=\"form-control\"></select>");

                    switch (typeCode)
                    {
                    case TypeCode.Object:
                        if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            var propertyType = prop.PropertyType.GetGenericArguments()[0];

                            if (prop.PropertyType.Name == "Decimal")
                            {
                                sb.AppendLine(CreateDecimalInputTag(prop.Name.ToString()));
                                break;
                            }
                            else if (prop.PropertyType.Name == "DateTime" || prop.Name.Contains("Date"))
                            {
                                sb.AppendLine(CreateDateTimeInputTag(prop.Name));
                                break;
                            }
                            else if (propertyType.Name == "Int32" && attrResult)
                            {
                                sb.AppendLine(CreateDropDownTag(prop.Name));
                            }
                        }
                        sb.AppendLine(CreateInt32InputTag(prop.Name));
                        break;

                    case TypeCode.Int32:
                        sb.AppendLine(CreateInt32InputTag(prop.Name));
                        break;

                    case TypeCode.Decimal:
                        sb.AppendLine(CreateDecimalInputTag(prop.Name));
                        break;

                    case TypeCode.Boolean:
                        sb.AppendLine("@Html.CheckBoxFor(x => x." + prop.Name + ", new { @checked = \"checked\" })");
                        break;

                    case TypeCode.DateTime:
                        sb.AppendLine(CreateDateTimeInputTag(prop.Name));
                        break;

                    default:
                        sb.AppendLine(CreateDefaultInputTag(prop.Name));
                        break;
                    }
                    sb.AppendLine("</div>");
                }

                sb.AppendLine("<div class=\"form-group\">");


                sb.AppendLine("<button type =\"submit\" id =\"btnKaydet\" class=\"btn btn-primary\" value =\"Kaydet\" > Kaydet</button>");
                sb.AppendLine("<input type =\"hidden\" id=\"Id\" name=\"Id\" value=\"@Model.Id\" />");
                //  sb.AppendLine("<input type =\"hidden\" id=\"CreatedUserId\" name=\"CreatedUserId\" value=\"@Model.Id\" />");

                sb.AppendLine("</div>");

                sb.AppendLine("}");
                sb.AppendLine("</div>");
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
            string result = sb.ToString();

            //HTML OLARAK ÇIKTI ÜRETECEK
            string path = @"D:\" + t.Name + ".html";

            using (StreamWriter sw = File.CreateText(path))
            {
                sw.Write(result);
            }
        }
 private bool TryGetHelpFromNode(Node node, out HelpAttribute help)
 {
     help = node.GetType().GetCustomAttributes(typeof(HelpAttribute), true).FirstOrDefault() as HelpAttribute;
     return(help is object);
 }