解决AnimationClip.SetCurve RectTransform Color参数 出现Missing!的情况

简介: 搬迁原来博客海澜CSDN在项目开发中有需求动态创建Animationclip设置其中的AnimationCure曲线,但是其中按照官方给出的示例方式设置一些参数的时候会出现Missing丢失的情况经过查找一些资料发...

搬迁原来博客海澜CSDN

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

经过查找一些资料发现这根他的命名方式可能有关系,如下 这种命名方式第一个字母会自动大写

img_c90890f7199a79a0a4cd3fb2e1030a92.png
img_58294eced76e9cb9cb1667d0d1ef7028.png

这种也会保持大写

img_159f4cbd327e9474cdff557f11b7ab66.png
img_9684396006e031d7b13e8cbf3847f220.png
如下但是这种命名方式会自动把m_剔除掉,然后首字母自动大写,所以我猜测在unity内部对于组建属性的命名有些可能是采用匈牙利命名法,这种命名方式再早期C++比较常见
img_b9ad1d572ee07d5dab92ae80a9fadfe8.png
img_1975275bcd5d4b9c2e256f3996cc6dd6.png
所以参数改成匈牙利命名法
img_d56703377bd61383ee4c998f5729cf2f.png
img_a11765a889272337d0e1db36b6a07c20.png

完美解决~~

附带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);  
    }  
}  
相关文章
|
6月前
|
XML C# 数据格式
The data at the root level is invalid. Line 1, position 1.
The data at the root level is invalid. Line 1, position 1.
106 0
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
HALCON error #1302: Wrong value of control parameter: 2 in operator affine_trans_region
|
算法 C# C++
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
HALCON error #1201: Wrong type of control parameter: 1 in operator threshold
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
RuntimeError: Given groups=1, weight of size 64 128 1 7, expected input[16,
2936 0
|
3月前
|
CDN
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
37 0
|
4月前
|
机器学习/深度学习 Python
【Python】已解决TypeError: init() got an unexpected keyword argument ‘threshold’
【Python】已解决TypeError: init() got an unexpected keyword argument ‘threshold’
128 0
|
6月前
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
Should pass resolved color instead of resource id here: getResources().getColor(R.color.brown)
50 6
|
计算机视觉
cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle‘
cv2.error: OpenCV(4.5.2) : -1 : error: (-5:Bad argument) in function ‘rectangle‘
445 0
|
Shell 开发工具 git
Git使用commit命令时报错“bad numeric config value ‘ture‘ for ‘color.ui‘: invalid unit”(已解决)
Git使用commit命令时报错“bad numeric config value ‘ture‘ for ‘color.ui‘: invalid unit”(已解决)
257 0
Git使用commit命令时报错“bad numeric config value ‘ture‘ for ‘color.ui‘: invalid unit”(已解决)
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
275 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