博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决AnimationClip.SetCurve RectTransform Color参数 出现Missing!的情况
阅读量:4147 次
发布时间:2019-05-25

本文共 1814 字,大约阅读时间需要 6 分钟。

在项目开发中有需求动态创建Animationclip设置其中的AnimationCure曲线,但是其中按照官方给出的示例方式设置一些参数的时候会出现Missing丢失的情况

经过查找一些资料发现这根他的命名方式可能有关系

这种命名方式第一个字母会自动大写

这种也会保持大写

但是这种命名方式会自动把m_剔除掉,然后首字母自动大写,所以我猜测在unity内部对于组建属性的命名有些可能是采用,这种命名方式再早期C++比较常见

所以参数改成匈牙利命名法

完美解决~~

附带unity官方API示例

using UnityEngine;using System.Collections;[RequireComponent(typeof(Animation))]public class ExampleClass : MonoBehaviour {    public Animation anim;    void Start() {        anim = GetComponent
(); AnimationCurve curve = AnimationCurve.Linear(0.0F, 1.0F, 2.0F, 0.0F); AnimationClip clip = new AnimationClip(); clip.legacy = true; clip.SetCurve("", typeof(Transform), "localPosition.x", curve); anim.AddClip(clip, "test"); anim.Play("test"); }}

// This script example shows how SetCurve() can be usedusing UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{    // Animate the position and color of the GameObject    public void Start()    {        Animation anim = GetComponent
(); AnimationCurve curve; // create a new AnimationClip AnimationClip clip = new AnimationClip(); clip.legacy = true; // create a curve to move the GameObject and assign to the clip Keyframe[] keys; keys = new Keyframe[3]; keys[0] = new Keyframe(0.0f, 0.0f); keys[1] = new Keyframe(1.0f, 1.5f); keys[2] = new Keyframe(2.0f, 0.0f); curve = new AnimationCurve(keys); clip.SetCurve("", typeof(Transform), "localPosition.x", curve); // update the clip to a change the red color curve = AnimationCurve.Linear(0.0f, 1.0f, 2.0f, 0.0f); clip.SetCurve("", typeof(Material), "_Color.r", curve); // now animate the GameObject anim.AddClip(clip, clip.name); anim.Play(clip.name); }}

你可能感兴趣的文章
NEXO代币持有者获得20,428,359.89美元股息
查看>>
Piper Sandler为EverArc收购Perimeter Solutions提供咨询服务
查看>>
RMRK筹集600万美元,用于在Polkadot上建立先进的NFT系统标准
查看>>
JavaSE_day14 集合中的Map集合_键值映射关系
查看>>
异常 Java学习Day_15
查看>>
Mysql初始化的命令
查看>>
MySQL关键字的些许问题
查看>>
浅谈HTML
查看>>
css基础
查看>>
Servlet进阶和JSP基础
查看>>
servlet中的cookie和session
查看>>
过滤器及JSP九大隐式对象
查看>>
软件(项目)的分层
查看>>
菜单树
查看>>
【Python】学习笔记——-6.2、使用第三方模块
查看>>
【Python】学习笔记——-7.0、面向对象编程
查看>>
【Python】学习笔记——-7.2、访问限制
查看>>
【Python】学习笔记——-7.3、继承和多态
查看>>
【Python】学习笔记——-7.5、实例属性和类属性
查看>>
git中文安装教程
查看>>