当前位置: 首页>>代码示例>>C#>>正文


C# MaterialPropertyBlock.SetTexture方法代码示例

本文整理汇总了C#中UnityEngine.MaterialPropertyBlock.SetTexture方法的典型用法代码示例。如果您正苦于以下问题:C# MaterialPropertyBlock.SetTexture方法的具体用法?C# MaterialPropertyBlock.SetTexture怎么用?C# MaterialPropertyBlock.SetTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.MaterialPropertyBlock的用法示例。


在下文中一共展示了MaterialPropertyBlock.SetTexture方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdatePropertyBlock

 public void UpdatePropertyBlock()
 {
     MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
     render.GetPropertyBlock(propBlock);
     propBlock.SetTexture("_MainTex", maskSprite.texture);
     propBlock.SetTexture("_SprTex", springSprite);
     propBlock.SetTexture("_SumTex", summerSprite);
     propBlock.SetTexture("_AutTex", autumnSprite);
     propBlock.SetTexture("_WinTex", winterSprite);
     render.SetPropertyBlock(propBlock);
 }
开发者ID:kmoverall,项目名称:azimuth-unity,代码行数:11,代码来源:SeasonalSpriteRenderer.cs

示例2: Start

    void Start()
    {
        _rnd = GetComponent<Renderer>();
        _rnd.GetPropertyBlock(_block = new MaterialPropertyBlock());

        _inputs = input.GetPixels();

        _width = input.width;
        _height = input.height;
        _pixelCount = _inputs.Length;
        _texSize = new Vector2(_width, _height);

        output = new Texture2D(_width, _height, TextureFormat.ARGB32, false);
        _outputs = input.GetPixels();
        output.SetPixels(_outputs);
        output.Apply();

        _block.SetTexture(PROP_MAIN_TEX, output);
        _rnd.SetPropertyBlock(_block);
        _mcmc = new MCMC(output, stdDev);

        StartCoroutine (Pinning (0.01f, 200));
    }
开发者ID:nobnak,项目名称:MCMC,代码行数:23,代码来源:TextureModifier.cs

示例3: Start

        void Start()
        {
            if (width <= 0)
                width = Screen.width;
            if (height <= 0)
                height = Screen.height;
            if (depth <= 0f)
                depth = srcCamera.nearClipPlane;

            _capture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
            _capture.antiAliasing = (QualitySettings.antiAliasing == 0 ? 1 : QualitySettings.antiAliasing);
            _capture.filterMode = FilterMode.Bilinear;
            _capture.wrapMode = TextureWrapMode.Clamp;
            _props = new MaterialPropertyBlock();
            _props.SetTexture(PROP_MAIN_TEXTURE, _capture);
            GetComponent<Renderer>().SetPropertyBlock(_props);

            srcCamera.targetTexture = _capture;
            var viewport = srcCamera.rect;
            var size = srcCamera.ViewportToWorldPoint(new Vector3(viewport.width, viewport.height, depth))
                - srcCamera.ViewportToWorldPoint(new Vector3(0f, 0f, depth));
            size.z = 1f;
            transform.localScale = size;
        }
开发者ID:nobnak,项目名称:LayerComposer,代码行数:24,代码来源:Layer.cs

