Ejemplo n.º 1
0
        /// <summary>
        /// Can be used to change the material of a prototype at runtime
        /// </summary>
        /// <param name="manager">GPUI Manager</param>
        /// <param name="prototype">GPUI Prototype</param>
        /// <param name="material">New material to set on the renderer</param>
        /// <param name="lodLevel">LOD level</param>
        /// <param name="rendererIndex">Renderer index on the LOD level</param>
        /// <param name="subMeshIndex">Submesh index of the renderer</param>
        public static void ChangeMaterial(GPUInstancerManager manager, GPUInstancerPrototype prototype, Material material, int lodLevel = 0, int rendererIndex = 0, int subMeshIndex = 0)
        {
            GPUInstancerRuntimeData runtimeData = manager.GetRuntimeData(prototype, true);

            if (runtimeData == null)
            {
                return;
            }
            GPUInstancerRenderer gpuiRenderer = runtimeData.instanceLODs[lodLevel].renderers[rendererIndex];

            // Generate proxy GO with a Mesh Renderer to get material property blocks
            GameObject   proxyGameObject = new GameObject("ProxyGO");
            MeshFilter   meshFilter      = proxyGameObject.AddComponent <MeshFilter>();
            MeshRenderer proxyRenderer   = proxyGameObject.AddComponent <MeshRenderer>();

            // Set mesh to proxy GO
            meshFilter.mesh = gpuiRenderer.mesh;
            // Set new material to runtime data
            gpuiRenderer.materials[subMeshIndex] = GPUInstancerConstants.gpuiSettings.shaderBindings.GetInstancedMaterial(material);
            // Set new material to proxy GO
            proxyRenderer.materials[subMeshIndex] = material;
            // Get material property blocks
            proxyRenderer.GetPropertyBlock(gpuiRenderer.mpb);
            if (gpuiRenderer.shadowMPB != null)
            {
                proxyRenderer.GetPropertyBlock(gpuiRenderer.shadowMPB);
            }

            // Destroy proxy GO
            GameObject.Destroy(proxyGameObject);

            // Setup new materials for instancing
            GPUInstancerUtility.SetAppendBuffers(runtimeData);
        }
Ejemplo n.º 2
0
    private void Awake()
    {
        camLayerMask    = unMaskLayer.value;
        cam             = CamMaskUtilities.MainCam;
        hasBackground   = false;
        defaultCamLayer = cam.cullingMask;
        mpb             = new MaterialPropertyBlock();
        maxTexPropId    = Shader.PropertyToID("_MainTex");
        colorPropId     = Shader.PropertyToID("_Color");
        if (top != null)
        {
            top.GetPropertyBlock(mpb);
            mpb.SetColor(colorPropId, Color.clear);
            top.SetPropertyBlock(mpb);
            top.enabled = false;
        }

        if (background != null)
        {
            background.GetPropertyBlock(mpb);
            mpb.SetColor(colorPropId, Color.clear);
            background.SetPropertyBlock(mpb);
            background.enabled = false;
        }

        transform.localPosition = Vector3.zero;
        transform.localRotation = Quaternion.identity;
    }
Ejemplo n.º 3
0
        /// <summary>
        /// This method was introduced as a workaround for too aggressive submesh draw call batching,
        /// leading to incorrect draw order when 3+ materials are used at submeshes in alternating order.
        /// Otherwise, e.g. when using Lightweight Render Pipeline, deliberately separated draw calls
        /// "A1 B A2" are reordered to "A1A2 B", regardless of batching-related project settings.
        /// </summary>
        private void SetMaterialSettingsToFixDrawOrder()
        {
            if (reusedPropertyBlock == null)
            {
                reusedPropertyBlock = new MaterialPropertyBlock();
            }

            bool hasPerRendererBlock = meshRenderer.HasPropertyBlock();

            if (hasPerRendererBlock)
            {
                meshRenderer.GetPropertyBlock(reusedPropertyBlock);
            }

            for (int i = 0; i < meshRenderer.sharedMaterials.Length; ++i)
            {
                if (!meshRenderer.sharedMaterials[i])
                {
                    continue;
                }

                if (!hasPerRendererBlock)
                {
                    meshRenderer.GetPropertyBlock(reusedPropertyBlock, i);
                }
                // Note: this parameter shall not exist at any shader, then Unity will create separate
                // material instances (not in terms of memory cost or leakage).
                reusedPropertyBlock.SetFloat(SUBMESH_DUMMY_PARAM_ID, i);
                meshRenderer.SetPropertyBlock(reusedPropertyBlock, i);

                meshRenderer.sharedMaterials[i].enableInstancing = false;
            }
        }
