UnityEditor.MaterialPropertyHandler.CreatePropertyDrawer C# (CSharp) Method

CreatePropertyDrawer() private static method

private static CreatePropertyDrawer ( Type klass, string argsText ) : MaterialPropertyDrawer
klass System.Type
argsText string
return MaterialPropertyDrawer
        private static MaterialPropertyDrawer CreatePropertyDrawer(Type klass, string argsText)
        {
            if (string.IsNullOrEmpty(argsText))
            {
                return (Activator.CreateInstance(klass) as MaterialPropertyDrawer);
            }
            char[] separator = new char[] { ',' };
            string[] strArray = argsText.Split(separator);
            object[] args = new object[strArray.Length];
            for (int i = 0; i < strArray.Length; i++)
            {
                float num2;
                string s = strArray[i].Trim();
                if (float.TryParse(s, NumberStyles.Float, (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat, out num2))
                {
                    args[i] = num2;
                }
                else
                {
                    args[i] = s;
                }
            }
            return (Activator.CreateInstance(klass, args) as MaterialPropertyDrawer);
        }

Usage Example

        private static MaterialPropertyDrawer GetShaderPropertyDrawer(string attrib, out bool isDecorator)
        {
            isDecorator = false;
            string str      = attrib;
            string argsText = string.Empty;
            Match  match    = Regex.Match(attrib, "(\\w+)\\s*\\((.*)\\)");

            if (match.Success)
            {
                str      = match.Groups[1].Value;
                argsText = match.Groups[2].Value.Trim();
            }
            foreach (System.Type klass in EditorAssemblies.SubclassesOf(typeof(MaterialPropertyDrawer)))
            {
                if (!(klass.Name == str))
                {
                    if (!(klass.Name == str + "Drawer"))
                    {
                        if (!(klass.Name == "Material" + str + "Drawer"))
                        {
                            if (!(klass.Name == str + "Decorator"))
                            {
                                if (!(klass.Name == "Material" + str + "Decorator"))
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
                try
                {
                    isDecorator = klass.Name.EndsWith("Decorator");
                    return(MaterialPropertyHandler.CreatePropertyDrawer(klass, argsText));
                }
                catch (Exception ex)
                {
                    Debug.LogWarningFormat("Failed to create material drawer {0} with arguments '{1}'", new object[2]
                    {
                        (object)str,
                        (object)argsText
                    });
                    return((MaterialPropertyDrawer)null);
                }
            }
            return((MaterialPropertyDrawer)null);
        }
All Usage Examples Of UnityEditor.MaterialPropertyHandler::CreatePropertyDrawer