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的更多相关文章

  1. Unity 4.0 中的新动画系统——MecAnim

    分享一个文档资料,关于动画系统的,版本应该很老了,但是有借鉴意义的: Unity 4.0 已于 2012 年 11 月 15 日正式发布,Unity 每一次版本的提升,都给游戏开发者带来惊喜,这一次也 ...

  2. 【Unity】10.1 类人动画的导入和设置

    分类:Unity.C#.VS2015 创建日期:2016-05-02 一.制作或购买类人模型 为了充分使用 Mecanim 类人动画系统和类人动画的动画重定位功能,需要先使用其他3D建模软件(例如3d ...

  3. Unity3D for VR 学习(9): Unity Shader 光照模型 (illumination model)

    关于光照模型 所谓模型,一般是由学术算法发起, 经过大量实际数据验证而成的可靠公式 现在还记得2009年做TD-SCDMA移动通信算法的时候,曾经看过自由空间传播模型(Free space propa ...

  4. 高速上手Unity中最好的补间动画插件DFTween

     出处:http://blog.csdn.net/u010019717 author:孙广东      时间:2015.3.17   23:00 DFTween 是一个在 Unity 游戏引擎中高 ...

  5. Android属性动画完全解析(下)

    转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...

  6. Android属性动画完全解析(上),初识属性动画的基本用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 在手机上去实现一些动画效果算是件比较炫酷的事情,因此Android系 ...

  7. 精选19款华丽的HTML5动画和实用案例

    下面是本人收集的19款超酷HTML5动画和实用案例,觉得不错,分享给大家. 1.HTML5 Canvas火焰喷射动画效果 还记得以前分享过的一款HTML5烟花动画HTML5 Canvas烟花特效,今天 ...

  8. Android属性动画完全解析(中)

    转载:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是 ...

  9. Android属性动画完全解析(下),Interpolator和ViewPropertyAnimator的用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中 ...

  10. Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/43536355 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法 ...

随机推荐

  1. 2020-11-22:mysql中,什么是filesort?

    福哥答案2020-11-22:[答案来自此链接:](http://bbs.xiangxueketang.cn/question/412)如果mysql在排序的时候没有使用到索引那么就会输出 using ...

  2. 2021-03-26:给定一个正整数N,表示有N份青草统一堆放在仓库里。有一只牛和一只羊,牛先吃,羊后吃,它俩轮流吃草。不管是牛还是羊,每一轮能吃的草量必须是:1,4,16,64…(4的某次方)。谁最先把草吃完,谁获胜。假设牛和羊都绝顶聪明,都想赢,都会做出理性的决定。根据唯一的参数N,返回谁会赢。

    2021-03-26:给定一个正整数N,表示有N份青草统一堆放在仓库里.有一只牛和一只羊,牛先吃,羊后吃,它俩轮流吃草.不管是牛还是羊,每一轮能吃的草量必须是:1,4,16,64-(4的某次方).谁最 ...

  3. Grafana系列-统一展示-8-ElasticSearch日志快速搜索仪表板

    系列文章 Grafana 系列文章 概述 我们是基于这篇文章: Grafana 系列文章(十二):如何使用 Loki 创建一个用于搜索日志的 Grafana 仪表板, 创建一个类似的, 但是基于 El ...

  4. 在国内用Java代理调用OpenAI的ChatGPT的API接口

    第一步:一个科学友好的上网工具,开启全局代理: 第二步:一个注册好的ChatGPT账号,且在个人设置里面生成apiKey:https://platform.openai.com/account/api ...

  5. 区间数k大数查询

    题目 问题描述 给定一个序列,每次询问序列中第 l 个数到第 r 个数中第 K 大的数是哪个. 输入格式 第一行包含一个数 n,表示序列长度. 第二行包含 n 个正整数,表示给定的序列. 第三个包含一 ...

  6. JavaWeb编程面试题——Spring Boot

    引言 面试题==知识点,这里所记录的面试题并不针对于面试者,而是将这些面试题作为技能知识点来看待.不以刷题进大厂为目的,而是以学习为目的.这里的知识点会持续更新,目录也会随时进行调整. 关注公众号:编 ...

  7. 「有问必答」Go如何优雅的对时间进行格式化?

    昨天 交流群 关于「Go如何优雅的对时间进行格式化?」展开了讨论: 咋搞捏? 如何在不循环的情况下,把列表数据结构体的时间修改为咱们习惯的格式,而不是UTC模式 我们要实现的效果如下: created ...

  8. PySide6(Qt for Python) QTableWidget表头边框线问题

    这个问题是在Windows10平台下特有问题. 网络上有很多Qt C++的解决方案.但是没有特定的PySide6的解决方案(以下是Qt C++的解决方案). https://blog.csdn.net ...

  9. 【了解LLM】—— LLM&& SD 基本概念

    本文地址:https://www.cnblogs.com/wanger-sjtu/p/17417312.html Causual LM 这里以llama模型为例,通常在执行用户输入之前会有一个[[文章 ...

  10. Reactor 模式与Tomcat中的Reactor

    系列文章目录和关于我 参考:[nio.pdf (oswego.edu)](https://gee.cs.oswego.edu/dl/cpjslides/nio.pdf) 一丶什么是Reactor Th ...