SetFloat() private method

private SetFloat ( int nameID, float value ) : void
nameID int
value float
return void
Esempio n. 1
0
    static int SetFloat(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <int, float>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                int   arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                float arg1 = (float)LuaDLL.lua_tonumber(L, 3);
                obj.SetFloat(arg0, arg1);
                return(0);
            }
            else if (count == 3 && TypeChecker.CheckTypes <string, float>(L, 2))
            {
                UnityEngine.MaterialPropertyBlock obj = (UnityEngine.MaterialPropertyBlock)ToLua.CheckObject(L, 1, typeof(UnityEngine.MaterialPropertyBlock));
                string arg0 = ToLua.ToString(L, 2);
                float  arg1 = (float)LuaDLL.lua_tonumber(L, 3);
                obj.SetFloat(arg0, arg1);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.MaterialPropertyBlock.SetFloat"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 2
0
 static public int SetFloat(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(float)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.SetFloat(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(float)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.SetFloat(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetFloat to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 3
0
    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);
    }
Esempio n. 4
0
 void UpdateOutline(bool outline)
 {
     MaterialPropertyBlock mpb = new MaterialPropertyBlock();
     spriteRenderer.GetPropertyBlock(mpb);
     mpb.SetFloat("_Outline", outline ? 1f : 0);
     mpb.SetColor("_OutlineColor", color);
     spriteRenderer.SetPropertyBlock(mpb);
 }
Esempio n. 5
0
  protected virtual void Awake() {
    _handModel = GetComponent<HandModel>();
    _renderer = GetComponentInChildren<Renderer>();

    _fadePropertyBlock = new MaterialPropertyBlock();
    _renderer.GetPropertyBlock(_fadePropertyBlock);
    _fadePropertyBlock.SetFloat("_Fade", 0);
    _renderer.SetPropertyBlock(_fadePropertyBlock);
  }
Esempio n. 6
0
	// 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);
	}
 /// <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 ) );
     }
 }
Esempio n. 8
0
 static public int SetFloat(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(int), typeof(float)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.SetFloat(a1, a2);
             pushValue(l, true);
             return(1);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(float)))
         {
             UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             self.SetFloat(a1, a2);
             pushValue(l, true);
             return(1);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function SetFloat to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
 static public int SetFloat__Int32__Single(IntPtr l)
 {
     try {
         UnityEngine.MaterialPropertyBlock self = (UnityEngine.MaterialPropertyBlock)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         self.SetFloat(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
    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);
    }
Esempio n. 11
0
 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");
     }
 }
Esempio n. 12
0
    protected void ApplyToRenderers()
    {
        UnityEngine.Debug.Assert(this.exportToLocal);
        if (materialPropertyBlock == null)
        {
            materialPropertyBlock = new UnityEngine.MaterialPropertyBlock();
        }

        int datasLength = this.Datas != null ? this.Datas.Length : 0;

        this.FindRenderers(renderers);
        int renderersCount = renderers.Count;

        for (int i = 0; i < renderersCount; ++i)
        {
            renderers[i].GetPropertyBlock(materialPropertyBlock);
            materialPropertyBlock.SetBuffer(this.BufferName, this.computeBuffer);
            materialPropertyBlock.SetFloat(this.bufferSizeName, datasLength);
            renderers[i].SetPropertyBlock(materialPropertyBlock);
            materialPropertyBlock.Clear();
        }

        renderers.Clear();
    }
        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;
        }
Esempio n. 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 public FogOfWarTile()
 {
     material = new MaterialPropertyBlock();
     material.SetFloat("_Alpha", alpha);
 }
Esempio n. 15
0
    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);
    }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
0
 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;
 }
Esempio n. 19
0
        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
                );
            }
        }
        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);
        }
 public bool AddToMaterialPropertyBlock(UnityEngine.MaterialPropertyBlock materialPropertyBlock)
 {
     materialPropertyBlock.SetFloat(this.PropertyName, this.PropertyValue);
     return(false);
 }
Esempio n. 22
0
    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();
    }
