public static MaterialSource GetMaterialSource(object src)
        {
            if (src is Renderer)
            {
                return(RendererMaterialSource.GetMaterialSource(src as Renderer));
            }
            else if (src is UnityEngine.UI.Graphic)
            {
                return(GraphicMaterialSource.GetMaterialSource(src as UnityEngine.UI.Graphic));
            }

            var go   = com.spacepuppy.Utils.GameObjectUtil.GetGameObjectFromSource(src);
            var rend = go.GetComponent <Renderer>();

            if (rend != null)
            {
                return(RendererMaterialSource.GetMaterialSource(rend));
            }

            var graph = go.GetComponent <UnityEngine.UI.Graphic>();

            if (graph != null)
            {
                return(GraphicMaterialSource.GetMaterialSource(graph));
            }

            return(null);
        }
        public static Material GetUniqueMaterial(this UnityEngine.UI.Graphic graphic, bool forceUnique = false)
        {
            if (graphic == null)
            {
                throw new System.ArgumentNullException("graphic");
            }

            var source = GraphicMaterialSource.GetMaterialSource(graphic);

            if (!source.IsUnique || forceUnique)
            {
                return(source.GetUniqueMaterial());
            }
            else
            {
                return(source.Material);
            }
        }