public static void SetImageSprite(Image image, GameObject prefab, bool isShowSpecMatrial = false) { if (image == null) { return; } if (prefab == null) { image.set_sprite(null); return; } SpriteRenderer component = prefab.GetComponent <SpriteRenderer>(); if (component != null) { image.set_sprite(component.sprite); if (isShowSpecMatrial && component.sharedMaterial != null && component.sharedMaterial.shader != null && !component.sharedMaterial.shader.name.Equals(CUIUtility.s_ui_defaultShaderName)) { float[] materailMaskPars = CUIUtility.GetMaterailMaskPars(image.get_material()); image.set_material(new Material(component.sharedMaterial)); image.get_material().shaderKeywords = component.sharedMaterial.shaderKeywords; CUIUtility.SetMaterailMaskPars(materailMaskPars, image.get_material()); } else if (isShowSpecMatrial) { image.set_material(null); } } if (image is Image2) { SGameSpriteSettings component2 = prefab.GetComponent <SGameSpriteSettings>(); Image2 image2 = image as Image2; image2.alphaTexLayout = ((component2 != null) ? component2.layout : ImageAlphaTexLayout.None); } }
public static void SetImageSprite(Image image, GameObject prefab) { if (image != null) { if (prefab == null) { image.sprite = null; } else { SpriteRenderer component = prefab.GetComponent <SpriteRenderer>(); if (component != null) { image.sprite = component.sprite; } if (image is Image2) { SGameSpriteSettings settings = prefab.GetComponent <SGameSpriteSettings>(); Image2 image2 = image as Image2; image2.alphaTexLayout = (settings == null) ? ImageAlphaTexLayout.None : settings.layout; } } } }