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


C# MaterialPropertyBlock.SetFloat方法代码示例

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


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

示例1: AssignParams

    public void AssignParams()
    {
        var renderer = GetComponent<Renderer>();
        var trans = GetComponent<Transform>();
        var material = renderer.sharedMaterial;

        if (m_mpb == null)
        {
            m_mpb = new MaterialPropertyBlock();
            m_mpb.SetFloat("_ObjectID", m_id);
        }

        var pos = m_use_root_position ? trans.root.position : trans.position;
        var rot = m_use_root_rotation ? trans.root.rotation : trans.rotation;
        var scale = m_use_root_scale ? trans.root.lossyScale : trans.lossyScale;
        if(m_debug_log)
        {
            Debug.Log("pos: " + pos);
            Debug.Log("rot: " + rot);
            Debug.Log("scale: " + scale);
        }
        m_mpb.SetVector("_Position", pos);
        m_mpb.SetVector("_Rotation", new Vector4(rot.x, rot.y, rot.z, rot.w));
        m_mpb.SetVector("_Scale", scale);
        m_mpb.SetFloat("_LocalTime", m_local_time);
        for (int i = 0; i < m_fparams.Count; ++i)
        {
            m_mpb.SetFloat(m_fparams[i].key, m_fparams[i].value);
        }
        renderer.SetPropertyBlock(m_mpb);
    }
开发者ID:n0mimono,项目名称:Unity5Effects,代码行数:31,代码来源:ShaderParams.cs

示例2: UpdateOutline

 void UpdateOutline(bool outline)
 {
     MaterialPropertyBlock mpb = new MaterialPropertyBlock();
     spriteRenderer.GetPropertyBlock(mpb);
     mpb.SetFloat("_Outline", outline ? 1f : 0);
     mpb.SetColor("_OutlineColor", color);
     spriteRenderer.SetPropertyBlock(mpb);
 }
开发者ID:Magicolo,项目名称:PseudoFramework,代码行数:8,代码来源:SpriteOutline.cs

示例3: Awake

  protected virtual void Awake() {
    _handModel = GetComponent<HandModel>();
    _renderer = GetComponentInChildren<Renderer>();

    _fadePropertyBlock = new MaterialPropertyBlock();
    _renderer.GetPropertyBlock(_fadePropertyBlock);
    _fadePropertyBlock.SetFloat("_Fade", 0);
    _renderer.SetPropertyBlock(_fadePropertyBlock);
  }
开发者ID:CMPUT302-W2016,项目名称:HCI-Gestures,代码行数:9,代码来源:HandFader.cs

示例4: Update

	// Update is called once per frame
	void Update () {
		Debug.Log (Mathf.Abs( Mathf.Cos (Time.time)));
		var material = gameObject.GetComponent<SpriteRenderer> ().material;
		material.SetFloat ("ShineLocation", Mathf.Abs( Mathf.Cos (Time.time)));

		MaterialPropertyBlock pb = new MaterialPropertyBlock ();
		gameObject.GetComponent<SpriteRenderer> ().GetPropertyBlock(pb);
		pb.SetFloat ("ShineLocation", Mathf.Abs (Mathf.Cos (Time.time)));
		gameObject.GetComponent<SpriteRenderer> ().SetPropertyBlock (pb);
	}
开发者ID:Javier-Rotelli,项目名称:exorcismo,代码行数:11,代码来源:glow.cs

示例5: Evaluate

 /// <summary>
 /// Evaluates the property at "t" and stores its value in the MaterialPropertyBlock.
 /// </summary>
 /// <param name="block"></param>
 /// <param name="t"></param>
 public void Evaluate( MaterialPropertyBlock block, float t )
 {
     if( type == Type.Color )
     {
         block.SetColor( Id, Color.Lerp( from, to, t ) );
     }
     else if( type == Type.Float )
     {
         block.SetFloat( Id, Mathf.Lerp( from.a, to.a, t ) );
     }
 }
开发者ID:kazenotenshi,项目名称:GlobalGameJam2016,代码行数:16,代码来源:TweenShader.cs

示例6: SetMaterial

    void SetMaterial()
    {
        if (!sprite)
        {
            Debug.LogError("No sprite set for UI fill", gameObject);
            return;
        }

        MaterialPropertyBlock block = new MaterialPropertyBlock();
        sprite.GetPropertyBlock(block);

        Vector3 scale = new Vector3(clockwise ? -1:1, 1, 1);
        Quaternion rot = Quaternion.Euler(0, 0, rotation + 90f);
        block.SetMatrix("_Rotation", Matrix4x4.TRS(Vector3.zero, rot, scale));
        block.SetFloat("_Fill", fillAmount);
        sprite.SetPropertyBlock(block);
    }
