示例#1
0
        private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
        {
            string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
            if ((shaderPropertyAttributes == null) || (shaderPropertyAttributes.Length == 0))
            {
                return(null);
            }
            MaterialPropertyHandler handler = new MaterialPropertyHandler();

            foreach (string str in shaderPropertyAttributes)
            {
                bool flag;
                MaterialPropertyDrawer shaderPropertyDrawer = GetShaderPropertyDrawer(str, out flag);
                if (shaderPropertyDrawer != null)
                {
                    if (flag)
                    {
                        if (handler.m_DecoratorDrawers == null)
                        {
                            handler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>();
                        }
                        handler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
                    }
                    else
                    {
                        if (handler.m_PropertyDrawer != null)
                        {
                            Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader);
                        }
                        handler.m_PropertyDrawer = shaderPropertyDrawer;
                    }
                }
            }
            return(handler);
        }
        internal static MaterialPropertyHandler GetHandler(Shader shader, string name)
        {
            MaterialPropertyHandler result;

            if (shader == null)
            {
                result = null;
            }
            else
            {
                string propertyString = MaterialPropertyHandler.GetPropertyString(shader, name);
                MaterialPropertyHandler materialPropertyHandler;
                if (MaterialPropertyHandler.s_PropertyHandlers.TryGetValue(propertyString, out materialPropertyHandler))
                {
                    result = materialPropertyHandler;
                }
                else
                {
                    materialPropertyHandler = MaterialPropertyHandler.GetShaderPropertyHandler(shader, name);
                    if (materialPropertyHandler != null && materialPropertyHandler.IsEmpty())
                    {
                        materialPropertyHandler = null;
                    }
                    MaterialPropertyHandler.s_PropertyHandlers[propertyString] = materialPropertyHandler;
                    result = materialPropertyHandler;
                }
            }
            return(result);
        }
        private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
        {
            string[] propertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
            if (propertyAttributes == null || propertyAttributes.Length == 0)
            {
                return((MaterialPropertyHandler)null);
            }
            MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler();

            foreach (string attrib in propertyAttributes)
            {
                bool isDecorator;
                MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out isDecorator);
                if (shaderPropertyDrawer != null)
                {
                    if (isDecorator)
                    {
                        if (materialPropertyHandler.m_DecoratorDrawers == null)
                        {
                            materialPropertyHandler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>();
                        }
                        materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
                    }
                    else
                    {
                        if (materialPropertyHandler.m_PropertyDrawer != null)
                        {
                            Debug.LogWarning((object)string.Format("Shader property {0} already has a property drawer", (object)name), (UnityEngine.Object)shader);
                        }
                        materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer;
                    }
                }
            }
            return(materialPropertyHandler);
        }
        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);
        }
        private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
        {
            if (name == null)
            {
                return(null);
            }
            int propertyIndex = shader.FindPropertyIndex(name);

            if (propertyIndex < 0)
            {
                return(null);
            }
            string[] attribs = shader.GetPropertyAttributes(propertyIndex);
            if (attribs == null || attribs.Length == 0)
            {
                return(null);
            }

            var handler = new MaterialPropertyHandler();

            foreach (var attr in attribs)
            {
                bool isDecorator;
                MaterialPropertyDrawer drawer = GetShaderPropertyDrawer(attr, out isDecorator);
                if (drawer != null)
                {
                    if (isDecorator)
                    {
                        if (handler.m_DecoratorDrawers == null)
                        {
                            handler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>();
                        }
                        handler.m_DecoratorDrawers.Add(drawer);
                    }
                    else
                    {
                        if (handler.m_PropertyDrawer != null)
                        {
                            Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader);
                        }
                        handler.m_PropertyDrawer = drawer;
                    }
                }
            }

            return(handler);
        }
        private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
        {
            string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
            MaterialPropertyHandler result;

            if (shaderPropertyAttributes == null || shaderPropertyAttributes.Length == 0)
            {
                result = null;
            }
            else
            {
                MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler();
                string[] array = shaderPropertyAttributes;
                for (int i = 0; i < array.Length; i++)
                {
                    string attrib = array[i];
                    bool   flag;
                    MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out flag);
                    if (shaderPropertyDrawer != null)
                    {
                        if (flag)
                        {
                            if (materialPropertyHandler.m_DecoratorDrawers == null)
                            {
                                materialPropertyHandler.m_DecoratorDrawers = new List <MaterialPropertyDrawer>();
                            }
                            materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
                        }
                        else
                        {
                            if (materialPropertyHandler.m_PropertyDrawer != null)
                            {
                                Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader);
                            }
                            materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer;
                        }
                    }
                }
                result = materialPropertyHandler;
            }
            return(result);
        }
        internal static MaterialPropertyHandler GetHandler(Shader shader, string name)
        {
            if ((UnityEngine.Object)shader == (UnityEngine.Object)null)
            {
                return((MaterialPropertyHandler)null);
            }
            string propertyString = MaterialPropertyHandler.GetPropertyString(shader, name);
            MaterialPropertyHandler materialPropertyHandler;

            if (MaterialPropertyHandler.s_PropertyHandlers.TryGetValue(propertyString, out materialPropertyHandler))
            {
                return(materialPropertyHandler);
            }
            materialPropertyHandler = MaterialPropertyHandler.GetShaderPropertyHandler(shader, name);
            if (materialPropertyHandler != null && materialPropertyHandler.IsEmpty())
            {
                materialPropertyHandler = (MaterialPropertyHandler)null;
            }
            MaterialPropertyHandler.s_PropertyHandlers[propertyString] = materialPropertyHandler;
            return(materialPropertyHandler);
        }
