当前位置:网站首页>随笔-Unity中一个简易的Spine动画控制器
随笔-Unity中一个简易的Spine动画控制器
2022-08-03 15:07:00 【魂牵丶梦萦】
我们在Unity中使用Spine动画时,调整一个属性可能调用的是不同类,可能简简单单启动一个动画需要写很多个函数,于是我这边对Spine的动画控制做了一个简易的封装,在目前来说使用还是很方便的,也并不难。如果需要什么其他功能也可以随时添加。废话不多说,直接上代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using System;
using static Spine.AnimationState;
public class SpineAnimCtrl : MonoBehaviour
{
/// <summary>
/// 播放Spine动画
/// </summary>
/// <param name="spine"></param>
/// <param name="trackIndex"></param>
/// <param name="animName"></param>
/// <param name="loop"></param>
/// <param name="skinName"></param>
/// <param name="callBack"></param>
public static void PlayAnim(SkeletonAnimation spine, int trackIndex, string animName, bool loop, string skinName = "", Action callBack = null)
{
Spine.Skeleton skeleton = spine.skeleton;
Spine.AnimationState state = spine.AnimationState;
if (spine != null)
{
if (!string.IsNullOrEmpty(skinName))
skeleton.SetSkin(skinName);
state.SetAnimation(trackIndex, animName, loop);
}
TrackEntryDelegate animCallBack = null;
animCallBack = delegate
{
if (callBack != null)
{
callBack.Invoke();
}
state.Complete -= animCallBack;
animCallBack = null;
};
state.Complete += animCallBack;
}
/// <summary>
/// 播放Spine动画(UI)
/// </summary>
/// <param name="spine"></param>
/// <param name="trackIndex"></param>
/// <param name="animName"></param>
/// <param name="loop"></param>
/// <param name="skinName"></param>
/// <param name="callBack"></param>
public static void PlayAnim(SkeletonGraphic spine, int trackIndex, string animName, bool loop, string skinName = "", Action callBack = null)
{
Spine.Skeleton skeleton = spine.Skeleton;
Spine.AnimationState state = spine.AnimationState;
if (spine != null)
{
if (!string.IsNullOrEmpty(skinName))
skeleton.SetSkin(skinName);
state.SetAnimation(trackIndex, animName, loop);
}
TrackEntryDelegate animCallBack = null;
animCallBack = delegate
{
if (callBack != null)
{
callBack.Invoke();
}
state.Complete -= animCallBack;
animCallBack = null;
};
state.Complete += animCallBack;
}
/// <summary>
/// 停止Spine动画
/// </summary>
/// <param name="spine"></param>
/// <param name="trackIndex"></param>
/// <param name="mixDuration"></param>
public static void StopAnim(SkeletonAnimation spine, int trackIndex, float mixDuration)
{
Spine.AnimationState state = spine.AnimationState;
state.SetEmptyAnimation(trackIndex, mixDuration);
}
/// <summary>
/// 停止Spine动画(UI)
/// </summary>
/// <param name="spine"></param>
/// <param name="trackIndex"></param>
/// <param name="mixDuration"></param>
public static void StopAnim(SkeletonGraphic spine, int trackIndex, float mixDuration)
{
Spine.AnimationState state = spine.AnimationState;
state.SetEmptyAnimation(trackIndex, mixDuration);
}
}
边栏推荐
- JS每晚24:00更新某方法
- 一次做数据报表的踩坑经历,让我领略了数据同步增量和全量的区别
- mysql占用服务器CPU100%的解决办法
- liunx服务器nohup不输出日志文件的方法
- 王守创:多组学整合分析揭示植物代谢多样性的分子机制(8月2号晚)
- Clickhouse Filling the Pit 3: Left Join changed to Right Join, resulting in incorrect statistical results
- cmd 关闭端口
- Jupyter Notebook 交互式编程 & 低代码拖拽式编程 | 数据科学生态下的理想平台
- 你把 vite打包 玩明白
- php类的析构函数:__destruct
猜你喜欢
【网络结构】VGG
【常见 error】Vivado 综合出现中断、失败、“PID not specified”
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
【MATLAB项目实战】基于CNN_SVM的图像花卉识别
输出一个整数的二进制形式
MySQL性能优化的'4工具+10技巧'
Huffman tree
With 1000 lines of code statistics after the xi 'an housing prices, I have a startling discovery...
Currency ATM: Solana Wallet Has Unknown Security Vulnerability, A Large Number Of Users' Digital Assets Are Stolen
2021年12月电子学会图形化一级编程题解析含答案:下雨
随机推荐
网络中的交换机和路由器
PAT乙级-B1017 A除以B(20)
2021年12月电子学会图形化三级编程题解析含答案:跳高比赛
QT之Mysql驱动
问题7:功能测试花瓶用例
云硬盘EVS详解以及如何用与避坑【华为云至简致远】
ubiquant量化竞赛
HDU 1406 (完数)
PAT乙级-B1010 一元多项式求导(25)
技术分享 | 接口自动化测试如何搞定 json 响应断言?
如何把MapGIS的区文件转为ArcGIS的SHAPE面文件
2021年12月电子学会图形化四级编程题解析含答案:棕熊大战
Day2:面试必考题目
redis的使用方法
Detailed explanation of cloud hard disk EVS and how to use and avoid pits [HUAWEI CLOUD is simple and far]
输出1!+2!+3!+......+n!
Currency ATM: Solana Wallet Has Unknown Security Vulnerability, A Large Number Of Users' Digital Assets Are Stolen
php中接口、抽象类以及接口和抽象类区别详解
Day1:面试必考真题
[The Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?