示例4: UpdateCards

        public void UpdateCards()
        {
            if (!Visible)
                foreach (var c in cards)
                    c.transform.parent = transform;

            if (UpdatesDisabled)
                return;

            //print("Updating cards on deck " + (TopCard == null ? "Empty" : TopCard.ToString()));

            var localCardSpacerX = cardSpacerX;
            var localCardSpacerY = cardSpacerY;

            if ((maxCardsSpace > 0) && (cards.Count > maxCardsSpace))
            {
                //override the spacers values to squeeze cards
                localCardSpacerX = (cardSpacerX * maxCardsSpace) / cards.Count;
                localCardSpacerY = (cardSpacerY * maxCardsSpace) / cards.Count;
            }

            //Loop on the Deck Cards (not playing cards)
            var lastTransform = transform;
            for (int i = 0; i < cards.Count; i++)
            {
                //Get the card object
                var card = cards[i];
                //var spriteRenderer = card.GetComponent<SpriteRenderer>();
                //if (spriteRenderer)
                //    spriteRenderer.sprite = card.desc.sprite;
                var meshRenderer = card.GetComponent<MeshRenderer>();
                if (meshRenderer)
                {
                    MaterialPropertyBlock mpb = new MaterialPropertyBlock ();
                    //mpb.SetTexture ("_DetailAlbedoMap", card.desc.texture);
                    mpb.SetTexture ("_MainTex", card.desc.texture);
                    meshRenderer.SetPropertyBlock (mpb);
                }
                card.transform.parent = lastTransform;
                //lastTransform = card.transform;

                var localSortOrder = sortStep*(i+1) + ((selected == card)?cards.Count:0);
                var targetLocalPosition = new Vector3(0, 0, (-localSortOrder) * 0.03f); // z needs to be set for mouse hit detection
                targetLocalPosition += new Vector3(localCardSpacerX, localCardSpacerY) * ((float)i - (centered?1:0) * cards.Count/2.0f);

                var targetLocalScale = Game.Instance.cardPrefab.transform.localScale;
                if (selected == card)
                {
                    targetLocalScale = targetLocalScale * 1.75f;
                    targetLocalPosition -= Vector3.forward * 0.5f;
                }

                targetLocalScale += targetLocalScale * (0.1f * (card.multiplier-1));

#if NGUI
                TweenPosition.Begin(card.gameObject, 0.25f, targetLocalPosition);
                TweenSize.Begin(card.gameObject, 0.25f, targetLocalScale);
#else
                iTween.MoveTo(card.gameObject, iTween.Hash("position", targetLocalPosition, "islocal", true, "time", 0.25f));
                iTween.ScaleTo(card.gameObject, iTween.Hash("scale", targetLocalScale, "islocal", true, "time", 0.25f));
#endif
                card.GetComponent<Collider2D>().enabled = false; // disable the collider until the card is finished moving.

                var sortOrder = order + localSortOrder; // Right decks are on top of left decks when squeezing together
                card.GetComponent<Renderer>().sortingOrder = sortOrder; // sort order needs to be set for visual to render correctly
                StartCoroutine(Delay(() => // schedule this for when the card finishes moving
                {
                    card.GetComponent<Collider2D>().enabled = card.IsDragable;
                }, 0.25f));
            }
        }
开发者ID:rejunity,项目名称:ggj16-coven,代码行数:71,代码来源:Deck.cs

示例5: LateUpdate

        void LateUpdate()
        {
            if (_needsReset) ResetResources();

            // Call the kernels.
            UpdateKernelShader();
            Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
            Graphics.Blit(_positionBuffer, _normalBuffer1, _kernelMaterial, 1);
            Graphics.Blit(_positionBuffer, _normalBuffer2, _kernelMaterial, 2);

            // Update the line material.
            _lineMaterial.SetColor("_Color", _lineColor);

            // Make a material property block for the following drawcalls.
            var props1 = new MaterialPropertyBlock();
            var props2 = new MaterialPropertyBlock();

            props1.SetTexture("_PositionBuffer", _positionBuffer);
            props2.SetTexture("_PositionBuffer", _positionBuffer);

            props1.SetTexture("_NormalBuffer", _normalBuffer1);
            props2.SetTexture("_NormalBuffer", _normalBuffer2);

            var mapOffs = new Vector3(0, 0, VOffset);
            props1.SetVector("_MapOffset", mapOffs);
            props2.SetVector("_MapOffset", mapOffs);

            props1.SetFloat("_UseBuffer", 1);
            props2.SetFloat("_UseBuffer", 1);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            position += transform.forward * ZOffset;

            // Draw mesh segments.
            for (var i = 0; i < _totalStacks; i += _stacksPerSegment)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;

                props1.SetVector("_BufferOffset", uv);
                props2.SetVector("_BufferOffset", uv);

                if (_material)
                {
                    // 1st half
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _material, 0, null, 0, props1,
                        _castShadows, _receiveShadows);

                    // 2nd half
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _material, 0, null, 1, props2,
                        _castShadows, _receiveShadows);
                }

                // lines
                if (_lineColor.a > 0.0f)
                    Graphics.DrawMesh(
                        mesh, position, rotation,
                        _lineMaterial, 0, null, 2,
                        props1, false, false);
            }
        }
