public void SetMaterial() { mGraphic = this.GetComponent <MaskableGraphic>(); if (mGraphic != null) { if (mGraphic.material == null || mGraphic.material.name == "Default UI Material") { //Applying default material with UI Image Crop shader mGraphic.material = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/UIScreen")); } } else { Debug.LogError("Please attach component to a Graphical UI component"); } }
// Use this for initialization void Start() { if (MaskArea == null) { MaskArea = GetComponent <RectTransform>(); } var text = GetComponent <Text>(); if (text != null) { mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader")); text.material = mat; cachedCanvas = text.canvas; cachedCanvasTransform = cachedCanvas.transform; // For some reason, having the mask control on the parent and disabled stops the mouse interacting // with the texture layer that is not visible.. Not needed for the Image. if (transform.parent.GetComponent <Mask>() == null) { transform.parent.gameObject.AddComponent <Mask>(); } transform.parent.GetComponent <Mask>().enabled = false; return; } var graphic = GetComponent <Graphic>(); if (graphic != null) { mat = new Material(ShaderLibrary.GetShaderInstance("UI Extensions/SoftMaskShader")); graphic.material = mat; cachedCanvas = graphic.canvas; cachedCanvasTransform = cachedCanvas.transform; } }
protected bool Initialize() { // initialize members if (_transform == null) { _transform = transform; } if (pSystem == null) { pSystem = GetComponent <ParticleSystem>(); if (pSystem == null) { return(false); } #if UNITY_5_5_OR_NEWER mainModule = pSystem.main; if (pSystem.main.maxParticles > 14000) { mainModule.maxParticles = 14000; } #else if (pSystem.maxParticles > 14000) { pSystem.maxParticles = 14000; } #endif pRenderer = pSystem.GetComponent <ParticleSystemRenderer>(); if (pRenderer != null) { pRenderer.enabled = false; } if (material == null) { var foundShader = ShaderLibrary.GetShaderInstance("UI Extensions/Particles/Additive"); if (foundShader) { material = new Material(foundShader); } } currentMaterial = material; if (currentMaterial && currentMaterial.HasProperty("_MainTex")) { currentTexture = currentMaterial.mainTexture; if (currentTexture == null) { currentTexture = Texture2D.whiteTexture; } } material = currentMaterial; // automatically set scaling #if UNITY_5_5_OR_NEWER mainModule.scalingMode = ParticleSystemScalingMode.Hierarchy; #else pSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; #endif particles = null; } #if UNITY_5_5_OR_NEWER if (particles == null) { particles = new ParticleSystem.Particle[pSystem.main.maxParticles]; } #else if (particles == null) { particles = new ParticleSystem.Particle[pSystem.maxParticles]; } #endif imageUV = new Vector4(0, 0, 1, 1); // prepare texture sheet animation textureSheetAnimation = pSystem.textureSheetAnimation; textureSheetAnimationFrames = 0; textureSheetAnimationFrameSize = Vector2.zero; if (textureSheetAnimation.enabled) { textureSheetAnimationFrames = textureSheetAnimation.numTilesX * textureSheetAnimation.numTilesY; textureSheetAnimationFrameSize = new Vector2(1f / textureSheetAnimation.numTilesX, 1f / textureSheetAnimation.numTilesY); } return(true); }