Untiy动画系统常用操作

Animaiton动画系统

导入模型时自动修改动画类型为legacy

使用编辑器脚本

using System.Collections;
using System.Collections.Generic;
using UnityEditor;

public class SetModelAnimationType2Legacy : AssetPostprocessor//需要继承这个
{
    void OnPreprocessModel()
    {
        if (assetPath.Contains("@"))//如果名字包含@
        { 
            ModelImporter model = assetImporter as ModelImporter;
            model.animationType = ModelImporterAnimationType.Legacy;
        }
    }
}

将脚本放到Editor文件夹下,没有自己新建一个,不一定要在根目录,导入资源时,会自动修改名字里带@的模型的动画类型

播放一段动画上的指定区域

private void CheckPausePlay()//开始播放
{
    float frameRate = animation_my.clip.frameRate;
    Vector2 clip = modelAnimaitonModel.animationClipList[modelAnimaitonModel.currentStepIndex];
    int startFrame = (int)clip.x;
    int endFrame = (int)clip.y;
    animation_my[animation_my.clip.name].time = startFrame / frameRate;
    //开始播放
    animation_my.Play();
}
private void CheckPausePlay()//暂停播放  Update里调用
{
    if (animation_my == null) return;
    if (animation_my[animation_my.clip.name].time >= endFrame / frameRate)
    {
        if (animation_my.isPlaying)
        {
            animation_my.Stop();
        }
    }
}

Aniamtor动画系统

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值