Ejemplo n.º 4
0
    private void SetSize(float size)
    {
        MaterialPropertyBlock prop = new MaterialPropertyBlock();

        meshRenderer.GetPropertyBlock(prop);
        prop.SetFloat("_Size", size);
        meshRenderer.SetPropertyBlock(prop);
    }
Ejemplo n.º 5
0
    public void SetHighlight(bool highlight)
    {
        MaterialPropertyBlock prop = new MaterialPropertyBlock();

        meshRenderer.GetPropertyBlock(prop);
        prop.SetFloat("_Highlight", highlight ? 1 : 0);
        meshRenderer.SetPropertyBlock(prop);
    }
Ejemplo n.º 6
0
 public void SetMaterial(Material material)
 {
     paintMaterial = material;
     if (material && !IsEraser)
     {
         reticle.GetPropertyBlock(propertyBlock);
         propertyBlock.SetColor("_Color", paintMaterial.color);
         reticle.SetPropertyBlock(propertyBlock);
     }
 }
Ejemplo n.º 7
0
    public void Init()
    {
        transform.rotation = Quaternion.Euler(0, thing.facing, 0);

        float x = thing.posX;
        float z = thing.posY;

        Vector3 origin = new Vector3(x, (float)MapLoader.maxZ / MapLoader.sizeDividor, z);
        //Vector3 target = new Vector3(x, (float)MapLoader.minZ / MapLoader.sizeDividor, z);

        RaycastHit hit;

        if (Physics.Raycast(origin, Vector3.down, out hit))
        {
            transform.position = hit.point;

            SectorController sc = hit.collider.gameObject.GetComponent <SectorController>();
            if (sc != null)
            {
                if (mr != null)
                {
                    mr.GetPropertyBlock(materialProperties);
                    materialProperties.SetFloat("_Brightness", alwaysBright ? 1f : sc.sector.brightness);
                    mr.SetPropertyBlock(materialProperties);
                }

                if (dynamic)
                {
                    sc.DynamicThings.AddFirst(this);
                }
                else
                {
                    sc.StaticThings.Add(this);
                }
            }
        }
        else
        {
            Destroy(gameObject);
        }

        if (!string.IsNullOrEmpty(spriteName))
        {
            Texture tex = TextureLoader.Instance.GetSpriteTexture(spriteName);
            //materialProperties.SetFloat("_ScaleX", (float)tex.width / MapLoader.sizeDividor);
            //materialProperties.SetFloat("_ScaleY", (float)tex.height / MapLoader.sizeDividor);
            Mesh mesh = Mesher.Instance.CreateBillboardMesh((float)tex.width / MapLoader.sizeDividor, (float)tex.height / MapLoader.sizeDividor, .5f, 0);
            GetComponent <MeshFilter>().mesh = mesh;

            SetTexture(tex);
            SetSpriteDirection(1);
        }
    }
Ejemplo n.º 8
0
    private IEnumerator Start()
    {
        // Setting fade plane to black at start
        var block = new MaterialPropertyBlock();

        _fadePlane.GetPropertyBlock(block);
        block.SetColor("_BaseColor", Color.black);
        _fadePlane.SetPropertyBlock(block);

        yield return(new WaitForSeconds(3));

        FadeStartPlane();
    }
