Example #1
0
 public static Material MatFrom(MaterialRequest req)
 {
     if (!UnityData.IsInMainThread)
     {
         Log.Error("Tried to get a material from a different thread.");
         return(null);
     }
     if (req.mainTex == null)
     {
         Log.Error("MatFrom with null sourceTex.");
         return(BaseContent.BadMat);
     }
     if (req.shader == null)
     {
         Log.Warning("Matfrom with null shader.");
         return(BaseContent.BadMat);
     }
     if (req.maskTex != null && !req.shader.SupportsMaskTex())
     {
         Log.Error("MaterialRequest has maskTex but shader does not support it. req=" + req.ToString());
         req.maskTex = null;
     }
     if (!matDictionary.TryGetValue(req, out Material value))
     {
         value             = MaterialAllocator.Create(req.shader);
         value.name        = req.shader.name + "_" + req.mainTex.name;
         value.mainTexture = req.mainTex;
         value.color       = req.color;
         if (req.maskTex != null)
         {
             value.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
             value.SetColor(ShaderPropertyIDs.ColorTwo, req.colorTwo);
         }
         if (req.renderQueue != 0)
         {
             value.renderQueue = req.renderQueue;
         }
         if (!req.shaderParameters.NullOrEmpty())
         {
             for (int i = 0; i < req.shaderParameters.Count; i++)
             {
                 req.shaderParameters[i].Apply(value);
             }
         }
         matDictionary.Add(req, value);
         if (!matDictionary.ContainsKey(req))
         {
             Log.Error("MaterialRequest is not present in the dictionary even though we've just added it there. The equality operators are most likely defined incorrectly.");
         }
         if (req.shader == ShaderDatabase.CutoutPlant || req.shader == ShaderDatabase.TransparentPlant)
         {
             WindManager.Notify_PlantMaterialCreated(value);
         }
     }
     return(value);
 }
        public static Material MatFrom(MaterialRequest req)
        {
            if (!UnityData.IsInMainThread)
            {
                Log.Error("Tried to get a material from a different thread.");
                return(null);
            }
            if ((Object)req.mainTex == (Object)null)
            {
                Log.Error("MatFrom with null sourceTex.");
                return(BaseContent.BadMat);
            }
            if ((Object)req.shader == (Object)null)
            {
                Log.Warning("Matfrom with null shader.");
                return(BaseContent.BadMat);
            }
            if ((Object)req.maskTex != (Object)null && !req.shader.SupportsMaskTex())
            {
                Log.Error("MaterialRequest has maskTex but shader does not support it. req=" + req.ToString());
                req.maskTex = null;
            }
            Material material = default(Material);

            if (!MaterialPool.matDictionary.TryGetValue(req, out material))
            {
                material             = new Material(req.shader);
                material.name        = req.shader.name + "_" + req.mainTex.name;
                material.mainTexture = req.mainTex;
                material.color       = req.color;
                if ((Object)req.maskTex != (Object)null)
                {
                    material.SetTexture(ShaderPropertyIDs.MaskTex, req.maskTex);
                    material.SetColor(ShaderPropertyIDs.ColorTwo, req.colorTwo);
                }
                if (req.renderQueue != 0)
                {
                    material.renderQueue = req.renderQueue;
                }
                MaterialPool.matDictionary.Add(req, material);
                if (!MaterialPool.matDictionary.ContainsKey(req))
                {
                    Log.Error("MaterialRequest is not present in the dictionary even though we've just added it there. The equality operators are most likely defined incorrectly.");
                }
                if ((Object)req.shader == (Object)ShaderDatabase.CutoutPlant || (Object)req.shader == (Object)ShaderDatabase.TransparentPlant)
                {
                    WindManager.Notify_PlantMaterialCreated(material);
                }
            }
            return(material);
        }