解决AnimationClip.SetCurve RectTransform Color参数 出现Missing!的情况
2017-07-12 11:42
519 查看
在项目开发中有需求动态创建Animationclip设置其中的AnimationCure曲线,但是其中按照官方给出的示例方式设置一些参数的时候会出现Missing丢失的情况
![](https://img-blog.csdn.net/20170712113426321)
![](https://img-blog.csdn.net/20170712113432301)
经过查找一些资料发现这根他的命名方式可能有关系
![](https://img-blog.csdn.net/20170712112709899)
![](https://img-blog.csdn.net/20170712112724156)
这种命名方式第一个字母会自动大写
![](https://img-blog.csdn.net/20170712112732630)
![](https://img-blog.csdn.net/20170712112738639)
这种也会保持大写
![](https://img-blog.csdn.net/20170712112748097)
![](https://img-blog.csdn.net/20170712112754691)
但是这种命名方式会自动把m_剔除掉,然后首字母自动大写,所以我猜测在unity内部对于组建属性的命名有些可能是采用匈牙利命名法,这种命名方式再早期C++比较常见
所以参数改成匈牙利命名法
![](https://img-blog.csdn.net/20170712113725825)
![](https://img-blog.csdn.net/20170712113730671)
完美解决~~
附带unity官方API示例
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animation))]
public class ExampleClass : MonoBehaviour {
public Animation anim;
void Start() {
anim = GetComponent<Animation>();
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 used
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
// Animate the position and color of the GameObject
public void Start()
{
Animation anim = GetComponent<Animation>();
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);
}
}
经过查找一些资料发现这根他的命名方式可能有关系
这种命名方式第一个字母会自动大写
这种也会保持大写
但是这种命名方式会自动把m_剔除掉,然后首字母自动大写,所以我猜测在unity内部对于组建属性的命名有些可能是采用匈牙利命名法,这种命名方式再早期C++比较常见
所以参数改成匈牙利命名法
完美解决~~
附带unity官方API示例
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animation))]
public class ExampleClass : MonoBehaviour {
public Animation anim;
void Start() {
anim = GetComponent<Animation>();
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 used
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
// Animate the position and color of the GameObject
public void Start()
{
Animation anim = GetComponent<Animation>();
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);
}
}
相关文章推荐
- maven项目出现web.xml is missing and <failOnMissingWebXml> is set to true错误的解决办法
- 在浏览器传中文参数时在本地上转码是正常的,到服务器上出现乱码情况时解决方法
- 在浏览器传中文参数时在本地上转码是正常的,到服务器上出现乱码情况时解决方法
- 解决出现JS跳转传中文参数出现乱码的情况
- maven中出现web.xml is missing and <failOnMissingWebXml> is set to true的错误如何解决
- 录制动画时AnimationClip.SetCurve的relativePath问题
- XCode 出现 is missing from working copy文件一直红色情况解决方法
- 对于请求中出现参数乱码的情况的几种解决方法
- maven项目出现web.xml is missing and <failOnMissingWebXml> is set to true错误的解决办法
- android setTextColor()的参数设置不起作用的解决方法
- pom.xml项目文件中出现web.xml is missing and <failOnMissingWebXml> is set to true解决方法
- 今天学到yum的新参数,解决了编译MPLAY出现的The GUI requires GTK devel packages
- VS2005 出现 The OutputPath property is not set for this project. 错误的解决方法
- silverlight beta2.0安装成功后新建silverlight项目出现object reference not set to an instance of an object的解决办法
- (word导出问题)解决:服务器出现意外情况。 (异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT))的解决方法
- 在.NET中如果不指定存储过程参数的长度出现的情况
- 安装Windows7之后出现“Bootmgr is missing”的解决办法
- ASP.NET中URL传参数出现乱码解决方法
- vs2005下出现“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”的解决方法
- ArcMap打不开且出现提示(Hostname:Not_Set)的解决方法