Ejemplo n.º 9
0
 // Update is called once per frame
 void Update()
 {
     if (boolDoneOnce1 == false && isUnlocked == true)
     {
         StartCoroutine(Unlocking());
         boolDoneOnce1 = true;
     }
     if (boolDoneOnce2 == false && isPlayed == true)
     {
         HasBeenPlayed();
         boolDoneOnce2 = true;
     }
     if (boolDoneOnce3 == false && isGold == true)
     {
         HasBeenGold();
         boolDoneOnce3 = true;
     }
     if (boolDoneOnce4 == false && isSelected == true)
     {
         meshRenderer.GetPropertyBlock(MatProp);
         MatProp.SetFloat("_Outline", 0.1f);
         meshRenderer.SetPropertyBlock(MatProp);
         boolDoneOnce4 = true;
     }
     if (isLocked == true)
     {
         DebugConstrast();
     }
 }
Ejemplo n.º 10
0
    public virtual void Init()
    {
        materialProperties = new MaterialPropertyBlock();

        cell.x = Mathf.FloorToInt(transform.position.x);
        cell.y = Mathf.FloorToInt(transform.position.z);

        AddToGrid();

        Triangle sectorTriangle = TheGrid.GetExactTriangle(transform.position);

        if (sectorTriangle == null)
        {
            Debug.Log("Thing \"" + thingName + "\" no sector found.");
            Destroy(gameObject);
            return;
        }

        currentSector      = sectorTriangle.sector;
        transform.position = new Vector3(transform.position.x, currentSector.floorHeight, transform.position.z);

        if (mr != null)
        {
            mr.GetPropertyBlock(materialProperties);
            materialProperties.SetFloat("_SectorLight", alwaysBright ? 1f : currentSector.brightness);
            mr.SetPropertyBlock(materialProperties);
        }

        CreateBillboard();

        if (currentSector.Dynamic)
        {
            dynamic = true; //things need to update when on elevators, crushers, etc
        }
        if (!dynamic)
        {
            enabled = false;
        }

        SectorController sc = currentSector.floorObject;

        if (dynamic)
        {
            sc.DynamicThings.AddFirst(this);
        }
        else
        {
            sc.StaticThings.Add(this);
        }
    }
Ejemplo n.º 11
0
        public void ToggleWatermark()
        {
            sR.GetPropertyBlock(sphereBlock);
            var curr = sphereBlock.GetInt("_Watermark");

            if (curr == 1)
            {
                sphereBlock.SetInt("_Watermark", 0);
            }
            else
            {
                sphereBlock.SetInt("_Watermark", 1);
            }
            sR.SetPropertyBlock(sphereBlock);
        }
Ejemplo n.º 12
0
    // меняем цвет тушки
    IEnumerator ChangeBodyColor(MeshRenderer mr, MaterialPropertyBlock MPB, Color color)
    {
        mr.GetPropertyBlock(MPB);
        MPB.SetColor("_Color", Color.red);
        mr.SetPropertyBlock(MPB);

        yield return(new WaitForSeconds(0.2f));

        if (mr != null)
        {
            mr.GetPropertyBlock(MPB);
            MPB.SetColor("_Color", color);
            mr.SetPropertyBlock(MPB);
        }
    }
Ejemplo n.º 13
0
    // меняем цвет тушки
    IEnumerator ChangeBodyColorInRage(MeshRenderer mr, MaterialPropertyBlock MPB, Color colorNew, float duration, Color colorOld)
    {
        mr.GetPropertyBlock(MPB);
        MPB.SetColor("_Color", colorNew);
        mr.SetPropertyBlock(MPB);

        yield return(new WaitForSeconds(duration));

        if (mr != null)
        {
            mr.GetPropertyBlock(MPB);
            MPB.SetColor("_Color", colorOld);
            mr.SetPropertyBlock(MPB);
        }
    }
 public void ReloadSkin()
 {
     if (headPropertyBlock != null)
     {
         HeadRenderer.GetPropertyBlock(headPropertyBlock);
         headPropertyBlock.SetTexture(mainTexShaderId, highlighted ? HighlightTexture : DefaultTexture);
         HeadRenderer.SetPropertyBlock(headPropertyBlock);
     }
     foreach (ArcArcSegmentComponent s in segments)
     {
         s.DefaultTexture   = DefaultTexture;
         s.HighlightTexture = HighlightTexture;
         s.ReloadSkin();
     }
 }