开发者ID:suwoonglee,项目名称:KvantTunnel,代码行数:69,代码来源:Tunnel.cs

示例6: Update

        void Update()
        {
            if (_needsReset) ResetResources();

            UpdateKernelShader();

            if (Application.isPlaying)
            {
                // Swap the particle buffers.
                var temp = _positionBuffer1;
                _positionBuffer1 = _positionBuffer2;
                _positionBuffer2 = temp;

                temp = _rotationBuffer1;
                _rotationBuffer1 = _rotationBuffer2;
                _rotationBuffer2 = temp;

                // Call the kernel shader.
                Graphics.Blit(_positionBuffer1, _positionBuffer2, _kernelMaterial, 2);
                Graphics.Blit(_rotationBuffer1, _rotationBuffer2, _kernelMaterial, 3);
            }
            else
            {
                InitializeAndPrewarmBuffers();
            }

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionBuffer", _positionBuffer2);
            props.SetTexture("_RotationBuffer", _rotationBuffer2);
            props.SetFloat("_ScaleMin", _minScale);
            props.SetFloat("_ScaleMax", _maxScale);
            props.SetFloat("_RandomSeed", _randomSeed);

            // Temporary variables
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer2.width, 0);

            // Draw a bulk mesh repeatedly.
            for (var i = 0; i < _positionBuffer2.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer2.height;
                props.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
开发者ID:Zero-Ax,项目名称:Mouse-position-Drag,代码行数:52,代码来源:Spray.cs

示例7: SetProperty

 public LUT3D SetProperty(MaterialPropertyBlock block)
 {
     block.SetFloat (PROP_SCALE, (float)(_dim - 1) / _dim);
     block.SetFloat (PROP_OFFSET, 1f / (2f * _dim));
     block.SetTexture (PROP_3DLUT, _3dlut);
     return this;
 }
开发者ID:nobnak,项目名称:ColorCorrection,代码行数:7,代码来源:LUT3D.cs

示例8: ApplyToBlock

		private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) {
		#if USE_PROPERTY_BLOCKS
			#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2

				block.SetVector(bids.exposureIBL,	exposures);
				block.SetVector(bids.exposureLM,	exposuresLM);
				block.SetMatrix(bids.skyMatrix,		skyMatrix);
				block.SetMatrix(bids.invSkyMatrix,	invMatrix);

				block.SetVector(bids.skyMin, skyMin);
				block.SetVector(bids.skyMax, skyMax);			

				if(specularCube) block.SetTexture(bids.specCubeIBL, specularCube);
				else 			 block.SetTexture(bids.specCubeIBL, blackCube);

				block.SetVector(bids.SH[0],	SH.cBuffer[0]);
				block.SetVector(bids.SH[1],	SH.cBuffer[1]);
				block.SetVector(bids.SH[2],	SH.cBuffer[2]);
				block.SetVector(bids.SH[3],	SH.cBuffer[3]);
				block.SetVector(bids.SH[4],	SH.cBuffer[4]);
				block.SetVector(bids.SH[5],	SH.cBuffer[5]);
				block.SetVector(bids.SH[6],	SH.cBuffer[6]);
				block.SetVector(bids.SH[7],	SH.cBuffer[7]);
				block.SetVector(bids.SH[8], SH.cBuffer[8]);

			#else 

				block.AddVector(bids.exposureIBL,	exposures);
				block.AddVector(bids.exposureLM,	exposuresLM);

				block.AddMatrix(bids.skyMatrix,		skyMatrix);
				block.AddMatrix(bids.invSkyMatrix,	invMatrix);

				block.AddVector(bids.skyMin, skyMin);
				block.AddVector(bids.skyMax, skyMax);			

				if(specularCube) block.AddTexture(bids.specCubeIBL, specularCube);
				else 			 block.AddTexture(bids.specCubeIBL, blackCube);

				block.AddVector(bids.SH[0],	SH.cBuffer[0]);
				block.AddVector(bids.SH[1],	SH.cBuffer[1]);
				block.AddVector(bids.SH[2],	SH.cBuffer[2]);
				block.AddVector(bids.SH[3],	SH.cBuffer[3]);
				block.AddVector(bids.SH[4],	SH.cBuffer[4]);
				block.AddVector(bids.SH[5],	SH.cBuffer[5]);
				block.AddVector(bids.SH[6],	SH.cBuffer[6]);
				block.AddVector(bids.SH[7],	SH.cBuffer[7]);
				block.AddVector(bids.SH[8], SH.cBuffer[8]);

			#endif
		#endif
		}