Esempio n. 23
0
    private void UpdateCharacterInput()
    {
        IntVector2 cell = ((IntVector2) next).CellCoords(32);

        regCursor.gameObject.SetActive(true);
        regCursor.transform.localPosition = cell * 32 + IntVector2.one * 16;

        if (addCharacter.isOn)
        {
            cellCursor.gameObject.SetActive(true);

            cellCursor.transform.localPosition = cell * 32 + IntVector2.one * 16;

            cursorBlock = cursorBlock ?? new MaterialPropertyBlock();
            cellCursor.GetPropertyBlock(cursorBlock);

            cursorBlock.SetFloat("_Cycle", Time.timeSinceLevelLoad * 12);
            cellCursor.SetPropertyBlock(cursorBlock);
            cellCursor.sprite = defaultCostume.down.uSprite;
        }
        else
        {
            cellCursor.gameObject.SetActive(false);
        }

        if (input.cancel.WasPressed)
        {
            hud.mode = HUD.Mode.Draw;
            CleanupCharacter();
            return;
        }

        characterDialogue.interactable = possessedActor != null;

        if (possessedActor != null)
        {
            if (characterDialogue.isFocused)
            {
                possessedActor.dialogue = characterDialogue.text;
            }
            else
            {
                characterDialogue.text = possessedActor.dialogue;
            }
        }
        else
        {
            characterDialogue.text = "NO CHARACTER SELECTED";
        }

        Actor hoveredActor;

        var scene = editScene;

        scene.TryGetActor(next, out hoveredActor, 0);

        if (hoveredActor != null)
        {
            if (hoveredActor == possessedActor)
            {
                SetCursorSprite(exitActorCursor);
            }
            else
            {
                SetCursorSprite(enterActorCursor);
            }
        }

        if (mousePress && hoveredActor != null)
        {
            if (removeCharacter.isOn)
            {
                scene.actors.Remove(hoveredActor);

                if (possessedActor == hoveredActor)
                    possessedActor = null;

                var changes = new Changes();
                changes.GetChange(hoveredActor, () => new ActorRemovedChange { world = scene, actor = hoveredActor });
                Do(changes);

                removeCharacter.isOn = false;
            }
            else
            {
                if (possessedActor == hoveredActor)
                {
                    possessedActor = null;
                    cameraController.focusTarget = hoveredActor.position.current - Vector2.one * 16;
                }
                else
                {
                    possessedActor = hoveredActor;
                    characterDialogue.text = possessedActor.dialogue;
                }
            }
        }
        else if (mousePress && addCharacter.isOn)
        {
            var pos = ((IntVector2) next).CellCoords(32) * 32 + IntVector2.one * 16;

            var actor = new Actor
            {
                world = scene,
                costume = NewSimpleCostume(project),
                state = new State { fragment = "start", line = 0 },
                position = new Position
                {
                    prev = pos,
                    next = pos,
                    progress = 0,
                },
            };

            scene.actors.Add(actor);

            var changes = new Changes();
            changes.GetChange(actor, () => new ActorAddedChange { world = scene, actor = actor });
            Do(changes);

            characterPlaceSound.Play();
            addCharacter.isOn = false;
            possessedActor = actor;
        }
    }
    void Update () 
	{
		//must reset mesh verts to 0 each frame.
		m_meshBuffer.SetData(new float[SIZE*7]);

		//Make the voxels.
		m_perlinNoise.SetInt("_Width", N);
		m_perlinNoise.SetInt("_Height", N);
		m_perlinNoise.SetFloat("_Frequency", 0.02f);
		m_perlinNoise.SetFloat("_Lacunarity", 2.0f);
		m_perlinNoise.SetFloat("_Gain", 0.5f);
		m_perlinNoise.SetFloat("_Time", Time.time * m_speed);
		m_perlinNoise.SetTexture(0, "_PermTable1D", perlin.GetPermutationTable1D());
		m_perlinNoise.SetTexture(0, "_PermTable2D", perlin.GetPermutationTable2D());
		m_perlinNoise.SetTexture(0, "_Gradient4D", perlin.GetGradient4D());
		m_perlinNoise.SetBuffer(0, "_Result", m_noiseBuffer);
		
		m_perlinNoise.Dispatch(0, N/8, N/8, N/8);

		//Make the voxel normals.
		m_normals.SetInt("_Width", N);
		m_normals.SetInt("_Height", N);
		m_normals.SetBuffer(0, "_Noise", m_noiseBuffer);
		m_normals.SetBuffer(0, "_Result", m_normalsBuffer);
		
		m_normals.Dispatch(0, N/8, N/8, N/8);

		//Make the mesh verts
		m_marchingCubes.SetInt("_Width", N);
		m_marchingCubes.SetInt("_Height", N);
		m_marchingCubes.SetInt("_Depth", N);
		m_marchingCubes.SetInt("_Border", 1);
		m_marchingCubes.SetFloat("_Target", 0.0f);
		m_marchingCubes.SetBuffer(0, "_Voxels", m_noiseBuffer);
		m_marchingCubes.SetBuffer(0, "_Normals", m_normalsBuffer);
		m_marchingCubes.SetBuffer(0, "_Buffer", m_meshBuffer);
		m_marchingCubes.SetBuffer(0, "_CubeEdgeFlags", m_cubeEdgeFlags);
		m_marchingCubes.SetBuffer(0, "_TriangleConnectionTable", m_triangleConnectionTable);
		
		m_marchingCubes.Dispatch(0, N/8, N/8, N/8);

        m_drawBuffer.SetBuffer("_Buffer", m_meshBuffer);
        m_drawBuffer.SetPass(0);

        var prop = new MaterialPropertyBlock();

        for (var i = 0; i < N; i++)
        {
            prop.SetFloat("_IdOffset", i * N * N * 3 * 5);
            Graphics.DrawMesh(m_mesh, transform.localToWorldMatrix, m_drawBuffer, 0, null, 0, prop);
        }
    }
Esempio n. 25
0
        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);
            }
        }