gpu instancer crowd 动画使用方式

实现先将动画对象,使用autolod插件生成lodground,

然后在GPUI Crowd Manager 生成CrowdPrefab,然后bake animation。

然后 Crowd 的animationdata 那里勾上use crowd animator,apply root motion 就可以使用了

生成对象

复制代码
   private List<GPUInstancerPrefab> _instanceList;
   生成方法
      GameObject g = Instantiate(prefab, spawnPosition, Quaternion.identity);
    GPUICrowdPrefab prefabInstance = g.GetComponent<GPUICrowdPrefab>(); // We reference the prototype by the GPUICrowdPrefab component that GPUI adds on the prefab...
      GPUInstancer.GPUInstancerAPI.AddPrefabInstance(gpuiCrowdManager, prefabInstance);
  _instanceList = new List<GPUInstancerPrefab>();
_instanceList.Add(prefabInstance);
   GPUInstancerAPI.RegisterPrefabInstanceList(gpuiCrowdManager, _instanceList);

动画切换

复制代码
 if (this.transform.GetComponent<GPUICrowdPrefab>() != null)
 {
     GPUICrowdPrototype crowdPrototype = this.transform.GetComponent<GPUICrowdPrefab>().prefabPrototype as GPUICrowdPrototype;
     GPUIAnimationClipData clipData = crowdPrototype.animationData.clipDataList[2];//需要切换的动画index,只能有四个
     GPUICrowdAPI.StartAnimation(this.transform.GetComponent<GPUICrowdPrefab>(), clipData, 0);
 }

基于脚本的动画播放进度的过渡,根据进度触发攻击事件,不用脚本可以在Manager 中设置在第几帧触发事件

复制代码
 GPUICrowdPrefab gPUICrowdPrefab = this.transform.GetComponent<GPUICrowdPrefab>();
 if (gPUICrowdPrefab != null)
 {
     GPUICrowdPrototype crowdPrototype = gPUICrowdPrefab.prefabPrototype as GPUICrowdPrototype;
     GPUIAnimationClipData clipData = crowdPrototype.animationData.clipDataList[1];
     //    GPUICrowdAPI.StartAnimation(gPUICrowdPrefab, clipData, 0);
     float t = gPUICrowdPrefab.crowdAnimator.GetClipTime(clipData);
     float currentClipFrame = GPUICrowdAnimator.GetClipFrame(t, clipData.length, clipData.clipFrameCount, false);
     float progress = currentClipFrame / clipData.clipFrameCount;
     if (progress >= 0.95f)
     {
         Vector4 _blendWeights= new Vector4(0, 0, 0, 0);
         isAttacking = false;
         _blendWeights.x = 1;
         _blendWeights.y = 0;
         clipData = crowdPrototype.animationData.clipDataList[0];
         gPUICrowdPrefab.crowdAnimator.StartBlend(gPUICrowdPrefab.runtimeData, gPUICrowdPrefab. gpuInstancerID - 1,_blendWeights, crowdPrototype.animationData.clipDataList[0], crowdPrototype.animationData.clipDataList[1], default, default, null, null, 0.1f);
 
     }

_blendWeights为过渡权重,x为1,y为0,就是过渡到第一个动画,0.1f为过渡值。

Vector4 _blendWeights是代表仅有的四个动画的权重

相关推荐
小贺儿开发2 小时前
Unity3D 八大菜系连连看
游戏·unity·互动·传统文化
在路上看风景2 小时前
25. 屏幕像素和纹理像素不匹配
unity
ۓ明哲ڪ4 小时前
Unity功能——创建新脚本时自动添加自定义头注释
unity·游戏引擎
熬夜敲代码的小N4 小时前
Unity大场景卡顿“急救包”:从诊断到落地的全栈优化方案
java·unity·游戏引擎
派葛穆5 小时前
Unity-realvirtual-S7通讯快速配置(未完结)
unity·游戏引擎
w-白兰地16 小时前
【Addressable远端加载资源】
unity·addressable·资源加载
小张不爱写代码19 小时前
[Unity 技巧] 如何自定义 Inspector 变量显示名称 (CustomLabel)
unity·游戏引擎
Sator120 小时前
Unity开发中常用的随机方法扩展
unity
dzj202120 小时前
Unity中使用LLMUnity遇到的问题(五)——主要脚本的继承关系+用DuckDB对知识库升级的思考
unity·向量数据库·向量搜索·duckdb·llmunity
地狱为王1 天前
Unity使用Spleeter分离人声和伴奏
unity·游戏引擎·spleeter