Ejemplo n.º 15
0
    // Update is called once per frame
    void Update()
    {
        if (mat == null || propBlock == null)
        {
            Init();
        }

        if (surfaceTexture == null || nightGlowTexture == null)
        {
            return;
        }

        meshRenderer.GetPropertyBlock(propBlock);

        if (scroll)
        {
            rot += Vector2.right * rotateSpeed;
            propBlock.SetVector("_Offset", rot);
        }

        if (sun != null)
        {
            Vector3 lightDir = (sun.position - transform.position).normalized;
            propBlock.SetVector("_LightDir", lightDir);
        }

        propBlock.SetTexture("_SurfaceTexture", surfaceTexture);
        propBlock.SetTexture("_WaterMask", nightGlowTexture);
        propBlock.SetColor("_Tint", tint);
        propBlock.SetFloat("_Radius", radius * zoom.ZoomLevel);
        propBlock.SetFloat("_ShadowStrength", shadowStrength);
        propBlock.SetColor("_ShadowColor", shadowColor);
        propBlock.SetFloat("_NightGlow", nightGlow);
        meshRenderer.SetPropertyBlock(propBlock);
    }
Ejemplo n.º 16
0
    void Awake()
    {
        for (int i = 0; i < 5; i++)
        {
            sprites[i] = TextureLoader.Instance.GetSpriteTexture(_spriteNames[i]);
        }

        mr = GetComponent <MeshRenderer>();

        if (mr == null)
        {
            Destroy(gameObject);
            return;
        }

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

        Triangle sectorTriangle = TheGrid.GetExactTriangle(transform.position);

        if (sectorTriangle != null)
        {
            materialProperties.SetFloat("_SectorLight", alwaysBright ? 1f : sectorTriangle.sector.brightness);
        }

        CreateBillboard();
    }
Ejemplo n.º 17
0
    public void SwapSwitchTexture(MeshRenderer mr)
    {
        if (mr == null)
        {
            return;
        }

        MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();

        mr.GetPropertyBlock(materialProperties);

        string current = materialProperties.GetTexture("_MainTex").name;

        //some switches are "invisible" in the sense that they are placed in a non-switch texture wall
        if (current.Substring(0, 2) != "SW")
        {
            return;
        }

        if (current[2] == '2')
        {
            current = "SW1" + current.Substring(3);
        }
        else
        {
            current = "SW2" + current.Substring(3);
        }

        materialProperties.SetTexture("_MainTex", GetWallTexture(current));
        mr.SetPropertyBlock(materialProperties);
    }
Ejemplo n.º 18
0
    void LateUpdate()
    {
        Matrix4x4 invTransformMatrix = transform.worldToLocalMatrix;

        // mat.SetMatrix("_InverseTransformMatrix", invTransformMatrix);
        if (props == null)
        {
            props = new MaterialPropertyBlock();
        }
        if (rend == null)
        {
            rend = GetComponent <MeshRenderer>();
        }
        rend.GetPropertyBlock(props);

        props.SetMatrix("_InverseTransformMatrix", invTransformMatrix);
        rend.SetPropertyBlock(props);

        if (ps != null)
        {
            psMain.scalingMode = ParticleSystemScalingMode.Hierarchy;
        }

        if (UseWorldSpaceRotation)
        {
            transform.rotation = Quaternion.Euler(worldRotation);
        }
    }