开发者ID:marnel-estrada,项目名称:UnityToolbag,代码行数:17,代码来源:SpriteRadialFill.cs

示例7: InitShaderProperties

 private void InitShaderProperties()
 {
     if (this.isCut)
     {
         MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
         this.renderer.GetPropertyBlock(materialPropertyBlock);
         materialPropertyBlock.SetFloat("_Variation", Mathf.Abs(Mathf.Abs(base.transform.position.x + base.transform.position.z) * 0.1f % 1f - 0.5f) * 2f);
         Quaternion q = Quaternion.AngleAxis(-base.transform.rotation.eulerAngles.y, Vector3.up);
         this.m_Matrix.SetTRS(Vector3.zero, q, new Vector3(1f, 1f, 1f));
         materialPropertyBlock.SetMatrix("_TreeRotMatrix", this.m_Matrix);
         this.renderer.SetPropertyBlock(materialPropertyBlock);
         this.mat.EnableKeyword("_CUTVERSION");
     }
     else
     {
         this.mat.DisableKeyword("_CUTVERSION");
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:18,代码来源:AFSTreeVariation.cs

示例8: Fade

        private IEnumerator Fade()
        {
            if (_isFading) yield break;

            var mr = GetComponent<MeshRenderer>();
            if (mr == null) yield break;

            _isFading = true;

            const float fadeRate = 2f;

            var pb = new MaterialPropertyBlock();

            var val = IsVisible ? 0f : -1f;

            for (; ; ) {
                var dest = IsVisible ? 1f : 0f;
                var sign = Math.Sign(dest - val);
                val += sign * fadeRate * Time.deltaTime;

                if (sign == 0 || sign == 1 && val >= dest || sign == -1 && val <= dest) break;

                pb.SetFloat(FadeId, (float) val);
                mr.SetPropertyBlock(pb);
                yield return new WaitForEndOfFrame();
            }

            mr.SetPropertyBlock(null);

            if (!IsVisible) {
                gameObject.SetActive(false);
            }

            _isFading = false;
        }
开发者ID:katalist5296,项目名称:SanAndreasUnity,代码行数:35,代码来源:StaticGeometry.cs

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

示例10: Update

    void Update()
    {
        if (_subdivided != _subdivision) RebuildMesh();

        var noiseDir = new Vector3(0.1f, 0.3f, -0.5f).normalized;
        _noiseOffset += noiseDir * (Time.deltaTime * _noiseSpeed);

        var radius = 1.0f + Reaktion.Perlin.Noise(Time.time, 23.5f) * _scaleAnimation;

        var props = new MaterialPropertyBlock();
        props.SetVector("_NoiseOffset", _noiseOffset);
        props.SetFloat("_NoiseFrequency", _noiseFrequency);
        props.SetFloat("_NoiseAmplitude", _noiseAmplitude);
        props.SetFloat("_Opacity", _opacity);
        props.SetFloat("_Radius", radius);

        Graphics.DrawMesh(
            _mesh, transform.localToWorldMatrix,
            _material, 0, null, 0, props,
            _shadowCastingMode, _receiveShadows);
    }
开发者ID:keijiro,项目名称:VJ05,代码行数:21,代码来源:SquamataRenderer.cs

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

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

示例13: SetPropertyBlock

        public void SetPropertyBlock(MaterialPropertyBlock block,
                                     Transform modelTransform)
        {
            // model local space to world space matrix
            var l2w = modelTransform.localToWorldMatrix;

            // world space to effector local space matrix
            var w2e = transform.worldToLocalMatrix;

            // effector local space to normalized effector space matrix
            var es = _effectorSize;
            var invs = new Vector3(1.0f / es.x, 1.0f / es.y, 1.0f / es.z);
            var e2n = Matrix4x4.Scale(invs);

            block.SetMatrix("_Effector", e2n * w2e * l2w);

            block.SetVector("_Steepness", new Vector3(
                _transitionSteepness,
                _emissionTransitionSteepness,
                _scaleTransitionSteepness
            ));

            block.SetColor("_InitialEmission", _initialEmission);
            block.SetFloat("_InitialScale", _initialScale);

            if (_effectType == EffectType.Destruction)
                SetDestructionProps(block, modelTransform);
            else
                SetDisintegrationProps(block);
        }
开发者ID:esther5576,项目名称:SW-game-project,代码行数:30,代码来源:ScatterEffector.cs

示例14: Update

        void Update()
        {
            if (_needsReset)
            {
                ResetResources();
                ResetState();
                _needsReset = false;
            }

            if (Application.isPlaying)
            {
                float deltaTime;
                int steps;

                if (_fixTimeStep)
                {
                    // fixed time step
                    deltaTime = 1.0f / _stepsPerSecond;
                    steps = Mathf.RoundToInt(Time.deltaTime * _stepsPerSecond);
                }
                else
                {
                    // variable time step
                    deltaTime = Time.smoothDeltaTime;
                    steps = 1;
                }

                // time steps
                for (var i = 0; i < steps; i++)
                    StepKernel(deltaTime);
            }
            else
            {
                ResetState();

                // warming up
                for (var i = 0; i < 32; i++)
                    StepKernel(0.1f);
            }

            // drawing lines
            UpdateLineShader();

            var matrix = transform.localToWorldMatrix;
            var stride = LinesPerDraw;
            var total = TotalLineCount;

            var props = new MaterialPropertyBlock();
            var uv = new Vector2(0.5f / _historyLength, 0);

            for (var i = 0; i < total; i += stride)
            {
                uv.y = (0.5f + i) / total;
                props.SetVector("_BufferOffset", uv);

                // front face
                props.SetFloat("_Flip", 1);
                Graphics.DrawMesh(
                    _mesh, matrix, _lineMaterial, gameObject.layer,
                    null, 0, props, _castShadows, _receiveShadows
                );

                // back face
                props.SetFloat("_Flip", -1);
                Graphics.DrawMesh(
                    _mesh, matrix, _lineMaterial, gameObject.layer,
                    null, 0, props, _castShadows, _receiveShadows
                );
            }
        }
开发者ID:keijiro,项目名称:KvantSwarm,代码行数:70,代码来源:Swarm.cs

示例15: RefreshBrushCursor

    private void RefreshBrushCursor()
    {
        drawCursorBlock = drawCursorBlock ?? new MaterialPropertyBlock();

        float quarter = Mathf.PI * 0.5f;

        this.angle = (this.angle + Mathf.PI * 2) % (Mathf.PI * 2);

        var angle = this.angle % quarter;
        int rots = Mathf.FloorToInt(this.angle / quarter + 3) % 4;

        //*
        if (angle > quarter * 0.5f)
        {
            angle -= quarter;
            rots = (rots + 1) % 4;
        }
        //*/

        float alpha = -Mathf.Tan(angle / 2f);
        float beta = Mathf.Sin(angle);

        //var shearSprite4 = TextureByte.Pooler.Instance.ShearX(stamp.brush, Time.timeSinceLevelLoad % 1);

        byte value = (byte) drawHUD.selected;
        Blend<byte> blend_ = (canvas, brush) => brush == 0 ? (byte) 0 : value;

        brushRenderer.GetPropertyBlock(drawCursorBlock);

        if (value == 0)
        {
            drawCursorBlock.SetFloat("_Cycle", Time.timeSinceLevelLoad * 16);

            blend_ = (canvas, brush) => brush == 0 ? (byte) 0 : (byte) 1;
        }
        else
        {
            drawCursorBlock.SetFloat("_Cycle", 0);
        }

        brushRenderer.SetPropertyBlock(drawCursorBlock);

        brushSpriteD.Clear(0);

        if (followToggle.isOn)
        {
            var shearSprite1 = TextureByte.Pooler.Instance.Rotated(stamp.brush, rots);
            //var shearSprite1 = TextureByte.Pooler.Instance.Copy(stamp.brush);
            var shearSprite2 = TextureByte.Pooler.Instance.ShearX(shearSprite1, alpha);
            TextureByte.Pooler.Instance.FreeTexture(shearSprite1.mTexture);
            TextureByte.Pooler.Instance.FreeSprite(shearSprite1);
            var shearSprite3 = TextureByte.Pooler.Instance.ShearY(shearSprite2, beta);
            TextureByte.Pooler.Instance.FreeTexture(shearSprite2.mTexture);
            TextureByte.Pooler.Instance.FreeSprite(shearSprite2);
            var shearSprite4 = TextureByte.Pooler.Instance.ShearX(shearSprite3, alpha);
            TextureByte.Pooler.Instance.FreeTexture(shearSprite3.mTexture);
            TextureByte.Pooler.Instance.FreeSprite(shearSprite3);

            ////var shearSprite4 = shearSprite1;

            brushSpriteD.Blend(shearSprite4, blend_);
            TextureByte.Pooler.Instance.FreeTexture(shearSprite4.mTexture);
            TextureByte.Pooler.Instance.FreeSprite(shearSprite4);
        }
        else
        {
            brushSpriteD.Blend(stamp.brush, blend_);
        }

        Actor actor = targetActor;

        if (project == null)
            return;

        var scene = editScene;

        if (actor != null || scene.TryGetActor(next, out actor, 3))
        {
            brushSpriteD.Crop(actor.costume[actor.position.direction],
                              canvasPosition: next,
                              brushPosition: actor.position.current);
        }

        brushSpriteD.mTexture.Apply();
    }
开发者ID:Ragzouken,项目名称:kooltool-rekindle,代码行数:85,代码来源:Main.cs


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