Exemplo n.º 1
0
    /// <summary>
    /// 绘制一个幻影
    /// </summary>
    /// <param name="propertyBlock"></param>
    /// <param name="afterimageData"></param>
    private void DrawAfterimageItem(MaterialPropertyBlock propertyBlock, AfterimageData afterimageData)
    {
        for (int i = 0; i < afterimageData.AM4x4List.Count; i++)
        {
            AfterimageMatrix4x4 item = afterimageData.AM4x4List[i];

            //设置贴图
            propertyBlock.SetTexture(idMainTex, item.sprite.texture);
            //获得网格
            var mesh = SpriteToMesh(item.sprite);


            buffer.DrawMesh(mesh, Matrix4x4.TRS(item.position, item.rotation, item.localScale), item.material, 0, 0, propertyBlock);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 绘制所有幻影
    /// </summary>
    /// <param name="afterimageDatas"></param>
    private void DrawAfterimage(List <AfterimageData> afterimageDatas)
    {
        buffer = new CommandBuffer();
        var propertyBlock = new MaterialPropertyBlock();


        for (int i = 0; i < afterimageDatas.Count; i++)
        {
            AfterimageData item = afterimageDatas[i];

            //绘制一张幻影
            //设置颜色
            propertyBlock.SetColor(idColor, item.color);
            //设置绘制数据
            DrawAfterimageItem(propertyBlock, item);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// 幻影数据刷新
    /// </summary>
    private void DataUptate()
    {
        if ((transform.position - lastPosition).magnitude < spacing)
        {
            return;
        }



        lastPosition = transform.position;


        AfterimageData afterimageData = new AfterimageData();

        //设置时间
        afterimageData.live = live;

        afterimageData.color = color;

        //遍历所有精灵创建一个幻影
        for (int i = 0; i < spriteList.Count; i++)
        {
            var item = spriteList[i];
            //获得当前精灵的信息
            AfterimageMatrix4x4 afterimageMatrix4X4 = new AfterimageMatrix4x4(
                item.transform.position,
                item.transform.rotation,
                item.transform.lossyScale,
                item.sprite,
                item.material);
            //添加当前精灵到幻影中
            afterimageData.AM4x4List.Add(afterimageMatrix4X4);
        }
        //将新的幻影添加到数据中
        AfterimageDataList.Add(afterimageData);
    }