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


C# MaterialPropertyBlock.AddTexture方法代码示例

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


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

示例1: SwapColors_Custom

    public void SwapColors_Custom(ColorPalette palette)
    {
        Texture2D t = spriteRenderer.sprite.texture;

        if (palette.cachedTexture == null)
        {
            var w = t.width;
            var h = t.height;

            var cloneTexture = new Texture2D(w, h);
            cloneTexture.wrapMode = TextureWrapMode.Clamp;
            cloneTexture.filterMode = FilterMode.Point;

            var colors = t.GetPixels();

            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = palette.GetColor(colors[i]);
            }

            cloneTexture.SetPixels(colors);
            cloneTexture.Apply();

            palette.cachedTexture = cloneTexture;
        }

        block = new MaterialPropertyBlock();
        block.AddTexture("_MainTex", palette.cachedTexture);
    }
开发者ID:Mrbransky,项目名称:Kissy_Ghost,代码行数:29,代码来源:PaletteSwapper.cs

示例2: Start

 // Use this for initialization
 void Start()
 {
     MaterialPropertyBlock bloc = new MaterialPropertyBlock();
     Renderer rend = gameObject.GetComponent<Renderer> ();
     rend.material = SpriteLightMaterial;
     rend.GetPropertyBlock (bloc);
     bloc.AddTexture ("_LightTex",Light.texture);
     rend.SetPropertyBlock (bloc);
 }
开发者ID:hydro-team,项目名称:hydro,代码行数:10,代码来源:LightReactiveSprite.cs

示例3: Awake

	void Awake()
	{
		mb = new MaterialPropertyBlock();
		mb.AddTexture("_MainTex",texture);

		foreach (Transform child in transform)
		{	defaultColor = child.renderer.material.color;


			Color newColor = defaultColor;
			//newColor.a = (1-child.localPosition.y*8)/2f;
			mb.AddColor("_Color",newColor);
			mb.AddColor("_TintColor",newColor);

			child.renderer.SetPropertyBlock(mb);
			child.renderer.material.SetTexture("_MainTex", texture);
		}
	}
开发者ID:marcteys,项目名称:trauts,代码行数:18,代码来源:SetHologramColor.cs

示例4: Start

    // Use this for initialization
    void Start()
    {
        texture = spriteRenderer.sprite.texture;

        var w = texture.width;
        var h = texture.height;

        cloneTexture = new Texture2D (w, h);
        cloneTexture.wrapMode = TextureWrapMode.Clamp;
        cloneTexture.filterMode = FilterMode.Point;

        Color[] pixels = texture.GetPixels ();

        cloneTexture.SetPixels (pixels);
        cloneTexture.Apply ();

        block = new MaterialPropertyBlock ();
        block.AddTexture ("_MainTex", cloneTexture);

        SwapColors ();
    }
开发者ID:nguyenqphan,项目名称:SpritePaletteSwapping,代码行数:22,代码来源:PaletteSwapper.cs

示例5: DestroyPlanetChunk

        void DestroyPlanetChunk()
        {
            //Make instance of texture
            Texture2D texInstance = MonoBehaviour.Instantiate<Texture2D> (spriteRend.sprite.texture);

            //Set pixels to transparent
            Color[] pixels = texInstance.GetPixels ();

            for (int y = 0; y<pixels.Length; y++) {
                if(y<10000){
                    pixels[y] = new Color(0,0,0,0);

                }
            }

            //Apply pixels to tex instance
            texInstance.SetPixels (pixels);
            texInstance.Apply ();

            //Apply texture to sprite
            MaterialPropertyBlock block = new MaterialPropertyBlock ();
            block.AddTexture ("_MainTex", texInstance);
            spriteRend.SetPropertyBlock(block);
        }
开发者ID:dialcforchris,项目名称:InterstellarmadillosGame,代码行数:24,代码来源:GravityBody.cs

示例6: ApplyToBlock

		private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) {
			#if USE_PROPERTY_BLOCKS
			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
		}
开发者ID:elephantatwork,项目名称:Secret-Game,代码行数:26,代码来源:Sky.cs