开发者ID:keyward,项目名称:EnemyOfMyEnemy,代码行数:52,代码来源:Sky.cs

示例9: CreateMesh

    public void CreateMesh()
    {
        if (meshF == null) {
            meshF = GetComponent<MeshFilter>() as MeshFilter;
        }
        if (rend == null) {
            rend = GetComponent<Renderer>() as Renderer;
        }
        if (meshF.sharedMesh) {
            DestroyImmediate(meshF.sharedMesh);
        }
        if (mesh) {
            DestroyImmediate(mesh);
        }

        if (useSprite == null) {
            return;
        }

        MaterialPropertyBlock pBlock = new MaterialPropertyBlock();
        pBlock.SetTexture(0, useSprite.texture);
        rend.SetPropertyBlock(pBlock);

        float ppu = useSprite.pixelsPerUnit;
        float cornerWidth = (float)(slicePixels) / ppu;
        float cornerHeight = (float)(slicePixels) / ppu;

        mesh = new Mesh();

        Vector3[] vertices = new Vector3[16];
        Vector3[] normals = new Vector3[16];
        Vector2[] uvs = new Vector2[16];

        float[] xPValues = new float[4];
        float[] yPValues = new float[4];

        float cornerWidthP = cornerWidth / width;
        float cornerHeightP = cornerHeight / height;

        xPValues[0] = 0.0f;
        yPValues[0] = 0.0f;
        xPValues[1] = cornerWidthP;
        yPValues[1] = cornerHeightP;
        xPValues[2] = 1.0f - cornerWidthP;
        yPValues[2] = 1.0f - cornerHeightP;
        xPValues[3] = 1.0f;
        yPValues[3] = 1.0f;

        for (int x = 0; x < 4; x++) {
            for (int y = 0; y < 4; y++) {
                float xP = xPValues[x];
                float yP = yPValues[y];

                int index = OneDee(x, y);
                vertices[index] = new Vector3(
                    Mathf.Lerp(-1.0f, 1.0f, xP) * width * 0.5f,
                    Mathf.Lerp(-1.0f, 1.0f, yP) * height * 0.5f,
                    0.0f);
                uvs[index] = new Vector2((float)x / 3.0f, (float)y / 3.0f);
                normals[index] = -Vector3.forward;
            }
        }

        int[] tris = new int[9 * 2 * 3];
        int i = 0;
        for (int x = 0; x < 3; x++) {
            for (int y = 0; y < 3; y++) {
                tris[i] = OneDee(x + 1, y);
                i++;
                tris[i] = OneDee(x, y);
                i++;
                tris[i] = OneDee(x + 1, y + 1);
                i++;
                tris[i] = OneDee(x, y);
                i++;
                tris[i] = OneDee(x, y + 1);
                i++;
                tris[i] = OneDee(x + 1, y + 1);
                i++;
            }
        }

        mesh.MarkDynamic();
        mesh.vertices = vertices;
        mesh.uv = uvs;
        mesh.triangles = tris;
        mesh.normals = normals;
        mesh.RecalculateBounds();

        meshF.sharedMesh = mesh;
    }
开发者ID:mandarinx,项目名称:buildahouse,代码行数:91,代码来源:NineSlice.cs

示例10: UpdateMaterial

    void UpdateMaterial()
    {
        if (! initialised) {
            // Parameters changed before Awake() has been run, do a full update when appropriate.
            // (Can't rely on Awake() when the GameObject is disabled. It does a lousy job as a constructor.)
            regenerateMesh = true;
            return;
        }

        if ((renderer.sharedMaterials.Length != 1) || (renderer.sharedMaterials[0] != m_material)) {
            // Update only when necessary to prevent false scene changes.
            renderer.sharedMaterials = new Material[] {m_material};
        }

        MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();
        renderer.GetPropertyBlock(materialProperties);

        if ((m_sprite != null) && (m_sprite.texture != null)) {
            materialProperties.SetTexture("_MainTex", m_sprite.texture);
        }
        else if (m_material != null) {
            if (materialProperties.GetTexture("_MainTex") != null) {
                materialProperties.Clear();
            }
            m_material.SetTexture("_MainTex", null);
        }

        renderer.SetPropertyBlock(materialProperties);
    }