Ejemplo n.º 19
0
    public void StartScene()
    {
        MPB = new MaterialPropertyBlock();
        mr  = GetComponentInChildren <MeshRenderer>();
        mr.GetPropertyBlock(MPB);
        MPB.SetColor("_Color", bodyColor);
        mr.SetPropertyBlock(MPB);
        Throwpoint = transform.Find("Throwpoint");
        lr         = Throwpoint.GetComponent <LineRenderer>();

        curHealthPoint = maxHealthPoint;

        path = new NavMeshPath();

        timerForVoidZoneReloading = Random.Range(0, voidZoneReloadingTime); // рандомный таймер для войд зоны (чтобы на старте все враги не начинали одновременный каст)
        timerForReloading         = reloadingTime;
        timerForVoidZoneCasting   = voidZoneDuration;

        if (rocketsCountPerShoot == 0)
        {
            rocketsCountPerShoot = 1;
        }

        curAng    = 0;
        targAng   = twisterAngle / 2f;
        rotateDir = 1;
    }
Ejemplo n.º 20
0
    public void Initialize(int gridIndex, int gridX, int gridY, GameManager gameManager)
    {
        this.gameManager = gameManager;
        this.gridIndex   = gridIndex;
        this.gridX       = gridX;
        this.gridY       = gridY;

        transform = base.transform;

        basePosition            = new Vector3(gridX, _baseHeight + _heightVariance * Random.Range(-1f, 1f), gridY);
        transform.localPosition = basePosition;

        float h, s, v;

        Color.RGBToHSV(_baseColor, out h, out s, out v);

        _materialPropertyBlock = new MaterialPropertyBlock();
        _meshRenderer.GetPropertyBlock(_materialPropertyBlock);
        _materialPropertyBlock.SetColor("_Color", Color.HSVToRGB(h, s, v + _colorVariance * Random.Range(-1f, 1f)));
        _meshRenderer.SetPropertyBlock(_materialPropertyBlock);

        name = gridIndex.ToString();

        neighbors = new List <Tile>()
        {
            gameManager.GetTile(gridX - 1, gridY),
            gameManager.GetTile(gridX, gridY + 1),
            gameManager.GetTile(gridX + 1, gridY),
            gameManager.GetTile(gridX, gridY - 1)
        };

        neighbors.RemoveAll(x => x == null);
    }
        void HandleRender(SkeletonRenderer.SmartMesh.Instruction instruction)
        {
            int rendererCount = partsRenderers.Count;

            if (rendererCount <= 0)
            {
                return;
            }

            int rendererIndex = 0;

            if (copyPropertyBlock)
            {
                mainMeshRenderer.GetPropertyBlock(copiedBlock);
            }

            var submeshInstructions      = instruction.submeshInstructions;
            var submeshInstructionsItems = submeshInstructions.Items;
            int lastSubmeshInstruction   = submeshInstructions.Count - 1;

            var  currentRenderer = partsRenderers[rendererIndex];
            bool addNormals      = skeletonRenderer.calculateNormals;
            bool addTangents     = skeletonRenderer.calculateTangents;

            for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++)
            {
                if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction)
                {
                    // Apply properties
                    var meshGenerator = currentRenderer.MeshGenerator;
                    meshGenerator.AddNormals  = addNormals;
                    meshGenerator.AddTangents = addTangents;
                    if (copyPropertyBlock)
                    {
                        currentRenderer.SetPropertyBlock(copiedBlock);
                    }

                    // Render
                    currentRenderer.RenderParts(instruction.submeshInstructions, start, si + 1);

                    start = si + 1;
                    rendererIndex++;
                    if (rendererIndex < rendererCount)
                    {
                        currentRenderer = partsRenderers[rendererIndex];
                    }
                    else
                    {
                        // Not enough renderers. Skip the rest of the instructions.
                        break;
                    }
                }
            }

            // Clear extra renderers if they exist.
            for (; rendererIndex < rendererCount; rendererIndex++)
            {
                partsRenderers[rendererIndex].ClearMesh();
            }
        }
Ejemplo n.º 22
0
 void SetIntensity(float _intensity)
 {
     light.intensity = Mathf.Lerp(0, lightMaxIntensity, _intensity);
     meshRenderer.GetPropertyBlock(materialPropertyBlock, lightMaterialIndex);
     materialPropertyBlock.SetColor("_EmissionColor", Color.Lerp(Color.black, maxMaterialColor, _intensity));
     meshRenderer.SetPropertyBlock(materialPropertyBlock, lightMaterialIndex);
 }