示例#8
0
        private static MaterialPropertyDrawer GetShaderPropertyDrawer(string attrib, out bool isDecorator)
        {
            isDecorator = false;
            string text  = attrib;
            string text2 = string.Empty;
            Match  match = Regex.Match(attrib, "(\\w+)\\s*\\((.*)\\)");

            if (match.Success)
            {
                text  = match.Groups[1].Value;
                text2 = match.Groups[2].Value.Trim();
            }
            foreach (Type current in EditorAssemblies.SubclassesOf(typeof(MaterialPropertyDrawer)))
            {
                if (!(current.Name == text) && !(current.Name == text + "Drawer") && !(current.Name == "Material" + text + "Drawer") && !(current.Name == text + "Decorator"))
                {
                    if (!(current.Name == "Material" + text + "Decorator"))
                    {
                        continue;
                    }
                }
                try
                {
                    isDecorator = current.Name.EndsWith("Decorator");
                    MaterialPropertyDrawer result = MaterialPropertyHandler.CreatePropertyDrawer(current, text2);
                    return(result);
                }
                catch (Exception)
                {
                    Debug.LogWarningFormat("Failed to create material drawer {0} with arguments '{1}'", new object[]
                    {
                        text,
                        text2
                    });
                    MaterialPropertyDrawer result = null;
                    return(result);
                }
            }
            return(null);
        }
 private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
 {
   string[] propertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
   if (propertyAttributes == null || propertyAttributes.Length == 0)
     return (MaterialPropertyHandler) null;
   MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler();
   foreach (string attrib in propertyAttributes)
   {
     bool isDecorator;
     MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out isDecorator);
     if (shaderPropertyDrawer != null)
     {
       if (isDecorator)
       {
         if (materialPropertyHandler.m_DecoratorDrawers == null)
           materialPropertyHandler.m_DecoratorDrawers = new List<MaterialPropertyDrawer>();
         materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
       }
       else
       {
         if (materialPropertyHandler.m_PropertyDrawer != null)
           Debug.LogWarning((object) string.Format("Shader property {0} already has a property drawer", (object) name), (UnityEngine.Object) shader);
         materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer;
       }
     }
   }
   return materialPropertyHandler;
 }
 private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
 {
     string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
     if ((shaderPropertyAttributes == null) || (shaderPropertyAttributes.Length == 0))
     {
         return null;
     }
     MaterialPropertyHandler handler = new MaterialPropertyHandler();
     foreach (string str in shaderPropertyAttributes)
     {
         bool flag;
         MaterialPropertyDrawer shaderPropertyDrawer = GetShaderPropertyDrawer(str, out flag);
         if (shaderPropertyDrawer != null)
         {
             if (flag)
             {
                 if (handler.m_DecoratorDrawers == null)
                 {
                     handler.m_DecoratorDrawers = new List<MaterialPropertyDrawer>();
                 }
                 handler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
             }
             else
             {
                 if (handler.m_PropertyDrawer != null)
                 {
                     Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader);
                 }
                 handler.m_PropertyDrawer = shaderPropertyDrawer;
             }
         }
     }
     return handler;
 }
		private static MaterialPropertyHandler GetShaderPropertyHandler(Shader shader, string name)
		{
			string[] shaderPropertyAttributes = ShaderUtil.GetShaderPropertyAttributes(shader, name);
			if (shaderPropertyAttributes == null || shaderPropertyAttributes.Length == 0)
			{
				return null;
			}
			MaterialPropertyHandler materialPropertyHandler = new MaterialPropertyHandler();
			string[] array = shaderPropertyAttributes;
			for (int i = 0; i < array.Length; i++)
			{
				string attrib = array[i];
				bool flag;
				MaterialPropertyDrawer shaderPropertyDrawer = MaterialPropertyHandler.GetShaderPropertyDrawer(attrib, out flag);
				if (shaderPropertyDrawer != null)
				{
					if (flag)
					{
						if (materialPropertyHandler.m_DecoratorDrawers == null)
						{
							materialPropertyHandler.m_DecoratorDrawers = new List<MaterialPropertyDrawer>();
						}
						materialPropertyHandler.m_DecoratorDrawers.Add(shaderPropertyDrawer);
					}
					else
					{
						if (materialPropertyHandler.m_PropertyDrawer != null)
						{
							Debug.LogWarning(string.Format("Shader property {0} already has a property drawer", name), shader);
						}
						materialPropertyHandler.m_PropertyDrawer = shaderPropertyDrawer;
					}
				}
			}
			return materialPropertyHandler;
		}