当前位置:网站首页>Unity—ParticleSystem (particle system) and Animator (animation state machine) batch manager
Unity—ParticleSystem (particle system) and Animator (animation state machine) batch manager
2022-08-08 07:03:00 【LCF_CSharp】
Unity - ParticleSystem (particle system) and Animator (animation state machine) batch manager
This script can play multiple particles and animations at the same time when Unity is running, which is convenient for artists and special effects artists to check the special effects and animation details repeatedly.
(Note: This script only does simple loop playback control and single playback control, if you have other needs, you can expand it yourself.)
using UnityEngine;using System.Collections;using UnityEditor;public class ParticleAndAnimation : MonoBehaviour{void Start() {PlayOnce();}[ContextMenu("Play Loop")]public void PlayLoop() {ParticleSystem[] pss = this.GetComponentsInChildren (true);foreach (ParticleSystem ps in pss) {ps.loop = true;ps.Play();}print("Particle system open loop successfully");Animator[] anis = this.GetComponentsInChildren(true);foreach (Animator an in anis){//string animString = an.GetCurrentAnimatorClipInfo(0)[0].clip.name;string animString = an.runtimeAnimatorController.animationClips[0].name;AnimationClip clip = an.runtimeAnimatorController.animationClips[0];// an.GetCurrentAnimatorClipInfo(0)[0].clip;AnimationClipSettings clipsetting = AnimationUtility.GetAnimationClipSettings(clip);clipsetting.loopTime = true;AnimationUtility.SetAnimationClipSettings(clip, clipsetting);an.Play(animString, 0,0f);}print("The animation system opened the loop successfully");}[ContextMenu("Play Once")]public void PlayOnce() {ParticleSystem[] pss = this.GetComponentsInChildren< ParticleSystem> (true);foreach (ParticleSystem ps in pss){ps.loop = false;ps.Play();}Animator[] anis = this.GetComponentsInChildren(true);foreach (Animator an in anis){// string animString = an.GetCurrentAnimatorClipInfo(0)[0].clip.name;string animString = an.runtimeAnimatorController.animationClips[0].name;AnimationClip clip = an.runtimeAnimatorController.animationClips[0];//an.GetCurrentAnimatorClipInfo(0)[0].clip;AnimationClipSettings clipsetting = AnimationUtility.GetAnimationClipSettings(clip);clipsetting.loopTime = false;AnimationUtility.SetAnimationClipSettings(clip, clipsetting);an.Play(animString, 0, 0f);}}}
The following is a visual button generated under the code module for easy operation.
(Note: The script of the button needs to be added, and the name and method name in the creation code need to be consistent in order to be correctly generated and called)
using UnityEngine;using UnityEditor;[CustomEditor(typeof(ParticleAndAnimation))]//Scripts that need to add buttonspublic class AnimatorPlayEditor : Editor {public override void OnInspectorGUI(){DrawDefaultInspector();ParticleAndAnimation myScript = (ParticleAndAnimation)target;//Get the script to add the buttonif (GUILayout.Button("Play once")){myScript.PlayOnce();//Call the method in the add button script}if (GUILayout.Button("Loop")){myScript.PlayLoop();}}}
The completed rendering is as follows
边栏推荐
猜你喜欢
随机推荐
yii2使用多个数据库的使用方法
关于Unity 按键事件响应错误触发UI事件的问题解决
Flutter学习开发资源整理与分享
bp神经网络预测模型原理,神经网络模型怎么预测
【嵌入式Linux】SQLite数据库
RCNN目标检测原文理解
Redis实战篇
Map和Set
Industry Research: Analysis of the Status and Prospects of the Pension Insurance Market in 2022
传统图像特征提取方法:边缘与角点
何恺明2017CVPR大会上演讲PPT,非常适合ResNet学习者!
fpga卷积神经网络加速器,FPGA卷积神经网络综述
【EagleEye】2020-ECCV-EagleEye: Fast Sub-net Evaluation for Efficient Neural Network Pruning-论文详解
MongoDB中的聚合-管道
必知必会的VGG网络(含代码)
Consumer Goods Industry Report: Research Analysis and Development Prospect Forecast of Cosmetic Container Market Status
如何使用conda,pip安装、更新、查看和卸载重装Pytorch?
PyTorch向量变换基本操作
[Unity] GPU动画实现(四)——生成动画数据
ESP32 温湿度和气体传感器驱动