unity特效ParticleSystem在UI上缩放(自适应屏幕)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了unity特效ParticleSystem在UI上缩放(自适应屏幕),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1723字,纯文字阅读大概需要3分钟。
内容图文
![unity特效ParticleSystem在UI上缩放(自适应屏幕)](/upload/InfoBanner/zyjiaocheng/1089/2d486b73bd2542f5b7472231b96268b7.jpg)
结合了下面这两个方案:
http://www.xuanyusong.com/archives/4271
http://www.unity.5helpyou.com/3630.html
第一个方案,应付不了复杂些的特效;
两篇文章结合后的代码如下:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class ScaleParticles : MonoBehaviour { private List<float> m_initialSizes = new List<float>(); publicvoid CacheParticleScale() { // Save off all the initial scale values at start. ParticleSystem[] particles = gameObject.GetComponentsInChildren<ParticleSystem>(); for (int i=0;i<particles.Length;i++) { m_initialSizes.Add(particles[i].startSize); ParticleSystemRenderer renderer = particles[i].GetComponent<ParticleSystemRenderer>(); if (renderer) { m_initialSizes.Add(renderer.lengthScale); m_initialSizes.Add(renderer.velocityScale); } } } publicvoid ResetParticleScale() { float designWidth = 1920;//开发时分辨率宽float designHeight = 1080;//开发时分辨率高float designScale = designWidth / designHeight; float scaleRate = (float)Screen.width / (float)Screen.height; float scaleFactor = scaleRate / designScale; // Scale all the particle components based on parent.int arrayIndex = 0; ParticleSystem[] particles = gameObject.GetComponentsInChildren<ParticleSystem>(); for (int i = 0; i < particles.Length; i++) { float rate = 1; if (scaleRate < designScale) { rate = scaleFactor; } else { rate = 1; } particles[i].startSize = m_initialSizes[arrayIndex++] * rate; ParticleSystemRenderer renderer = particles[i].GetComponent<ParticleSystemRenderer>(); if (renderer) { renderer.lengthScale = m_initialSizes[arrayIndex++] * rate; renderer.velocityScale = m_initialSizes[arrayIndex++] * rate; } } } }
原文:http://www.cnblogs.com/kuluodisi/p/7341079.html
内容总结
以上是互联网集市为您收集整理的unity特效ParticleSystem在UI上缩放(自适应屏幕)全部内容,希望文章能够帮你解决unity特效ParticleSystem在UI上缩放(自适应屏幕)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。