示例7: 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.AddTexture("_PositionTex", _positionBuffer);
            props.AddTexture("_RotationTex", _rotationBuffer);
            props.AddTexture("_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.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }
        }
开发者ID:Nabetse990,项目名称:KvantWall,代码行数:39,代码来源:Wall.cs

示例8: 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

示例9: SetTexture

 public override void SetTexture(Texture2D texture)
 {
     base.SetTexture(texture);
     MaterialPropertyBlock props = new MaterialPropertyBlock();
     props.AddTexture("_MainTex", texture);
     spriteRenderer.SetPropertyBlock(props);
 }
开发者ID:JorgenNyborg,项目名称:Fishualizer,代码行数:7,代码来源:OnlineMapsSpriteRendererControl.cs

示例10: 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.AddTexture("_PositionTex", _positionBuffer);
            props.AddTexture("_RotationTex", _rotationBuffer);
            props.AddTexture("_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.AddVector("_BufferOffset", uv);
                Graphics.DrawMesh(
                    mesh, position, rotation,
                    material, 0, null, 0, props,
                    _castShadows, _receiveShadows);
            }

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

示例11: OnTriggerEnter2D

    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag ("SphinxLeftHole")) {

            leftHoleActivated=!leftHoleActivated;

            if (rightHoleActivated && leftHoleActivated) {
                counter++;
                rightHoleActivated = false;
                leftHoleActivated = false;
                rightHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
                leftHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
            }

            if(leftHoleActivated==true){
                leftHoleTrigger.GetComponent<SpriteRenderer>().enabled=true;
            } else if (leftHoleActivated==false){
                leftHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
            }

            switch(counter) {
            case 1:
                MaterialPropertyBlock block1 = new MaterialPropertyBlock();
                block1.AddTexture("_BLUE",blue);
                upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(block1);
                break;

            case 2:
                MaterialPropertyBlock block2 = new MaterialPropertyBlock();
                block2.AddTexture("_RED",red);
                upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(block2);
                break;
                //case 3: upgradeDisplay.GetComponent<SpriteRenderer>().sprite.texture=green; break;
                //case 4: upgradeDisplay.GetComponent<SpriteRenderer>().sprite.texture=yellow; break;
            default:
                MaterialPropertyBlock blockDef = new MaterialPropertyBlock();
                blockDef.AddTexture("_YELLOW",yellow);
                upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(blockDef);
                break;
            }

        }

        if (collision.CompareTag ("SphinxRightHole")) {

            rightHoleActivated=!rightHoleActivated;

            if (rightHoleActivated && leftHoleActivated) {
                counter++;
                rightHoleActivated = false;
                leftHoleActivated = false;
                rightHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
                leftHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
            }

            if(rightHoleActivated==true){
                rightHoleTrigger.GetComponent<SpriteRenderer>().enabled=true;
            } else if (rightHoleActivated==false){
                rightHoleTrigger.GetComponent<SpriteRenderer>().enabled=false;
            }

                //MaterialPropertyBlock block = new MaterialPropertyBlock();
                //block.AddTexture("_BLUE",blue);
                //upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(block);

                switch(counter) {
                case 1:
                    MaterialPropertyBlock block1 = new MaterialPropertyBlock();
                    block1.AddTexture("_BLUE",blue);
                    upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(block1);
                    break;

                case 2:
                    MaterialPropertyBlock block2 = new MaterialPropertyBlock();
                    block2.AddTexture("_RED",red);
                    upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(block2);
                    break;
                //case 3: upgradeDisplay.GetComponent<SpriteRenderer>().sprite.texture=green; break;
                //case 4: upgradeDisplay.GetComponent<SpriteRenderer>().sprite.texture=yellow; break;
                default:
                    MaterialPropertyBlock blockDef = new MaterialPropertyBlock();
                    blockDef.AddTexture("_YELLOW",yellow);
                    upgradeDisplay.GetComponent<SpriteRenderer>().SetPropertyBlock(blockDef);
                    break;
                }
            }
    }
开发者ID:OmathiasO,项目名称:flipper,代码行数:87,代码来源:FHSphinxUpgradeBehavior.cs


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