MaterialUtil_Tips.lua 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ---@class MaterialUtil @注释
  2. ---@field greyMat UnityEngine.Material
  3. MaterialUtil = class()
  4. local this = MaterialUtil
  5. this.isHasInitShader = false
  6. local editorMode = CS.TCFramework.ResourceManager.editorMode
  7. local isGameBranch = ResourceManager.isGameBranch
  8. function this.GetGreyMat()
  9. if this.greyMat then
  10. return
  11. end
  12. if editorMode and not isGameBranch then
  13. local greyshader = ShaderEx.Find("UI/Grey712")
  14. if greyshader ~= nil then
  15. this.greyMat = CS.UnityEngine.Material(greyshader)
  16. end
  17. else
  18. if not this.isHasInitShader then
  19. return nil
  20. end
  21. local greyshader = ShaderEx.Find("UI/Grey712")
  22. if greyshader ~= nil then
  23. this.greyMat = CS.UnityEngine.Material(greyshader)
  24. end
  25. end
  26. return this.greyMat
  27. end
  28. function this.SetFloat(go,floatId, f)
  29. local rs = go:GetComponentsInChildren(typeof(CS.UnityEngine.Renderer))
  30. for i = 0, rs.Length - 1 do
  31. local r = rs[i]
  32. for j = 0, r.materials.Length - 1 do
  33. local mat = r.materials[j]
  34. if mat then
  35. if mat:HasProperty(floatId) then
  36. mat:SetFloat(floatId,f)
  37. end
  38. end
  39. end
  40. end
  41. end