private Sample LoadSample(SampleSuite suite, MethodInfo method, string fileSourceCode) { DescriptionAttribute descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(method, typeof(DescriptionAttribute)); TitleAttribute titleAttribute = (TitleAttribute)Attribute.GetCustomAttribute(method, typeof(TitleAttribute)); return(new Sample(suite, method, (titleAttribute != null) ? titleAttribute.Title : "", (descriptionAttribute != null) ? descriptionAttribute.Description : "", CodeExtractor.GetCodeBlock(fileSourceCode, "void " + method.Name))); }
public override int GetHashCode() { var hash = 3; hash = (hash * 2) + EnableLdapAuthentication.GetHashCode(); hash = (hash * 2) + StartTls.GetHashCode(); hash = (hash * 2) + Server.GetHashCode(); hash = (hash * 2) + UserDN.GetHashCode(); hash = (hash * 2) + PortNumber.GetHashCode(); hash = (hash * 2) + UserFilter.GetHashCode(); hash = (hash * 2) + LoginAttribute.GetHashCode(); hash = (hash * 2) + FirstNameAttribute.GetHashCode(); hash = (hash * 2) + SecondNameAttribute.GetHashCode(); hash = (hash * 2) + MailAttribute.GetHashCode(); hash = (hash * 2) + TitleAttribute.GetHashCode(); hash = (hash * 2) + MobilePhoneAttribute.GetHashCode(); hash = (hash * 2) + LocationAttribute.GetHashCode(); hash = (hash * 2) + GroupMembership.GetHashCode(); hash = (hash * 2) + GroupDN.GetHashCode(); hash = (hash * 2) + GroupNameAttribute.GetHashCode(); hash = (hash * 2) + GroupFilter.GetHashCode(); hash = (hash * 2) + UserAttribute.GetHashCode(); hash = (hash * 2) + GroupAttribute.GetHashCode(); hash = (hash * 2) + Authentication.GetHashCode(); hash = (hash * 2) + Login.GetHashCode(); return(hash); }
public static MvcHtmlString DropDownForEnum <EnumType>(this HtmlHelper html, string name, EnumType?value, object htmlAttributes = null) where EnumType : struct { var type = typeof(EnumType); if (!type.IsEnum) { throw new Exception("The member must be an Enum"); } var builder = new TagBuilder("select"); builder.GenerateId(name); builder.MergeAttribute("name", name); foreach (var n in Enum.GetNames(type)) { var title = TitleAttribute.GetTitle(type.GetField(n, BindingFlags.Public | BindingFlags.Static), n); TagBuilder op = new TagBuilder("option"); var thisVal = (int)Enum.Parse(type, n); op.Attributes["value"] = thisVal.ToString(); //if (value != null && (int)value.Value == thisVal) // op.Attributes["selected"] = "selected"; op.SetInnerText(title); builder.InnerHtml += op.ToString(); } if (htmlAttributes != null) { foreach (var prop in htmlAttributes.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { builder.Attributes[prop.Name] = prop.GetValue(htmlAttributes, null).ToString(); } } return(MvcHtmlString.Create(builder.ToString())); }
public override void OnGUI(Rect position) { TitleAttribute title = (TitleAttribute)attribute; position.yMin += EditorGUIUtility.singleLineHeight * 0.5f; position = EditorGUI.IndentedRect(position); GUIStyle style = GUIHelper.GUIStyleFromLabelStyle(title.style); //store font size before int fontSize = style.fontSize; //set size if (title.textSize != TextSize.normal) { style.fontSize = (int)title.textSize; } EditorGUI.LabelField(position, title.content, style); //set size if (title.textSize != TextSize.normal) { style.fontSize = fontSize; } }
protected override NodeLibrary ConstructNodeLibrary(NodeLibrary library) { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (var type in types) { if (!type.IsAbstract && type.IsSubclassOf(typeof(NodeSketch.Nodes.Node))) { TitleAttribute titleAttrib = type.GetCustomAttribute <TitleAttribute>(false); string[] title; if (titleAttrib != null) { title = titleAttrib.Title.Split('/'); } else { title = type.FullName.Split('.'); } library.Add(new NodeTemplate(title, "UXML/Nodes/GraphNode", "Styles/Nodes/GraphNode", type)); } } } return(library); }
public static string GetTitle(IEnumerable <object> attributes) { TitleAttribute attribute = CustomAttributeHelpers.GetAttribute <TitleAttribute>(attributes); if (attribute == null) { return(null); } return(attribute.get_Text()); }
private string Title() { if (!Attribute.IsDefined(_type, typeof(TitleAttribute))) { return(_type.Name); } TitleAttribute title = (TitleAttribute)Attribute.GetCustomAttribute(_type, typeof(TitleAttribute)); return(title.Title); }
public override void OnGUI(Rect position) { // 获取Attribute TitleAttribute attr = (TitleAttribute)attribute; // 转换颜色 Color color = htmlToColor(attr.htmlColor); // 重绘GUI position = EditorGUI.IndentedRect(position); style.normal.textColor = color; GUI.Label(position, attr.title, style); }
public SampleGroup Load(SampleSuite suite) { Type suiteType = suite.GetType(); // get attributes attached to suite DescriptionAttribute descriptionAttribute = (DescriptionAttribute)Attribute.GetCustomAttribute(suiteType, typeof(DescriptionAttribute)); TitleAttribute titleAttribute = (TitleAttribute)Attribute.GetCustomAttribute(suiteType, typeof(TitleAttribute)); PrefixAttribute prefixAttribute = (PrefixAttribute)Attribute.GetCustomAttribute(suiteType, typeof(PrefixAttribute)); if (prefixAttribute == null) { throw new InvalidOperationException("[Prefix] attribute not specified on " + suiteType.Name); } string prefix = prefixAttribute.Prefix; SampleGroup suiteGroup = new SampleGroup(suite, (titleAttribute != null) ? titleAttribute.Title : "", (descriptionAttribute != null) ? descriptionAttribute.Description : ""); string sourceFile = FindSourceFile(suiteType.Name + ".cs"); string sourceCode = (sourceFile != null) ? File.ReadAllText(sourceFile) : ""; MethodInfo[] categoriesObj = suiteType.GetMethods(); List <string> categories = new List <string>(); foreach (MethodInfo c in categoriesObj) { if (c.Name.StartsWith(prefix) == true) { CategoryAttribute[] attributes = (CategoryAttribute[])c.GetCustomAttributes(typeof(CategoryAttribute), false); if (attributes.Length > 0) { if (categories.Contains(attributes[0].Category) == false) { categories.Add(attributes[0].Category); } } } } foreach (string cat in categories) { suiteGroup.Children.Add(LoadCategory(suite, cat, prefix, sourceCode)); } return(suiteGroup); }
public static List <TitleAttribute> ListTitleAttibute(object target) { List <TitleAttribute> list = new List <TitleAttribute>(); PropertyInfo[] props = target.GetType().GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { TitleAttribute authAttr = attr as TitleAttribute; if (authAttr != null) { list.Add(authAttr); } } } return(list); }
protected override NodeLibrary ConstructNodeLibrary(NodeLibrary library) { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in assemblies) { Type[] types = assembly.GetTypes(); foreach (var type in types) { TitleAttribute titleAttrib = type.GetCustomAttribute <TitleAttribute>(false); string[] title; if (titleAttrib != null) { title = titleAttrib.Title.Split('/'); } else { title = type.FullName.Split('.'); } // Ignore abstract types if (type.IsAbstract) { continue; } if (type.IsSubclassOf(typeof(Composite))) { library.nodeTemplates.Add(new NodeTemplate(title, "UXML/Nodes/GraphNode", "Styles/Nodes/GraphNode", type)); } else if (type.IsSubclassOf(typeof(Decorator))) { library.nodeTemplates.Add(new NodeTemplate(title, "UXML/Nodes/ValueNode", "Styles/Nodes/GraphNode", type)); } else if (type.IsSubclassOf(typeof(Task))) { library.nodeTemplates.Add(new NodeTemplate(title, "UXML/Nodes/ValueNode", "Styles/Nodes/GraphNode", type)); } } } return(library); }
private string GetTitle() { if (View == null || View.DataContext == null) { return(null); } Type type = View.DataContext.GetType().GetInterfaces().FirstOrDefault(t => t.GetCustomAttributes(typeof(TitleAttribute), false).Any()); if (type != null) { TitleAttribute attribute = type.GetCustomAttributes(typeof(TitleAttribute), false).FirstOrDefault() as TitleAttribute; if (attribute != null) { return(attribute.Title); } } return(null); }
static void CreateEnumColumn <TContext, TEntity>(GridColumnFactory <TEntity> cols, KeyValuePair <PropertyInfo, Attribute[]> p) where TContext : CachableDbContext <TContext>, new() where TEntity : class { List <KeyValuePair <int, string> > data = new List <KeyValuePair <int, string> >(); var values = Enum.GetValues(p.Key.PropertyType); foreach (var v in values) { var name = Enum.GetName(p.Key.PropertyType, v); var title = TitleAttribute.GetTitle(p.Key.PropertyType, name); if (string.IsNullOrEmpty(title)) { title = name; } data.Add(new KeyValuePair <int, string>((int)v, title)); } var col = cols.ForeignKey(p.Key.Name, data, "Key", "Value"); SetColumnProperties(p.Key, p.Value, col); }
public TagGroupDocumentation(ResourceKeyStack messagePath, ITagGroup tagGroup, IList <Func <ITag, TagDocumentation, bool> > specials, Dictionary <int, TagDocumentation> tagDictionary) { _messagePath = messagePath.BranchFor(tagGroup); _name = tagGroup.Name; _specials = specials; _tagDictionary = tagDictionary; _tags = new List <int>(); var tagGroupType = tagGroup.GetType(); _description = DescriptionAttribute.Harvest(tagGroupType) ?? _messagePath.Description; _title = TitleAttribute.HarvestTagLibrary(tagGroupType); foreach (ITag _tag in tagGroup) { var hash = _tag.GetType().GetHashCode(); if (!_tagDictionary.ContainsKey(hash)) { _tagDictionary[hash] = null; var tagDoc = new TagDocumentation(_messagePath, _tag, _specials, _tagDictionary); _tagDictionary[hash] = tagDoc; } _tags.Add(hash); } if (ExampleAttribute.Harvest(tagGroupType)) { _examples.AddRange(ExampleAttribute.HarvestTags(tagGroupType)); } if (HasExample.Has(tagGroupType)) { _examples.Add(new ExampleAttribute(_messagePath.Example)); } if (NoteAttribute.Harvest(tagGroupType)) { _notes.AddRange(NoteAttribute.HarvestTags(tagGroupType)); } if (HasNote.Has(tagGroupType)) { _notes.Add(new NoteAttribute(_messagePath.Note)); } }
public static Dictionary <string, string> GetTitleAttibute(object target) { Dictionary <string, string> _dict = new Dictionary <string, string>(); PropertyInfo[] props = target.GetType().GetProperties(); foreach (PropertyInfo prop in props) { object[] attrs = prop.GetCustomAttributes(true); foreach (object attr in attrs) { TitleAttribute titleAttr = attr as TitleAttribute; if (titleAttr != null) { string propName = prop.Name; string auth = titleAttr.Title; _dict.Add(propName, auth); } } } return(_dict); }
public static MvcHtmlString DropDownForEnum <TModel, TProperty>(this HtmlHelper <TModel> html , Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null) { var memberInfo = expression.MemberInfo(); var type = ((PropertyInfo)memberInfo).PropertyType; if (!type.IsEnum) { throw new Exception("The member must be an Enum"); } var builder = new TagBuilder("select"); builder.GenerateId(memberInfo.Name); builder.MergeAttribute("name", expression.MemberName()); object value = GetValue(html, expression); foreach (var name in Enum.GetNames(type)) { var title = TitleAttribute.GetTitle(type.GetField(name, BindingFlags.Public | BindingFlags.Static), name); TagBuilder op = new TagBuilder("option"); var thisVal = (int)Enum.Parse(type, name); op.Attributes["value"] = thisVal.ToString(); if (value != null && (int)value == thisVal) { op.Attributes["selected"] = "selected"; } op.SetInnerText(title); builder.InnerHtml += op.ToString(); } if (htmlAttributes != null) { foreach (var prop in htmlAttributes.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { builder.Attributes[prop.Name] = prop.GetValue(htmlAttributes, null).ToString(); } } return(MvcHtmlString.Create(builder.ToString())); }
public FormDefinition GetDefinition(string xml, bool freeze) { var document = XDocument.Parse(xml); if (document.Root == null) { throw new InvalidOperationException("Invalid XML document."); } void AddMetadata(IDictionary <string, string> dict, XElement xelement) { const int stroffset = 5; // "meta-".Length foreach (var attr in xelement.Attributes()) { if (attr.Name.LocalName.StartsWith("meta-", StringComparison.OrdinalIgnoreCase)) { dict[attr.Name.LocalName.Substring(stroffset)] = attr.Value; } } } FormElement WithMetadata(FormElement element, XElement xelement) { AddMetadata(element.Metadata, xelement); return(element); } ILayout Terminal(XElement element) { var elementName = element.Name.LocalName.ToLower(); FormElement formElement; switch (elementName) { case "layout": return(Layout(element)); case "input": case "textarea": case "toggle": case "password": { var typeName = element.TryGetAttribute("type") ?? "string"; var attributes = new List <Attribute>(); Type propertyType; if (elementName == "input" && TypeConstructors.TryGetValue(typeName, out var constructor)) { var data = constructor(new XmlConstructionContext(element)); propertyType = data.PropertyType; attributes.AddRange(data.CustomAttributes); } else if (!TypeNames.TryGetValue(typeName, out propertyType)) { throw new InvalidOperationException($"Type '{typeName}' not found."); } var fieldName = element.TryGetAttribute("name"); attributes.Add(Utilities.GetFieldAttributeFromElement(element)); attributes.Add(Utilities.GetBindingAttributeFromElement(element)); switch (elementName) { case "textarea": attributes.Add(new MultiLineAttribute()); propertyType = typeof(string); break; case "toggle": attributes.Add(new ToggleAttribute()); propertyType = typeof(bool); break; case "password": attributes.Add(new PasswordAttribute()); propertyType = typeof(string); break; } attributes.AddRange(Utilities.GetValidatorsFromElement(element)); var property = new DynamicProperty(fieldName, propertyType, attributes.ToArray()); var deserializer = TryGetDeserializer(propertyType); formElement = Build(property, deserializer); if (formElement != null) { foreach (var initializer in FieldInitializers) { initializer.Initialize(formElement, property, deserializer); } formElement.LinePosition = (Position)(-1); } return(new FormElementLayout(WithMetadata(formElement, element))); } case "select": { var from = element.TryGetAttribute("from"); object itemsSource; string typeName; string displayPath; string valuePath; Type propertyType = null; if (!string.IsNullOrEmpty(from)) { if (from.StartsWith("type:")) { var qualifiedType = from.Substring("type:".Length); var nullable = false; if (qualifiedType.EndsWith("?")) { qualifiedType = qualifiedType.Substring(0, qualifiedType.Length - 1); nullable = true; } propertyType = Utilities.FindTypes(t => t.FullName == qualifiedType).FirstOrDefault(); itemsSource = propertyType ?? throw new InvalidOperationException($"Could not find type '{qualifiedType}'."); if (propertyType.IsValueType && nullable) { propertyType = typeof(Nullable <>).MakeGenericType(propertyType); itemsSource = propertyType; } typeName = element.TryGetAttribute("type"); } else { itemsSource = from; typeName = element.TryGetAttribute("type") ?? "string"; } displayPath = element.TryGetAttribute("displayPath"); valuePath = element.TryGetAttribute("valuePath"); } else { typeName = "string"; displayPath = "Name"; valuePath = "Value"; itemsSource = Utilities.GetSelectOptionsFromElement(element); } if (typeName != null && !TypeNames.TryGetValue(typeName, out propertyType)) { throw new InvalidOperationException($"Type '{typeName}' not found."); } if (propertyType.IsValueType && element.TryGetAttribute("nullable") != null && (!propertyType.IsGenericType || propertyType.GetGenericTypeDefinition() != typeof(Nullable <>))) { propertyType = typeof(Nullable <>).MakeGenericType(propertyType); } var fieldName = element.TryGetAttribute("name"); var attributes = new List <Attribute> { new SelectFromAttribute(itemsSource) { SelectionType = Utilities.TryParse(element.TryGetAttribute("as"), SelectionType.ComboBox), DisplayPath = displayPath, ValuePath = valuePath, ItemStringFormat = element.TryGetAttribute("itemStringFormat") }, Utilities.GetFieldAttributeFromElement(element), Utilities.GetBindingAttributeFromElement(element) }; attributes.AddRange(Utilities.GetValidatorsFromElement(element)); var property = new DynamicProperty(fieldName, propertyType, attributes.ToArray()); var deserializer = TryGetDeserializer(propertyType); formElement = Build(property, deserializer); if (formElement != null) { foreach (var initializer in FieldInitializers) { initializer.Initialize(formElement, property, deserializer); } formElement.LinePosition = (Position)(-1); } return(new FormElementLayout(WithMetadata(formElement, element))); } case "title": formElement = new TitleAttribute(element.GetAttributeOrValue("content")) { Icon = element.TryGetAttribute("icon") } .WithBaseProperties(element) .WithTextProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "heading": formElement = new HeadingAttribute(element.GetAttributeOrValue("content")) { Icon = element.TryGetAttribute("icon") } .WithBaseProperties(element) .WithTextProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "text": formElement = new TextAttribute(element.GetAttributeOrValue("content")) .WithBaseProperties(element) .WithTextProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "error": formElement = new ErrorTextAttribute(element.GetAttributeOrValue("content")) .WithBaseProperties(element) .WithTextProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "img": formElement = new ImageAttribute(element.TryGetAttribute("src")) { Width = element.TryGetAttribute("width"), Height = element.TryGetAttribute("height"), HorizontalAlignment = element.TryGetAttribute("align"), VerticalAlignment = element.TryGetAttribute("valign"), Stretch = element.TryGetAttribute("stretch"), StretchDirection = element.TryGetAttribute("direction") } .WithBaseProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "br": formElement = new BreakAttribute { Height = element.TryGetAttribute("height") } .WithBaseProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "hr": var hasMargin = element.TryGetAttribute("hasMargin"); formElement = (hasMargin != null ? new DividerAttribute(bool.Parse(hasMargin)) : new DividerAttribute()) .WithBaseProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); case "action": formElement = Utilities.GetAction(element) .WithBaseProperties(element) .GetElement(); return(new FormElementLayout(WithMetadata(formElement, element))); default: throw new InvalidOperationException($"Unknown element '{element.Name.LocalName}'."); } } GridColumnLayout Column(XElement element) { var elements = element.Elements().ToList(); var child = elements.Count == 1 ? Row(elements[0]) : new Layout(elements.Select(Row)); return(new GridColumnLayout( child, Utilities.ParseDouble(element.TryGetAttribute("width"), 1d), Utilities.ParseDouble(element.TryGetAttribute("left"), 0d), Utilities.ParseDouble(element.TryGetAttribute("right"), 0d))); } GridLayout Grid(XElement element) { return(new GridLayout( element.Elements().Select(Column), Utilities.ParseDouble(element.TryGetAttribute("top"), 0d), Utilities.ParseDouble(element.TryGetAttribute("bottom"), 0d))); } InlineLayout Inline(XElement element) { return(new InlineLayout( element.Elements().Select(Terminal), Utilities.ParseDouble(element.TryGetAttribute("top"), 0d), Utilities.ParseDouble(element.TryGetAttribute("bottom"), 0d))); } ILayout Row(XElement element) { if (!string.Equals(element.Name.LocalName, "row", StringComparison.OrdinalIgnoreCase)) { return(Terminal(element)); } if (element .Elements() .All(e => string.Equals(e.Name.LocalName, "col", StringComparison.OrdinalIgnoreCase))) { return(Grid(element)); } return(Inline(element)); } Layout Layout(XElement element) { return(new Layout( element.Elements().Select(Row), Utilities.ParseThickness(element.TryGetAttribute("margin")), Utilities.TryParse(element.TryGetAttribute("valign"), VerticalAlignment.Stretch), Utilities.TryParse(element.TryGetAttribute("align"), HorizontalAlignment.Stretch), Utilities.ParseNullableDouble(element.TryGetAttribute("minHeight")), Utilities.ParseNullableDouble(element.TryGetAttribute("maxHeight")))); } var form = new FormDefinition(null); // null indicates dynamic type AddMetadata(form.Metadata, document.Root); form.FormRows.Add(new FormRow(true, 1) { Elements = { new FormElementContainer(0, 1, Layout(document.Root)) } }); if (freeze) { form.FreezeAll(); } return(form); }
static string GetTitle(ICustomAttributeProvider typeMember, string name = null, Type containingType = null) { return(TitleAttribute.GetTitle(typeMember, name, containingType)); }
public void Initialize() { if (FieldInfo != null) { var methodInfo = this.GetType().GetMethod("RegisterCallbackInternal", BindingFlags.NonPublic | BindingFlags.Instance); var method = methodInfo.MakeGenericMethod(m_fieldInfo.FieldType); VisualElement visualElement = null; bool failed = false; Type type = m_fieldInfo.FieldType; TitleAttribute titleAttrib = m_fieldInfo.GetCustomAttribute <TitleAttribute>(); string fieldName = ""; if (titleAttrib != null) { fieldName = titleAttrib.Title; } else { fieldName = m_fieldInfo.Name; } if (type == typeof(float)) { visualElement = new FloatField(fieldName); } else if (type == typeof(int)) { visualElement = new IntegerField(fieldName); } else if (type == typeof(string)) { visualElement = new TextField(fieldName); } else if (type == typeof(bool)) { visualElement = new Toggle(fieldName); } else if (type == typeof(AnimationCurve)) { visualElement = new CurveField(fieldName); } else if (type == typeof(Vector2)) { visualElement = new Vector2Field(fieldName); } else if (type == typeof(Vector3)) { visualElement = new Vector3Field(fieldName); } else if (type == typeof(Vector4)) { visualElement = new Vector4Field(fieldName); } else if (type == typeof(Color)) { visualElement = new ColorField(fieldName); } else if (type == typeof(Enum)) { visualElement = new EnumField(fieldName); } else { failed = true; visualElement = new ErrorText("Unsupported Field: " + FieldInfo.Name + ":" + type.Name); visualElement.name = "error-text"; } if (!failed) { var baseFieldType = typeof(BaseField <>).MakeGenericType(type); PropertyInfo info = baseFieldType.GetProperty("value"); info.SetValue(visualElement, m_fieldInfo.GetValue(m_fieldOwner)); method?.Invoke(this, new object[] { visualElement }); } this.Add(visualElement); } }
public override float GetHeight() { TitleAttribute title = (TitleAttribute)attribute; return(EditorGUIUtility.singleLineHeight * title.overrideHeight + EditorGUIUtility.singleLineHeight * 0.5f); }
protected void SetParentNodeVars(Graph g) { if (g == null || parentNode == null) { return; } var props = parentNode.GetType().GetProperties(); var p = g; if (p != null) { foreach (var prop in props) { if (!prop.PropertyType.Equals(typeof(int)) && !prop.PropertyType.Equals(typeof(float)) && !prop.PropertyType.Equals(typeof(MVector)) && !prop.PropertyType.Equals(typeof(bool)) && !prop.PropertyType.Equals(typeof(double)) && !prop.PropertyType.Equals(typeof(Vector4))) { continue; } try { HidePropertyAttribute hb = prop.GetCustomAttribute <HidePropertyAttribute>(); if (hb != null) { continue; } } catch { } object v = null; if (p.HasParameterValue(parentNode.Id, prop.Name)) { var gp = p.GetParameterRaw(parentNode.Id, prop.Name); if (!gp.IsFunction()) { v = gp.Value; } else { v = prop.GetValue(parentNode); } } else { v = prop.GetValue(parentNode); } string varName = ""; try { TitleAttribute t = prop.GetCustomAttribute <TitleAttribute>(); if (t != null) { varName = t.Title.Replace(" ", "").Replace("-", ""); } else { varName = prop.Name; } } catch { varName = prop.Name; } if (v != null) { if (v is Vector4) { Vector4 vec = (Vector4)v; v = new MVector(vec.X, vec.Y, vec.Z, vec.W); } SetVar(varName, v); } } } else { foreach (var prop in props) { if (!prop.PropertyType.Equals(typeof(int)) && !prop.PropertyType.Equals(typeof(float)) && !prop.PropertyType.Equals(typeof(MVector)) && !prop.PropertyType.Equals(typeof(bool)) && !prop.PropertyType.Equals(typeof(double)) && !prop.PropertyType.Equals(typeof(Vector4))) { continue; } try { HidePropertyAttribute hb = prop.GetCustomAttribute <HidePropertyAttribute>(); if (hb != null) { continue; } } catch { } object v = prop.GetValue(parentNode); string varName = ""; try { TitleAttribute t = prop.GetCustomAttribute <TitleAttribute>(); if (t != null) { varName = t.Title.Replace(" ", "").Replace("-", ""); } else { varName = prop.Name; } } catch { varName = prop.Name; } if (v != null) { if (v is Vector4) { Vector4 vec = (Vector4)v; v = new MVector(vec.X, vec.Y, vec.Z, vec.W); } SetVar(varName, v); } } } }
void CreateUIElement(Type t, PropertyInfo p, string name) { DropdownAttribute dp = p.GetCustomAttribute <DropdownAttribute>(); LevelEditorAttribute le = p.GetCustomAttribute <LevelEditorAttribute>(); CurveEditorAttribute ce = p.GetCustomAttribute <CurveEditorAttribute>(); SliderAttribute sl = p.GetCustomAttribute <SliderAttribute>(); FileSelectorAttribute fsl = p.GetCustomAttribute <FileSelectorAttribute>(); HidePropertyAttribute hp = p.GetCustomAttribute <HidePropertyAttribute>(); ColorPickerAttribute cp = p.GetCustomAttribute <ColorPickerAttribute>(); TitleAttribute ti = p.GetCustomAttribute <TitleAttribute>(); TextInputAttribute tinp = p.GetCustomAttribute <TextInputAttribute>(); GraphParameterEditorAttribute gpe = p.GetCustomAttribute <GraphParameterEditorAttribute>(); ParameterMapEditorAttribute pme = p.GetCustomAttribute <ParameterMapEditorAttribute>(); PromoteAttribute pro = p.GetCustomAttribute <PromoteAttribute>(); //handle very special stuff //exposed constant parameter variable names if (gpe != null) { if (node is Graph) { Graph g = node as Graph; GraphParameterEditor inp = new GraphParameterEditor(g, g.Parameters); Stack.Children.Add(inp); elementLookup[name] = inp; } } //for graph instance exposed parameters from underlying graph else if (pme != null) { if (node is GraphInstanceNode) { GraphInstanceNode gin = node as GraphInstanceNode; ParameterMap pm = new ParameterMap(gin.GraphInst, gin.Parameters); Stack.Children.Add(pm); elementLookup[name] = pm; } } string title = name; if (ti != null) { title = ti.Title; } PropertyInfo op = null; //we don't create an element for this one //as it is hidden if (hp != null) { return; } try { if (ce != null) { op = node.GetType().GetProperty(ce.OutputProperty); } } catch (Exception e) { Console.WriteLine(e.StackTrace); } if (t.Equals(typeof(Vector4))) { if (cp != null) { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); ColorSelect cs = new ColorSelect(p, node); Stack.Children.Add(cs); elementLookup[name] = cs; } } else if (t.Equals(typeof(string[]))) { if (dp != null) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); DropDown inp = new DropDown((string[])p.GetValue(node), node, p, dp.OutputProperty); Stack.Children.Add(inp); elementLookup[name] = inp; } } else if (t.Equals(typeof(bool))) { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); ToggleControl tg = new ToggleControl(name, p, node); Stack.Children.Add(tg); elementLookup[name] = tg; } else if (t.Equals(typeof(string))) { if (tinp != null) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); PropertyInput ip = new PropertyInput(p, node); Stack.Children.Add(ip); elementLookup[name] = ip; } else if (fsl != null) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); FileSelector inp = new FileSelector(p, node, fsl.Filter); Stack.Children.Add(inp); elementLookup[name] = inp; } else if (dp != null) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); object[] names = dp.Values; DropDown inp = new DropDown(names, node, p, dp.OutputProperty); Stack.Children.Add(inp); elementLookup[name] = inp; } } if (t.Equals(typeof(float))) { if (sl != null) { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); NumberSlider inp = new NumberSlider(sl, p, node); Stack.Children.Add(inp); elementLookup[name] = inp; } else { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); NumberInput inp = new NumberInput(NumberInputType.Float, node, p); Stack.Children.Add(inp); elementLookup[name] = inp; } } else if (t.Equals(typeof(int))) { if (dp != null) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); //do a dropdown object[] names = dp.Values; DropDown inp = new DropDown(names, node, p, dp.OutputProperty); Stack.Children.Add(inp); elementLookup[name] = inp; } else if (sl != null) { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); NumberSlider inp = new NumberSlider(sl, p, node); Stack.Children.Add(inp); elementLookup[name] = inp; } else { PropertyLabel l = null; if (pro != null && node is Node) { l = new PropertyLabel(title, node as Node, name); } else { l = new PropertyLabel(); l.Title = title; } labels.Add(l); Stack.Children.Add(l); NumberInput inp = new NumberInput(NumberInputType.Int, node, p); Stack.Children.Add(inp); elementLookup[name] = inp; } } else if (t.Equals(typeof(MultiRange))) { if (le != null) { UILevels lv = null; if (node is Node) { Node nd = (Node)node; if (nd.Inputs.Count > 0 && nd.Inputs[0].Input != null) { var n = nd.Inputs[0].Input.Node; byte[] result = n.GetPreview(n.Width, n.Height); RawBitmap bit = null; if (result != null) { bit = new RawBitmap(n.Width, n.Height, result); } lv = new UILevels(bit, node, p); } else { lv = new UILevels(null, node, p); } Stack.Children.Add(lv); elementLookup[name] = lv; } } } else if (op != null && ce != null) { UICurves cv = new UICurves(p, op, node); Stack.Children.Add(cv); elementLookup[name] = cv; } else if (t.IsEnum) { PropertyLabel l = new PropertyLabel(); l.Title = title; labels.Add(l); Stack.Children.Add(l); string[] names = Enum.GetNames(t); DropDown inp = new DropDown(names, node, p); Stack.Children.Add(inp); elementLookup[name] = inp; } }
public void GenerateNodeEntries() { Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries"); // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. List <NodeEntry> nodeEntries = new List <NodeEntry>(); bool hideCustomInterpolators = m_Graph.activeTargets.All(at => at.ignoreCustomInterpolators); if (target is ContextView contextView) { // Iterate all BlockFieldDescriptors currently cached on GraphData foreach (var field in m_Graph.blockFieldDescriptors) { if (field.isHidden) { continue; } // Test stage if (field.shaderStage != contextView.contextData.shaderStage) { continue; } // Create title List <string> title = ListPool <string> .Get(); if (!string.IsNullOrEmpty(field.path)) { var path = field.path.Split('/').ToList(); title.AddRange(path); } title.Add(field.displayName); // Create and initialize BlockNode instance then add entry var node = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); node.Init(field); AddEntries(node, title.ToArray(), nodeEntries); } SortEntries(nodeEntries); if (contextView.contextData.shaderStage == ShaderStage.Vertex && !hideCustomInterpolators) { var customBlockNodeStub = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); customBlockNodeStub.InitCustomDefault(); AddEntries(customBlockNodeStub, new string[] { "Custom Interpolator" }, nodeEntries); } currentNodeEntries = nodeEntries; return; } Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateKnowNodes"); foreach (var type in NodeClassCache.knownNodeTypes) { if ((!type.IsClass || type.IsAbstract) || type == typeof(PropertyNode) || type == typeof(KeywordNode) || type == typeof(DropdownNode) || type == typeof(SubGraphNode)) { continue; } TitleAttribute titleAttribute = NodeClassCache.GetAttributeOnNodeType <TitleAttribute>(type); if (titleAttribute != null) { var node = (AbstractMaterialNode)Activator.CreateInstance(type); if (!node.ExposeToSearcher) { continue; } if (ShaderGraphPreferences.allowDeprecatedBehaviors && node.latestVersion > 0) { var versions = node.allowedNodeVersions ?? Enumerable.Range(0, node.latestVersion + 1); bool multiple = (versions.Count() > 1); foreach (int i in versions) { var depNode = (AbstractMaterialNode)Activator.CreateInstance(type); depNode.ChangeVersion(i); if (multiple) { AddEntries(depNode, titleAttribute.title.Append($"v{i}").ToArray(), nodeEntries); } else { AddEntries(depNode, titleAttribute.title, nodeEntries); } } } else { AddEntries(node, titleAttribute.title, nodeEntries); } } } Profiler.EndSample(); Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateSubgraphAssets"); foreach (var asset in NodeClassCache.knownSubGraphAssets) { if (asset == null) { continue; } var node = new SubGraphNode { asset = asset }; var title = asset.path.Split('/').ToList(); if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid) { continue; } if (string.IsNullOrEmpty(asset.path)) { AddEntries(node, new string[1] { asset.name }, nodeEntries); } else if (title[0] != k_HiddenFolderName) { title.Add(asset.name); AddEntries(node, title.ToArray(), nodeEntries); } } Profiler.EndSample(); Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries.IterateGraphInputs"); foreach (var property in m_Graph.properties) { if (property is Serialization.MultiJsonInternal.UnknownShaderPropertyType) { continue; } var node = new PropertyNode(); node.property = property; AddEntries(node, new[] { "Properties", "Property: " + property.displayName }, nodeEntries); } foreach (var keyword in m_Graph.keywords) { var node = new KeywordNode(); node.keyword = keyword; AddEntries(node, new[] { "Keywords", "Keyword: " + keyword.displayName }, nodeEntries); } foreach (var dropdown in m_Graph.dropdowns) { var node = new DropdownNode(); node.dropdown = dropdown; AddEntries(node, new[] { "Dropdowns", "dropdown: " + dropdown.displayName }, nodeEntries); } if (!hideCustomInterpolators) { foreach (var cibnode in m_Graph.vertexContext.blocks.Where(b => b.value.isCustomBlock)) { var node = Activator.CreateInstance <CustomInterpolatorNode>(); node.ConnectToCustomBlock(cibnode.value); AddEntries(node, new[] { "Custom Interpolator", cibnode.value.customName }, nodeEntries); } } Profiler.EndSample(); SortEntries(nodeEntries); currentNodeEntries = nodeEntries; Profiler.EndSample(); }
public void GenerateNodeEntries() { Profiler.BeginSample("SearchWindowProvider.GenerateNodeEntries"); // First build up temporary data structure containing group & title as an array of strings (the last one is the actual title) and associated node type. List <NodeEntry> nodeEntries = new List <NodeEntry>(); if (target is ContextView contextView) { // Iterate all BlockFieldDescriptors currently cached on GraphData foreach (var field in m_Graph.blockFieldDescriptors) { if (field.isHidden) { continue; } // Test stage if (field.shaderStage != contextView.contextData.shaderStage) { continue; } // Create title List <string> title = ListPool <string> .Get(); if (!string.IsNullOrEmpty(field.path)) { var path = field.path.Split('/').ToList(); title.AddRange(path); } title.Add(field.displayName); // Create and initialize BlockNode instance then add entry var node = (BlockNode)Activator.CreateInstance(typeof(BlockNode)); node.Init(field); AddEntries(node, title.ToArray(), nodeEntries); } SortEntries(nodeEntries); currentNodeEntries = nodeEntries; return; } foreach (var type in NodeClassCache.knownNodeTypes) { if ((!type.IsClass || type.IsAbstract) || type == typeof(PropertyNode) || type == typeof(KeywordNode) || type == typeof(SubGraphNode)) { continue; } TitleAttribute titleAttribute = NodeClassCache.GetAttributeOnNodeType <TitleAttribute>(type); if (titleAttribute != null) { var node = (AbstractMaterialNode)Activator.CreateInstance(type); if (ShaderGraphPreferences.allowDeprecatedBehaviors && node.latestVersion > 0) { var versions = node.allowedNodeVersions ?? Enumerable.Range(0, node.latestVersion + 1); bool multiple = (versions.Count() > 1); foreach (int i in versions) { var depNode = (AbstractMaterialNode)Activator.CreateInstance(type); depNode.ChangeVersion(i); if (multiple) { AddEntries(depNode, titleAttribute.title.Append($"V{i}").ToArray(), nodeEntries); } else { AddEntries(depNode, titleAttribute.title, nodeEntries); } } } else { AddEntries(node, titleAttribute.title, nodeEntries); } } } foreach (var guid in AssetDatabase.FindAssets(string.Format("t:{0}", typeof(SubGraphAsset)))) { var asset = AssetDatabase.LoadAssetAtPath <SubGraphAsset>(AssetDatabase.GUIDToAssetPath(guid)); var node = new SubGraphNode { asset = asset }; var title = asset.path.Split('/').ToList(); if (asset.descendents.Contains(m_Graph.assetGuid) || asset.assetGuid == m_Graph.assetGuid) { continue; } if (string.IsNullOrEmpty(asset.path)) { AddEntries(node, new string[1] { asset.name }, nodeEntries); } else if (title[0] != k_HiddenFolderName) { title.Add(asset.name); AddEntries(node, title.ToArray(), nodeEntries); } } foreach (var property in m_Graph.properties) { if (property is Serialization.MultiJsonInternal.UnknownShaderPropertyType) { continue; } var node = new PropertyNode(); node.property = property; AddEntries(node, new[] { "Properties", "Property: " + property.displayName }, nodeEntries); } foreach (var keyword in m_Graph.keywords) { var node = new KeywordNode(); node.keyword = keyword; AddEntries(node, new[] { "Keywords", "Keyword: " + keyword.displayName }, nodeEntries); } SortEntries(nodeEntries); currentNodeEntries = nodeEntries; Profiler.EndSample(); }
public EnumValue(FieldInfo field) { _value = (T)field.GetValue(null); _title = (TitleAttribute)field.GetCustomAttributes(typeof(TitleAttribute), false)[0]; _description = (DescriptionAttribute)field.GetCustomAttributes(typeof(DescriptionAttribute), false)[0]; }