GetShader() public static method

public static GetShader ( string name ) : Shader
name string
return UnityEngine.Shader
示例#1
0
        /// <summary>
        ///
        /// </summary>
        public MaterialManager GetMaterialManager(string shaderName, string[] keywords)
        {
            if (_root != this)
            {
                return(_root.GetMaterialManager(shaderName, keywords));
            }

            if (_materialManagers == null)
            {
                _materialManagers = new Dictionary <string, MaterialManager>();
            }

            string key = shaderName;

            if (keywords != null)
            {
                //对于带指定关键字的,目前的设计是不参加共享材质了,因为逻辑会变得更复杂
                key = shaderName + "_" + _gCounter++;
            }

            MaterialManager mm;

            if (!_materialManagers.TryGetValue(key, out mm))
            {
                mm             = new MaterialManager(this, ShaderConfig.GetShader(shaderName), keywords);
                mm._managerKey = key;
                _materialManagers.Add(key, mm);
            }

            return(mm);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        public MaterialManager GetMaterialManager(string shaderName)
        {
            if (_root != this)
            {
                if (_root == null)
                {
                    return(null);
                }
                else
                {
                    return(_root.GetMaterialManager(shaderName));
                }
            }

            if (_materialManagers == null)
            {
                _materialManagers = new Dictionary <string, MaterialManager>();
            }

            MaterialManager mm;

            if (!_materialManagers.TryGetValue(shaderName, out mm))
            {
                mm = new MaterialManager(this, ShaderConfig.GetShader(shaderName));
                _materialManagers.Add(shaderName, mm);
            }

            return(mm);
        }
示例#3
0
        /// <summary>
        /// 进入绘画模式,整个对象将画到一张RenderTexture上,然后这种贴图将代替原有的显示内容。
        /// 可以在onPaint回调里对这张纹理进行进一步操作,实现特殊效果。
        /// 可能有多个地方要求进入绘画模式,这里用requestorId加以区别,取值是1、2、4、8、16以此类推。1024内内部保留。用户自定义的id从1024开始。
        /// </summary>
        /// <param name="requestId">请求者id</param>
        /// <param name="margin">纹理四周的留空。如果特殊处理后的内容大于原内容,那么这里的设置可以使纹理扩大。</param>
        public void EnterPaintingMode(int requestorId, Margin?margin)
        {
            bool first = _paintingMode == 0;

            _paintingMode |= requestorId;
            if (first)
            {
                if (paintingGraphics == null)
                {
                    if (graphics == null)
                    {
                        paintingGraphics = new NGraphics(this.gameObject);
                    }
                    else
                    {
                        GameObject go = new GameObject(this.gameObject.name + " (Painter)");
                        go.layer = this.gameObject.layer;
                        ToolSet.SetParent(go.transform, cachedTransform);
                        go.hideFlags     = DisplayOptions.hideFlags;
                        paintingGraphics = new NGraphics(go);
                    }
                }
                else
                {
                    paintingGraphics.enabled = true;
                }
                paintingGraphics.vertexMatrix = null;

                if (_paintingMaterial == null)
                {
                    _paintingMaterial           = new Material(ShaderConfig.GetShader(ShaderConfig.imageShader));
                    _paintingMaterial.hideFlags = DisplayOptions.hideFlags;
                }
                paintingGraphics.material = _paintingMaterial;

                if (this is Container)
                {
                    ((Container)this).SetChildrenLayer(CaptureCamera.hiddenLayer);
                    ((Container)this).UpdateBatchingFlags();
                }
                else
                {
                    this.InvalidateBatchingState();
                }

                if (graphics != null)
                {
                    this.gameObject.layer = CaptureCamera.hiddenLayer;
                }

                _paintingMargin = new Margin();
            }
            if (margin != null)
            {
                _paintingMargin = (Margin)margin;
            }
            _paintingFlag = 1;
        }
示例#4
0
        public NMaterial CreateMaterial()
        {
            NMaterial mat = new NMaterial(ShaderConfig.GetShader(shaderName));

            mat.mainTexture = texture.nativeTexture;
            if (texture.alphaTexture != null)
            {
                mat.EnableKeyword("COMBINED");
                mat.SetTexture("_AlphaTex", texture.alphaTexture);
            }
            if (_keywords != null)
            {
                foreach (string v in _keywords)
                {
                    mat.EnableKeyword(v);
                }
            }
            mat.hideFlags = DisplayOptions.hideFlags;

            return(mat);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public NMaterial CreateMaterial()
        {
            NMaterial nm = new NMaterial(ShaderConfig.GetShader(shaderName));

            nm.material.mainTexture = texture.nativeTexture;
            if (texture.alphaTexture != null)
            {
                nm.combined = true;
                nm.material.EnableKeyword("COMBINED");
                nm.material.SetTexture("_AlphaTex", texture.alphaTexture.nativeTexture);
            }
            if (_keywords != null)
            {
                foreach (string v in _keywords)
                {
                    nm.material.EnableKeyword(v);
                }
            }
            nm.material.hideFlags = DisplayOptions.hideFlags;

            return(nm);
        }
示例#6
0
        virtual public void Update(UpdateContext context)
        {
            if (graphics != null)
            {
                graphics.alpha  = context.alpha * _alpha;
                graphics.grayed = context.grayed | _grayed;
                graphics.UpdateMaterial(context);
            }

            if (_paintingMode != 0)
            {
                NTexture paintingTexture = paintingGraphics.texture;
                if (paintingTexture != null && paintingTexture.disposed)                 //Texture可能已被Stage.MonitorTexture销毁
                {
                    paintingTexture = null;
                    _paintingFlag   = 1;
                }
                if (_paintingFlag == 1)
                {
                    _paintingFlag = 0;

                    //从优化考虑,决定使用绘画模式的容器都需要明确指定大小,而不是自动计算包围。这在UI使用上并没有问题,因为组件总是有固定大小的
                    int textureWidth  = Mathf.RoundToInt(_contentRect.width + _paintingMargin.left + _paintingMargin.right);
                    int textureHeight = Mathf.RoundToInt(_contentRect.height + _paintingMargin.top + _paintingMargin.bottom);
                    if (paintingTexture == null || paintingTexture.width != textureWidth || paintingTexture.height != textureHeight)
                    {
                        if (paintingTexture != null)
                        {
                            paintingTexture.Dispose(true);
                        }
                        if (textureWidth > 0 && textureHeight > 0)
                        {
                            paintingTexture = new NTexture(CaptureCamera.CreateRenderTexture(textureWidth, textureHeight, false));
                            Stage.inst.MonitorTexture(paintingTexture);
                        }
                        else
                        {
                            paintingTexture = null;
                        }
                        paintingGraphics.texture = paintingTexture;
                    }

                    if (paintingGraphics.material == null)
                    {
                        paintingGraphics.material           = new Material(ShaderConfig.GetShader(ShaderConfig.imageShader));
                        paintingGraphics.material.hideFlags = DisplayOptions.hideFlags;
                    }

                    if (paintingTexture != null)
                    {
                        paintingGraphics.SetOneQuadMesh(
                            new Rect(-_paintingMargin.left, -_paintingMargin.top, paintingTexture.width, paintingTexture.height),
                            new Rect(0, 0, 1, 1), Color.white);
                    }
                    else
                    {
                        paintingGraphics.ClearMesh();
                    }
                }

                if (paintingTexture != null)
                {
                    paintingTexture.lastActive = Time.time;

                    if (!(this is Container) &&                  //如果是容器,这句移到Container.Update的最后执行,因为容器中可能也有需要Capture的内容,要等他们完成后再进行容器的Capture。
                        (_paintingFlag != 2 || !_cacheAsBitmap))
                    {
                        UpdateContext.OnEnd += _captureDelegate;
                    }
                }

                paintingGraphics.UpdateMaterial(context);
            }

            if (_filter != null)
            {
                _filter.Update();
            }

            Stats.ObjectCount++;
        }