// ------------------------------------------------------------------ /// Return shared material matchs given shader and texture // ------------------------------------------------------------------ public static Material GetMaterial(Shader _shader, Texture _texture) { if (_shader == null) { _shader = Shader.Find("ex2D/Alpha Blended"); if (_shader == null) { return(null); } } MaterialTableKey key = new MaterialTableKey(_shader, _texture); Material mat; if (!materialTable.TryGetValue(key, out mat) || mat == null) { mat = new Material(_shader); mat.hideFlags = HideFlags.DontSave; mat.mainTexture = _texture; materialTable[key] = mat; } return(mat); }
// ------------------------------------------------------------------ /// Return shared material matchs given shader and texture for the clipping // ------------------------------------------------------------------ public Material GetClippedMaterial(Shader _shader, Texture _texture) { if (_shader == null) { _shader = Shader.Find("ex2D/Alpha Blended" + shaderPostfix); if (_shader == null) { return(null); } } else { Shader clipShader = Shader.Find(_shader.name + shaderPostfix); if (clipShader == null) { Debug.LogError("Failed to find clip shader named " + _shader.name + shaderPostfix); return(null); } _shader = clipShader; } MaterialTableKey key = new MaterialTableKey(_shader, _texture); Material mat; if (!materialTable.TryGetValue(key, out mat) || mat == null) { mat = new Material(_shader); mat.hideFlags = HideFlags.DontSave; mat.mainTexture = _texture; // also update clip rect Rect rect = GetWorldAABoundingRect(); Vector4 clipRect = new Vector4(rect.center.x, rect.center.y, rect.width, rect.height); mat.SetVector("_ClipRect", clipRect); materialTable[key] = mat; } return(mat); }
// ------------------------------------------------------------------ /// Return shared material matchs given shader and texture // ------------------------------------------------------------------ public static Material GetMaterial(Shader _shader, Texture _texture) { if (_shader == null) { _shader = Shader.Find("ex2D/Alpha Blended"); if (_shader == null) { return null; } } MaterialTableKey key = new MaterialTableKey(_shader, _texture); Material mat; if ( !materialTable.TryGetValue(key, out mat) || mat == null ) { mat = new Material(_shader); mat.hideFlags = HideFlags.DontSave; mat.mainTexture = _texture; materialTable[key] = mat; } return mat; }
// ------------------------------------------------------------------ /// Return shared material matchs given shader and texture for the clipping // ------------------------------------------------------------------ public Material GetClippedMaterial(Shader _shader, Texture _texture) { if (_shader == null) { _shader = Shader.Find("ex2D/Alpha Blended" + shaderPostfix); if (_shader == null) { return null; } } else { Shader clipShader = Shader.Find(_shader.name + shaderPostfix); if (clipShader == null) { Debug.LogError("Failed to find clip shader named " + _shader.name + shaderPostfix); return null; } _shader = clipShader; } MaterialTableKey key = new MaterialTableKey(_shader, _texture); Material mat; if ( !materialTable.TryGetValue(key, out mat) || mat == null ) { mat = new Material(_shader); mat.hideFlags = HideFlags.DontSave; mat.mainTexture = _texture; // also update clip rect Rect rect = GetWorldAABoundingRect (); Vector4 clipRect = new Vector4( rect.center.x, rect.center.y, rect.width, rect.height ); mat.SetVector ( "_ClipRect", clipRect ); materialTable[key] = mat; } return mat; }