首页 > 其他分享 >Animator工具函数收集

Animator工具函数收集

时间:2022-11-19 22:55:29浏览次数:51  
标签:收集 layer 函数 clip outClip var Animator animator

1) 获取AnimationClip

public static bool TryGetAnimatorClip(Animator animator, string clipName, out AnimationClip outClip)
{
    var clips = animator.runtimeAnimatorController.animationClips;
    for (var i = 0; i < clips.Length; ++i)
    {
        var clip = clips[i];
        if (clip.name == clipName)
        {
            outClip = clip;
            return true;
        }
    }

    outClip = null;
    return false;
}

 

2) 另一种获取AnimationClip

public static bool TryGetAnimatorClip(Animator animator, int layerIndex, string clipName, out AnimationClip outClip)
{
    var clipInfo = animator.GetCurrentAnimatorClipInfo(layerIndex);
    for (var i = 0; i < clipInfo.Length; ++i)
    {
        var clip = clipInfo[i].clip;
        if (clip.name == clipName)
        {
            outClip = clip;
            return true;
        }
    }

    outClip = null;
    return false;
}

 

3) 状态切换

public static void ForceCrossFade(Animator animator, string name, float transitionDuration, int layer = 0, float normalizedTime = float.NegativeInfinity)
{
    if (animator.GetNextAnimatorStateInfo(layer).fullPathHash == 0)
    {
        animator.CrossFade(name, transitionDuration, layer, normalizedTime);
    }
    else
    {
        animator.Play(animator.GetNextAnimatorStateInfo(layer).fullPathHash, layer);
        animator.Update(0);
        animator.CrossFade(name, transitionDuration, layer, normalizedTime);
    }
}

 

4) 状态机中是否有某个状态

public static bool HasState(Animator animator, string stateName, int layerIndex = 0)
{
    var stateId = Animator.StringToHash(stateName);
    return animator.HasState(layerIndex, stateId);
}

 

标签:收集,layer,函数,clip,outClip,var,Animator,animator
From: https://www.cnblogs.com/sailJs/p/16871849.html

相关文章

  • 构造函数
    作用:帮助我们初始化对象(给对象的每个属性依次赋值) 构造函数是一个特殊的方法:1)构造函数没有返回值,连void也不能写2)构造函数的名称必须和类名一样(你的类叫Person,你的构......
  • 【C语言进阶】三.字符串函数
    (一)字符串函数1.strlen(计算字符串元素数)(1)用法size_tstrlen(constchar*str)字符串已经'\0'作为结束标志,strlen函数返回的是在字符串中'\0'前面出现的字符个数(不包......
  • 三种回归损失函数
    详细介绍这里,清楚的介绍了三种损失函数。我这里重点记录一下他们的异同,方便自己消化理解。1、对于回归损失函数,通常主要有MSE(均方误差),MAE(平均绝对误差),HuberLoss。其中,Hub......
  • 欧拉函数
    欧拉函数欧拉函数\(\phi(n)\)表示小于等于\(n\)的和\(n\)互质的数的个数。求一个数\(n\)的欧拉函数,设将\(n\)质因数分解后的质因数集合为\(p_{1...m}\),则\(......
  • 损失函数
    title:损失函数date:2022-06-1920:51:05tags:-cvcategories:-note-DeepLearning目录:最小二乘法极大似然估计交叉熵reference最小二乘法xi......
  • 1.3.2 数学函数
    ......
  • 89:构造函数__init___
    ###__init__构造方法和__new__方法类是抽象的,也称之为“对象的模板”。我们需要通过类这个模板,创建类的实例对象,然后才能使用类定义的功能。我们前面说过一个Python对象......
  • shell expect免密函数块sftp、scp、ssh
    一、expect编写函数1、变量设置#!/bin/bash################remoteinfomation############remoteuser=zhangsanremotepass=123456remoteport=22remoteip=ip.txtremoteconfi......
  • C++学习------cinttypes头文件的源码学习02---函数定义
    函数定义257__BEGIN_DECLS258intmax_timaxabs(intmax_t__i)__attribute_const____INTRODUCED_IN(19);259imaxdiv_timaxdiv(intmax_t__numerator,intmax_t__de......
  • commonjs规范 require 函数解析
    functionrequire(modulePath){//1.根据传入的模块路径得到模块完整的绝对路径constmoduleId=getModuleId(modulePath)//2.判断缓存if(cache[mo......