Ejemplo n.º 23
0
    public void OnNewFrame(Astra.ColorizedBodyFrame frame)
    {
        if (frame.Width == 0 ||
            frame.Height == 0)
        {
            return;
        }

        if (_lastFrameIndex == frame.FrameIndex)
        {
            return;
        }

        _lastFrameIndex = frame.FrameIndex;
        EnsureTexture(frame.Width, frame.Height);
        _texture.LoadRawTextureData(frame.DataPtr, (int)frame.ByteLength);
//        .material.SetTexture("_MainTex", _texture);
        MeshRenderer          mr  = GetComponent <MeshRenderer>();
        MaterialPropertyBlock mpb = new MaterialPropertyBlock();

        mr.GetPropertyBlock(mpb);
        mpb.SetFloat("_Outline", true ? 1f : 0);
        mpb.SetColor("_OutlineColor", new Color(0, 0, 0));
        mr.SetPropertyBlock(mpb);

        _texture.Apply();
    }
Ejemplo n.º 24
0
    /// <summary>
    /// The Unity Start() method.
    /// </summary>
    public void Start()
    {
        //lr = FindObjectOfType<LineRenderer>();
        camera = Camera.main.gameObject;

        texture = GameObject.FindGameObjectWithTag("DepthTexture");

        m_MeshRenderer = GetComponent <MeshRenderer>();
        m_Mesh         = GetComponent <MeshFilter>().mesh;
        if (m_Mesh == null)
        {
            m_Mesh = new Mesh();
        }

        m_Mesh.Clear();

        m_CachedColor = PointColor;

        m_ScreenWidthId  = Shader.PropertyToID("_ScreenWidth");
        m_ScreenHeightId = Shader.PropertyToID("_ScreenHeight");
        m_ColorId        = Shader.PropertyToID("_Color");

        m_PropertyBlock = new MaterialPropertyBlock();
        m_MeshRenderer.GetPropertyBlock(m_PropertyBlock);
        m_PropertyBlock.SetColor(m_ColorId, m_CachedColor);
        m_MeshRenderer.SetPropertyBlock(m_PropertyBlock);

        m_CachedPoints = new LinkedList <PointInfo>();
    }
