unity中Playable的使用

https://unity.cn/projects/playable-api-bu-yong-animatorru-he-bo-fang-dong-hua
https://www.cnblogs.com/caiger-blog/p/13700821.html

Playable是一组API,可以组合不同动画,然后通过一个输出,将这个输出播放出来。

1、创建graph
graph = PlayableGraph.Create(“BlendController”);

2、创建一个输出
AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, “Animation”, GetComponent());

3、创建一个混合器
AnimationMixerPlayable mixer = AnimationMixerPlayable.Create(graph, 2);

4、让输出有一个输入源,源是混合器
output.SetSourcePlayable(mixer);

5、创建一个动画片段
AnimationClipPlayable acp1 = AnimationClipPlayable.Create(graph, clip);

6、在创建一个动画片段
AnimationClipPlayable acp2 = AnimationClipPlayable.Create(graph, clip2);

7、连接
graph.Connect(acp1, 0, mixer, 0); //source的0号输出,到目的0号输入
graph.Connect(acp2, 0, mixer, 1); //source的0号输出,到目的1号输入

8、graph进行工作
graph.Play();

9、改变两个动画的混合权重
mixer.SetInputWeight(0, 1.0f - weight);
mixer.SetInputWeight(1, weight);

10、让某个动画片段不参与混合了
clipPlay1.Pause();

11、销毁动画
graph.Destroy();
graph.DestroyPlayable(mixer);
graph.DestroyOutput(output);
graph.Disconnect(mixer, 0);

12、设置某个动画片段播放的第几秒
AnimationClipPlayable clipP = AnimationClipPlayable.Create(graph, clip);
clipP.SetTime(time);

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Unity 使用 proto,需要先安装 Google 的 protobuf 工具。然后在 Unity 项目导入相关的 proto 文件,使用 protoc 编译器生成对应的 C# 类代码。在 Unity ,可以通过这些 C# 类来序列化和反序列化 proto 数据。 具体的步骤如下: 1. 下载并安装 protobuf 工具,包括 protoc 编译器和 C# 支持库。 2. 在 Unity 创建一个 C# 类来表示你的 proto 数据结构。 3. 在 Unity 导入 proto 文件,使用 protoc 编译器生成对应的 C# 类代码。 4. 在 Unity 使用生成的 C# 类来序列化和反序列化 proto 数据。 以下是一个简单的示例代码,演示了如何在 Unity 使用 proto: ```csharp using System.Collections; using System.Collections.Generic; using UnityEngine; using Google.Protobuf; public class ProtoTest : MonoBehaviour { void Start() { // 创建一个 proto 数据结构 var msg = new MyMessage { Id = 1, Name = "ProtoTest", Values = { 1, 2, 3 } }; // 将 proto 数据序列化成二进制数据 var bytes = msg.ToByteArray(); // 将二进制数据反序列化成 proto 数据 var newMsg = MyMessage.Parser.ParseFrom(bytes); // 输出 proto 数据的内容 Debug.Log($"Id: {newMsg.Id}, Name: {newMsg.Name}, Values: {string.Join(", ", newMsg.Values)}"); } } // 定义一个 proto 数据结构 message MyMessage { int32 Id = 1; string Name = 2; repeated int32 Values = 3; } ``` 注意:在使用 proto 时,需要保证 Unity 和服务器端使用相同的 proto 文件和版本,否则可能会出现兼容性问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值