Unity的AssetPostprocessor之Model之动画:深入解析与实用案例 3
Unity AssetPostprocessor的Model的动画相关的函数修改实际应用
在Unity中,AssetPostprocessor是一个非常有用的工具,它可以在导入资源时自动执行一些操作。其中,Model的动画相关的函数修改可以帮助我们在导入模型时自动修改动画相关的函数,从而提高我们的工作效率。本文将介绍如何使用AssetPostprocessor的Model的动画相关的函数修改,并提供多个使用例子。
什么是AssetPostprocessor
AssetPostprocessor是Unity中的一个类,它可以在导入资源时自动执行一些操作。我们可以通过继承AssetPostprocessor并重写其中的方法来实现自己的需求。其中,Model的动画相关的函数修改是AssetPostprocessor中的一个功能,它可以帮助我们在导入模型时自动修改动画相关的函数。
Model的动画相关的函数修改
在Unity中,我们可以通过Animator组件来控制模型的动画。Animator组件中包含了一些动画相关的函数,例如SetBool、SetFloat、SetInteger等。这些函数可以帮助我们控制动画的播放。在导入模型时,我们可以通过AssetPostprocessor的Model的动画相关的函数修改来自动修改这些函数。
修改SetBool函数
我们可以通过修改SetBool函数来控制动画的播放。例如,我们可以在导入模型时自动将所有的SetBool函数中的参数名“isRunning”改为“isWalking”,从而控制动画的播放。具体实现如下:
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Bool)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetBool" && e.stringParameter == "isRunning")
{
e.stringParameter = "isWalking";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
修改SetFloat函数
我们也可以通过修改SetFloat函数来控制动画的播放。例如,我们可以在导入模型时自动将所有的SetFloat函数中的参数名“speed”改为“velocity”,从而控制动画的播放。具体实现如下:
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Float)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetFloat" && e.stringParameter == "speed")
{
e.stringParameter = "velocity";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
修改SetInteger函数
我们还可以通过修改SetInteger函数来控制动画的播放。例如,我们可以在导入模型时自动将所有的SetInteger函数中的参数名“state”改为“status”,从而控制动画的播放。具体实现如下
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Int)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetInteger" && e.stringParameter == "state")
{
e.stringParameter = "status";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
使用例子
下面是几个使用AssetPostprocessor的Model的动画相关的函数修改的例子。
例子1:修改SetBool函数
我们可以在导入模型时自将所有的SetBool函数中的参数名“isRunning”改为“isWalking”,从而控制动画的播放。具体实现如下:
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Bool)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetBool" && e.stringParameter == "isRunning")
{
e.stringParameter = "isWalking";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
例子2:修改SetFloat函数
我们可以在导入模型时自动将所有的SetFloat函数中的参数名“speed”改为“velocity”,从而控制动画的播放。具体现如下:
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor : AssetPostprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Float)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetFloat" && e.stringParameter == "speed")
{
e.stringParameter = "velocity";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
例子3:修改SetInteger函数
我们可以在导入模型时自动将所有的SetInteger函数中的参数名“state”改为“status”,从而控制动画的播放。具体实现如下:
using UnityEngine;
using UnityEditor;
public class ModelPostprocessor :Postprocessor
{
void OnPostprocessModel(GameObject go)
{
Animator animator = go.GetComponent<Animator>();
if (animator != null)
{
AnimatorController controller = animator.runtimeAnimatorController as AnimatorController;
if (controller != null)
{
foreach (AnimatorControllerParameter parameter in controller.parameters)
{
if (parameter.type == AnimatorControllerParameterType.Int)
{
foreach (AnimationClip clip in controller.animationClips)
{
AnimationEvent[] events = AnimationUtility.GetAnimationEvents(clip);
foreach (AnimationEvent e in events)
{
if (e.functionName == "SetInteger" && e.stringParameter == "state")
{
e.stringParameter = "status";
AnimationUtility.SetAnimationEvents(clip, events);
}
}
}
}
}
}
}
}
}
总结
本文介绍了如何使用AssetPostprocessor的Model的动画相关的函数修改,并提供了多个使用例子。通过使用AssetPostprocessor的Model的动画相关的函数修改,我们可以在导入模型时自动修改画相关的函数,从而提高我们的工作效率。
Unity的AssetPostprocessor之Model之动画:深入解析与实用案例 3的更多相关文章
- Unity 4.0 中的新动画系统——MecAnim
分享一个文档资料,关于动画系统的,版本应该很老了,但是有借鉴意义的: Unity 4.0 已于 2012 年 11 月 15 日正式发布,Unity 每一次版本的提升,都给游戏开发者带来惊喜,这一次也 ...
- 【Unity】10.1 类人动画的导入和设置
分类:Unity.C#.VS2015 创建日期:2016-05-02 一.制作或购买类人模型 为了充分使用 Mecanim 类人动画系统和类人动画的动画重定位功能,需要先使用其他3D建模软件(例如3d ...
- Unity3D for VR 学习(9): Unity Shader 光照模型 (illumination model)
关于光照模型 所谓模型,一般是由学术算法发起, 经过大量实际数据验证而成的可靠公式 现在还记得2009年做TD-SCDMA移动通信算法的时候,曾经看过自由空间传播模型(Free space propa ...
- 高速上手Unity中最好的补间动画插件DFTween
出处:http://blog.csdn.net/u010019717 author:孙广东 时间:2015.3.17 23:00 DFTween 是一个在 Unity 游戏引擎中高 ...
- Android属性动画完全解析(下)
转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...
- Android属性动画完全解析(上),初识属性动画的基本用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...
- 精选19款华丽的HTML5动画和实用案例
下面是本人收集的19款超酷HTML5动画和实用案例,觉得不错,分享给大家. 1.HTML5 Canvas火焰喷射动画效果 还记得以前分享过的一款HTML5烟花动画HTML5 Canvas烟花特效,今天 ...
- Android属性动画完全解析(中)
转载:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是 ...
- Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中 ...
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...
随机推荐
- Selenium - 元素定位(2) - XPATH进阶
Selenium - 元素定位 XPATH 定位进阶 元素示例 属性定位 # xpath 通过id属性定位 driver.find_element_by_xpath("//*[@id='kw ...
- Python这样读写Excel数据,这样简直不要太粗暴!
什么是xlrd&xlwt? xlrd和xlwt是Python语言中,读取和写入Excel数据的扩展工具.xlrd为xls文件read库,xlwt为xls文件write库.具体请看xlrd百度百 ...
- vulnhub_jangow
来源 vulnhub:https://www.vulnhub.com/entry/jangow-101,754/ 描述 难度:简单 这在 VirtualBox 而不是 VMware 上效果更好 我这里 ...
- 常见 Linux 提权
Common Linux Privesc 记录 常见 Linux 提权的 提权方式:水平提权,垂直提权. 水平提权:这是您通过接管与您处于相同权限级别的不同用户来扩大您对受感染系统的影响的地方. 例如 ...
- JavaScript 显示数据
JavaScript 显示数据 JavaScript 可以通过不同的方式来输出数据: 使用 window.alert() 弹出警告框. 使用 document.write() 方法将内容写到 HTML ...
- 使用 InstructPix2Pix 对 Stable Diffusion 进行指令微调
本文主要探讨如何使用指令微调的方法教会 Stable Diffusion 按照指令 PS 图像.这样,我们 Stable Diffusion 就能听得懂人话,并根据要求对输入图像进行相应操作,如: 将 ...
- 前端Vue自定义顶部搜索框 热门搜索 历史搜索 用于搜索跳转使用
前端Vue自定义顶部搜索框 热门搜索 历史搜索 用于搜索跳转使用, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13128 效 ...
- 前端Vue自定义简单实用中国省市区三级联动选择器
前端Vue自定义简单实用中国省市区三级联动选择器, 请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=13118 效果图如下: 使用方法 < ...
- 力扣744:寻找比目标字母大的最小字母; LeetCode744:Find Smallest Letter Greater Than Target
题目见文末 LeetCode link 思路及题解 手写二分 源码: class Solution: def nextGreatestLetter(self, letters: List[str], ...
- Python中使用支付宝支付
准备 # 支付宝文档 https://opendocs.alipay.com/open/270/105898?pathHash=b3b2b667 # 在沙箱环境下实名认证 https://openho ...