Ejemplo n.º 25
0
 void UpdateVisuals()
 {
     if (mpb != null)
     {
         mr.GetPropertyBlock(mpb);
     }
     else
     {
         mpb = new MaterialPropertyBlock();
     }
     if (sprite != null)
     {
         mpb.SetTexture(mainTex, sprite);
     }
     mpb.SetColor(c, color);
     mpb.SetColor(g, glow);
     //mpb.SetColor (ec, new Color(163f/255f, 0, 0));
     if (elite)
     {
         mpb.SetFloat(e, 1);
     }
     else
     {
         mpb.SetFloat(e, 0);
     }
     mpb.SetFloat(timeOffsetTex, timeOffset);
     mpb.SetFloat(str, strength);
     mr.SetPropertyBlock(mpb);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Calls the rendering of a Portal frame
        /// </summary>
        private void OnWillRenderObject()
        {
            if (!TargetPortal)
            {
                return;
            }
            //Is the mesh renderer in the camera frustrum?
            if (MeshRenderer.isVisible)
            {
                UpdateDopplegangers();
                TargetPortal.UpdateDopplegangers();

#if UNITY_EDITOR
                if (Camera.current.name == "SceneCamera" || Camera.current.name == "Preview Camera")
                {
                    return;
                }
#endif
                TryRenderPortal(Camera.current, _nearClipVertsGlobal);
                if (Camera.current == Camera.main)
                {
                    SKSGlobalRenderSettings.Inverted = SKSGlobalRenderSettings.Inverted;
                    SKSGlobalRenderSettings.UvFlip   = SKSGlobalRenderSettings.UvFlip;
                }
                MeshRenderer.GetPropertyBlock(_seamlessRecursionBlock);
                SeamlessRecursionRenderer.SetPropertyBlock(_seamlessRecursionBlock);
                //}
            }
            UpdateEffects();
        }
Ejemplo n.º 27
0
    private void SetMaterialProperty()
    {
        MeshRenderer renderer = gameObject.GetComponent <MeshRenderer>();

        if (renderer == null)
        {
            return;
        }

        MaterialPropertyBlock matPb = new MaterialPropertyBlock();

        renderer.GetPropertyBlock(matPb);
        matPb.SetVector(ShaderParameters.TerrainLocalPosition, LocalPosition);
        if (UsingChannels.Length == 1)
        {
            matPb.SetVector(ShaderParameters.ChannelsVector4_0, (UsingChannels[0] - Vector4.one));
        }
        else if (UsingChannels.Length == 2)
        {
            matPb.SetVector(ShaderParameters.ChannelsVector4_0, UsingChannels[0] - Vector4.one);
            matPb.SetVector(ShaderParameters.ChannelsVector4_1, UsingChannels[1] - Vector4.one);
        }
        else if (UsingChannels.Length == 3)
        {
            matPb.SetVector(ShaderParameters.ChannelsVector4_0, UsingChannels[0] - Vector4.one);
            matPb.SetVector(ShaderParameters.ChannelsVector4_1, UsingChannels[1] - Vector4.one);
            matPb.SetVector(ShaderParameters.ChannelsVector4_2, UsingChannels[2] - Vector4.one);
        }


        renderer.SetPropertyBlock(matPb);
    }
Ejemplo n.º 28
0
        void LateUpdate()
        {
            int p = planes;

            //if (!Application.isPlaying)p
            if (Application.isPlaying && animate)
            {
                p = Mathf.FloorToInt(Mathf.Lerp(0, planes, animateCurve.Evaluate(Time.time * animateSpeed)));
            }
            UpdateMatrices();

            if (meshRenderer && mesh)
            {
                meshRenderer.GetPropertyBlock(mpr);
                mpr.SetColor("_Color", color);
                for (int i = 0; i < p; i++)
                {
                    Graphics.DrawMesh(mesh, _ms[i], meshRenderer.sharedMaterial, gameObject.layer, null, 0, mpr, shadowCastingMode, receiveShadows);
                }
            }



            //Graphics.DrawMeshInstanced(mesh, 0, meshRenderer.sharedMaterial, _ms, mpr, shadowCastingMode, receiveShadows);
        }
Ejemplo n.º 29
0
 void UpdatePropBlock()
 {
     if (_meshRenderer)
     {
         if (_curPropBlock == null)
         {
             _curPropBlock = new MaterialPropertyBlock();
         }
         _meshRenderer.GetPropertyBlock(_curPropBlock);
         _curPropBlock.SetColor("_Tint", tint);
         var sprite = clip ? clip.Sprite : null;
         var atlas  = sprite && sprite.texture ? sprite.texture : Texture2D.whiteTexture;
         var atlasA = sprite ? sprite.associatedAlphaSplitTexture : null;
         _curPropBlock.SetTexture(
             "_MainTex",
             atlas ? atlas : Texture2D.whiteTexture);
         if (atlasA)
         {
             _curPropBlock.SetTexture("_AlphaTex", atlasA);
             _curPropBlock.SetFloat("_ExternalAlpha", 1.0f);
         }
         else
         {
             _curPropBlock.SetTexture("_AlphaTex", Texture2D.whiteTexture);
             _curPropBlock.SetFloat("_ExternalAlpha", 0.0f);
         }
         _meshRenderer.SetPropertyBlock(_curPropBlock);
     }
 }
 void Start()
 {
     currentFallOffTime = fallOffTime;
     lastDamageTime     = Mathf.NegativeInfinity;
     mpb = new MaterialPropertyBlock();
     mr.GetPropertyBlock(mpb);
 }