Unity5中的粒子缩放(附测试源码)

本文章由cartzhang编写,转载请注明出处。 所有权利保留。 

文章链接:http://blog.csdn.net/cartzhang/article/details/49363241

作者:cartzhang



开始:

关于Unity 5 中的例子缩放,搜索了半天竟然还有人说:

As far as I know that is not possible to do from code. 


然后到官方找来了插件

https://www.assetstore.unity3d.com/cn/#!/content/4400

Particle Scaler

这货居然还需要10刀。我表示很不满啊!


BTW: 官方下载10美刀的居然只能在编辑器中使用,在运行中然并卵的节奏还是让人疼啊!

---------

方法:

然后功夫不负有心人!!!找到了解决方案。

之前代码上有个public void UpdateScale() 

我不了解是不是之前的版本的函数。反正是现在没戏了。


做了简单修改,然后就大功告成了。

还是代码啊!

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ScaleParticles : MonoBehaviour
{
    // @zpj default scale size;
    public float ScaleSize = 1.0f;
    private List<float> initialSizes = new List<float>();

    void Awake()
    {
        // Save off all the initial scale values at start.
        ParticleSystem[] particles = gameObject.GetComponentsInChildren<ParticleSystem>();
        foreach (ParticleSystem particle in particles)
        {
            initialSizes.Add(particle.startSize);
            ParticleSystemRenderer renderer = particle.GetComponent<ParticleSystemRenderer>();
            if (renderer)
            {
                initialSizes.Add(renderer.lengthScale);
                initialSizes.Add(renderer.velocityScale);
            }
        }
    }

    void Start()
    {
        gameObject.transform.localScale = new Vector3(ScaleSize, ScaleSize, ScaleSize);
        // Scale all the particle components based on parent.
        int arrayIndex = 0;
        ParticleSystem[] particles = gameObject.GetComponentsInChildren<ParticleSystem>();
        foreach (ParticleSystem particle in particles)
        {
            particle.startSize = initialSizes[arrayIndex++] * gameObject.transform.localScale.magnitude;
            ParticleSystemRenderer renderer = particle.GetComponent<ParticleSystemRenderer>();
            if (renderer)
            {
                renderer.lengthScale = initialSizes[arrayIndex++] *
                    gameObject.transform.localScale.magnitude;
                renderer.velocityScale = initialSizes[arrayIndex++] *
                    gameObject.transform.localScale.magnitude;
            }
        }
    }

}


使用:

建立一个空对象,把上面的名字为ScaleParticles.cs的拖拽到空对象上。把你需要的粒子效果作为一个子对象挂载到空对象上。

如下所示;



修改检视板中的scale size 大小,来修改粒子大小。


是不是很简单实用呢。


源码呢:

免分下载地址如下:

源码地址:http://download.csdn.net/detail/cartzhang/9207203


-------------------------------------



就是这样。

若有问题,请随时联系!
非常感谢!!!




转载于:https://www.cnblogs.com/qitian1/p/6461942.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值