开发者ID:ChubbRck,项目名称:SFB,代码行数:29,代码来源:TiledSpriteRenderer.cs

示例11: Update

        void Update()
        {
            if (_needsReset) ResetResources();

            if (Application.isPlaying)
            {
                UpdateKernelShader();
                SwapBuffersAndInvokeKernels();
            }
            else
            {
                InitializeAndPrewarmBuffers();
            }

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionBuffer", _positionBuffer2);
            props.SetTexture("_RotationBuffer", _rotationBuffer2);
            props.SetFloat("_ScaleMin", _scale * (1 - _scaleRandomness));
            props.SetFloat("_ScaleMax", _scale);
            props.SetFloat("_RandomSeed", _randomSeed);

            // Temporary variables
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer2.width, 0);

            // Draw a bulk mesh repeatedly.
            for (var i = 0; i < _positionBuffer2.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer2.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
开发者ID:dgkae,项目名称:KvantSpray,代码行数:40,代码来源:Spray.cs

示例12: SetTexture

 public override void SetTexture(Texture2D texture)
 {
     base.SetTexture(texture);
     MaterialPropertyBlock props = new MaterialPropertyBlock();
     #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
     props.AddTexture("_MainTex", texture);
     #else
     props.SetTexture("_MainTex", texture);
     #endif
     spriteRenderer.SetPropertyBlock(props);
 }
开发者ID:Ronnie619,项目名称:TouchScreenKiosk,代码行数:11,代码来源:OnlineMapsSpriteRendererControl.cs

示例13: Update

        void Update()
        {
            if (_needsReset) ResetResources();

            // Call the kernels.
            UpdateKernelShader();
            Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
            Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);
            Graphics.Blit(null, _scaleBuffer,    _kernelMaterial, 2);

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionTex", _positionBuffer);
            props.SetTexture("_RotationTex", _rotationBuffer);
            props.SetTexture("_ScaleTex", _scaleBuffer);
            props.SetVector("_ColumnRow", new Vector2(_columns, _rows));
            props.SetVector("_UVOffset", UVOffset);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            position += transform.right * XOffset;
            position += transform.up * YOffset;

            // Draw mesh segments.
            for (var i = 0; i < _positionBuffer.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
开发者ID:Arafo,项目名称:Syncopia,代码行数:39,代码来源:Wall.cs

示例14: Update

        void Update()
        {
            if (_needsReset) ResetResources();

            // Advance the time variables.
            _rotationNoiseTime += _rotationNoiseSpeed * Time.deltaTime;

            // Call the kernels.
            UpdateKernelShader();

            if (_needsReset || _positionUpdateFlag)
                Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);

            Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);

            if (_needsReset || _scaleUpdateFlag)
                Graphics.Blit(null, _scaleBuffer,    _kernelMaterial, 2);

            // Make a material property block for the following drawcalls.
            var props = new MaterialPropertyBlock();
            props.SetTexture("_PositionTex", _positionBuffer);
            props.SetTexture("_RotationTex", _rotationBuffer);
            props.SetTexture("_ScaleTex", _scaleBuffer);

            // Temporary variables.
            var mesh = _bulkMesh.mesh;
            var position = transform.position;
            var rotation = transform.rotation;
            var material = _material ? _material : _defaultMaterial;
            var uv = new Vector2(0.5f / _positionBuffer.width, 0);

            // Draw mesh segments.
            for (var i = 0; i < _positionBuffer.height; i++)
            {
                uv.y = (0.5f + i) / _positionBuffer.height;
                props.SetVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }

            // Clear flag variables.
            _positionUpdateFlag = true;
            _scaleUpdateFlag = true;
            _needsReset = false;
        }
开发者ID:keijiro,项目名称:KvantGrass,代码行数:47,代码来源:Grass.cs


注:本文中的UnityEngine.MaterialPropertyBlock.SetTexture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。